-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: rolling with datetime ArrowDtype #56370
Conversation
@@ -2514,4 +2515,8 @@ def dtype_to_unit(dtype: DatetimeTZDtype | np.dtype) -> str: | |||
""" | |||
if isinstance(dtype, DatetimeTZDtype): | |||
return dtype.unit | |||
elif isinstance(dtype, ArrowDtype): | |||
if dtype.kind not in "mM": | |||
raise ValueError(f"{dtype=} does not have a resolution.") |
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.
typo here?
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 don't think so? (If you're referring to dtype=
, it was intentional to render e.g. "dtype=int64[pyarrow] does not have a resolution"
)
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.
maybe im misunderstanding how f-strings work. id expect this to render "int64[pyarrow]= does not have a resolution"
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.
In [2]: import pandas as pd
In [3]: import pyarrow as pa
In [4]: dtype = pd.ArrowDtype(pa.int64())
In [5]: f"{dtype=} does not have a resolution"
Out[5]: 'dtype=int64[pyarrow] does not have a resolution'
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.
neat!
if isinstance(self._on, (PeriodIndex, DatetimeIndex, TimedeltaIndex)): | ||
return self._on.asi8 | ||
elif isinstance(self._on.dtype, ArrowDtype): | ||
return self._on.to_numpy(dtype=np.int64) |
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.
comment/assertion about self._on.dtype.kind?
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.
Yup good point. Added a kind check
pandas/core/window/rolling.py
Outdated
@@ -1871,7 +1875,7 @@ def _validate(self): | |||
# we allow rolling on a datetimelike index | |||
if ( | |||
self.obj.empty | |||
or isinstance(self._on, (DatetimeIndex, TimedeltaIndex, PeriodIndex)) | |||
or (isinstance(self._on, PeriodIndex) or self._on.dtype.kind in "Mm") |
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.
id err on the side of being more explicit about the supported dtypes being ArrowDtype
Since there's no more comments here going to merge. Can follow up if needed |
…type) (#56665) Backport PR #56370: BUG: rolling with datetime ArrowDtype Co-authored-by: Matthew Roeschke <[email protected]>
* BUG: rolling with datetime ArrowDtype * Dont modify needs_i8_conversion * More explicit tests * Fix arrow to_numpy
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.Additionally renamed _apply_blockwise to _apply_columnwise to fit the actual methodology