Skip to content

Conversation

@YooSunYoung
Copy link
Member

ScitiffMetadat schema does not support datetime64 dtype but IO module can handle it with a few if-statements.

It might be very convenient to store/load some important dates and timestamp...?
But it means we customzie the serialize/deserialize function and may be surprising to someone who reads the metadata in a different way...

Or is there a better way...?

@YooSunYoung YooSunYoung requested a review from jl-wynen January 20, 2026 13:13
@YooSunYoung YooSunYoung added the enhancement New feature or request label Jan 20, 2026
@github-project-automation github-project-automation bot moved this to In progress in Development Board Jan 20, 2026
@YooSunYoung YooSunYoung moved this from In progress to Selected in Development Board Jan 20, 2026
"""Warning for broken scitiff metadata."""


def _from_dict(dict_repr_var: dict) -> sc.Variable:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give this a more distinct name? I got confused about _from_dict and from_dict.

else:
values = np.datetime64(values)
corrected_repr_var['values'] = values
return from_dict(corrected_repr_var)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this handle units correctly? I don't remember whether the variable constructor converts the datetime to the provided unit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what way? I just tried this:

var = sc.datetime('now', unit='s')
display(var)
new_var = sc.datetime(str(var.value), unit='hour')
display(new_var)

and it gave me
datetime64 [s] 2026-01-20T15:21:32 and datetime64 [h] 2026-01-20T15
respectively.

Or did you mean some other cases...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the general approach is fine. Storing datetime as ISO strings is pretty common and robust. But this seems to me like scipp's from_dict should be able to handle it. Did you consider updating that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really about making it to a dictionary though.
It's only when it has to be part of the pydantic Model instance, which will be serialized as a json at the end.

Do you think it'll be helpful that from_dict turns the datetime64 into a string value...?

Base automatically changed from arbitrary-meta to main January 22, 2026 15:00
@YooSunYoung YooSunYoung enabled auto-merge January 22, 2026 15:01
@YooSunYoung YooSunYoung merged commit 4fa3d20 into main Jan 22, 2026
4 checks passed
@YooSunYoung YooSunYoung deleted the datetime branch January 22, 2026 15:03
@github-project-automation github-project-automation bot moved this from Selected to Done in Development Board Jan 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants