-
Notifications
You must be signed in to change notification settings - Fork 473
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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?).
pint/facets/plain/quantity.py
Outdated
if is_timedelta(value) or is_timedelta_array(value): | ||
inst._magnitude = to_seconds(value) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
It looks like this is ready for another review |
pre-commit run --all-files
with no errors