ion-python icon indicating copy to clipboard operation
ion-python copied to clipboard

C extension timestamp precision defaults to 6 while sometimes people wants other precision

Open cheqianh opened this issue 2 years ago • 1 comments

The issue was raised in https://github.com/amzn/ion-python/issues/208

Consider

obj = simple_types.IonPyTimestamp.fromisoformat("2022-07-01")
str = simpleion.dumps(obj)

What should be the expected str value? It's 2022-07-01T00:00:00.000000-00:00 currently as C extension set precision to 6 by default but users may only want 2022-07-01.

We should implement https://github.com/amzn/ion-python/issues/208#issuecomment-1190819593 solution 3 and support constructing an ion timestamp by fromisoformat. Here is a proof-of-concept - https://github.com/amzn/ion-python/issues/208#issuecomment-1192011182

cheqianh avatar Jul 28 '22 21:07 cheqianh

Just to be clear, there are two different problems here, and neither one is specific to the C extension.

  1. Timestamp (and therefore also IonPyTimestamp) can have a precision of None. It is possible to create a Timestamp with a precision of None even though it may appear to the user that the precision should be implied. (E.g. in Timestamp(2022, 8, 1) it looks like the precision should be day.) When precision is None all of the writer implementations must choose some sort of default precision, and whatever that default may be (even if it is user configurable), it is likely to be surprising to users because users will expect that Timestamp constructor and factory functions can infer the correct precision when the precision seems obvious.

  2. ion-python writers have to be able to handle writing standard types like date and datetime as Ion. Since these types do not have a notion of precision like Ion Timestamps, the writer implementations are forced to choose a default precision. Some users may want to configure the default precision used by a writer. This can probably be solved by adding a default_timestamp_precision to the kwargs of simpleion.dumps().

popematt avatar Aug 01 '22 21:08 popematt