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

support timedelta in Q_.init #1978

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

andrewgsavage
Copy link
Collaborator

Copy link
Contributor

@keewis keewis left a comment

Choose a reason for hiding this comment

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

I've got a couple of comments, mostly regarding timedelta64 and where to put the code handling it.

I would also like to have a way to convert a quantity with dimension [time] to a timedelta64, but that can be its own PR (the API is not quite clear to me: should to special-case units of timedelta64[us], for example?).

Comment on lines 231 to 232
if is_timedelta(value) or is_timedelta_array(value):
inst._magnitude = to_seconds(value)
Copy link
Contributor

@keewis keewis May 10, 2024

Choose a reason for hiding this comment

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

would it be possible to special-case numpy.timedelta64, probably in the numpy facet? That way we could roundtrip exactly

pint/compat.py Outdated
if isinstance(obj, datetime.timedelta):
return obj.total_seconds()
elif isinstance(obj, np_timedelta64) or obj.dtype == np_timedelta64:
return obj.astype(float)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not going to work in general: timedelta64 has its own units, which can range from days (or years?) to nanoseconds, and astype(float) is the equivalent of magnitude. I don't have any advice on how to extract that, though, other than parsing the string repr of the dtype.

@jakirkham
Copy link

It looks like this is ready for another review

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

Successfully merging this pull request may close these issues.

Convert timedelta to quantity
3 participants