Skip to content

Conversation

@erikvansebille
Copy link
Member

This fixes #1738

@VeckoTheGecko
Copy link
Contributor

Maybe updating

https://github.com/OceanParcels/Parcels/blob/c079963de25f842cbe9b0500319feaa7f8056c98/parcels/particlefile.py#L354
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.time_origin = time_origin
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)

@erikvansebille
Copy link
Member Author

Not needed in v4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

3 participants