-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Series.__getitem__ returns a datetime.timedelta for pl.Duration('ns') dtype #14695
Comments
The same is true for both But I do agree that we should perhaps create a >>> from datetime import time
>>> import polar as pl
>>> s = pl.time_range(time(hour=1), time(hour=1, second=1), interval="1ns")
>>> s.filter(s <= time(hour=1, nanosecond=1)) # can't do this!
>>> s.filter(s.cast(pl.Int64) <= (1_000_000_000*3600 + 1)).cast(pl.Time) # must use integer
shape: (2,)
Series: 'literal' [time]
[
01:00:00
01:00:00.000000001
] It would be nice to be able to do: >>> s.filter(s < pl.Time.Scalar(hour=1, nanosecond=1)) ...or something of the sort. |
I think I will open an enhancement request for a scalar and see how that is received. |
This is not a bug, but I can understand the need for a scalar type. We have already talked about this internally. I'll close this in favor of #14700 for now. |
I suppose external uses could convert back to an int using
Would it necessarily be ? Maybe it would be possible to subclass |
EDIT: It did not take long to find an issue of this kind, starting from polars' own |
Checks
Reproducible example
Log output
Issue description
pl.Duration('ns')
dtype is able to represent nanosecond-recision durations.However,
datetime.timedelta()
is not able to represent nanosecond-precision durations:https://bugs.python.org/issue15443
python/cpython#59648
This means it's currently not possible to access the real value without casting to an integer dtype first.
Expected behavior
Series.__getitem__
should return instances of a type able to represent the values stored in the series.pandas has implemented its own equivalent type that does handle nanoseconds (possibly for unrelated reasons):
https://pandas.pydata.org/pandas-docs/version/2.1/reference/api/pandas.Timedelta.html
Installed versions
EDIT: added the CPython github issue tracker link
The text was updated successfully, but these errors were encountered: