Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing non-second timedelta64 bug #1807

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

erikvansebille
Copy link
Member

This fixes #1738

@VeckoTheGecko
Copy link
Contributor

Maybe updating

obs = pset.particledata.getvardata("obs_written", indices_to_write)

to

-                obs = pset.particledata.getvardata("obs_written", indices_to_write)
+                obs: list[int] = pset.particledata.getvardata("obs_written", indices_to_write)

Will fix mypy?

self.calendar = "np_datetime64"
elif isinstance(time_origin, np.timedelta64):
self.time_origin = time_origin.astype("timedelta64[s]")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it a concern that this may lose subsecond resolution?

>>> np.timedelta64(110, "ns").astype('timedelta64[s]')
np.timedelta64(0,'s')

Copy link
Member Author

Choose a reason for hiding this comment

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

Now using nanoseconds for timedelta64; better like this?

Copy link
Contributor

@VeckoTheGecko VeckoTheGecko Jan 6, 2025

Choose a reason for hiding this comment

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

I don't think so. The issue stems with the actual comparison of datetime objects in .reltime(). I'm not entirely sure what datetime objects are coming into (or expected to come into) that function, so something more sophisticated may be needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK is fine; then let's discuss in person. Or feel free to propose something else, if you want

@VeckoTheGecko
Copy link
Contributor

VeckoTheGecko commented Jan 6, 2025

Looking under the hood at xarray, I think that we can rely on xarray internals for this.

https://github.com/pydata/xarray/blob/49502fcde4db6ea3da1f60ead589580cfdad5c98/xarray/coding/times.py

edit: hmmm, this is in their private API though info

@VeckoTheGecko
Copy link
Contributor

I think looking at how xarray does it and adopting a similar approach would be a good way to go (though whether we want to do that before v4 is another matter - not sure if this bug is encountered in production)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

TimeConverter.reltime with time_origin = np.timedelta64 sensitive to precision
2 participants