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

BUG: rolling with datetime ArrowDtype #56370

Merged
merged 9 commits into from
Dec 28, 2023

Conversation

mroeschke
Copy link
Member

@mroeschke mroeschke commented Dec 6, 2023

Additionally renamed _apply_blockwise to _apply_columnwise to fit the actual methodology

@mroeschke mroeschke added Datetime Datetime data dtype Window rolling, ewma, expanding Arrow pyarrow functionality labels Dec 6, 2023
@mroeschke mroeschke added this to the 2.2 milestone Dec 7, 2023
@@ -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.")
Copy link
Member

Choose a reason for hiding this comment

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

typo here?

Copy link
Member Author

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")

Copy link
Member

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"

Copy link
Member Author

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'

Copy link
Member

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)
Copy link
Member

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?

Copy link
Member Author

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

@@ -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")
Copy link
Member

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

@mroeschke
Copy link
Member Author

Since there's no more comments here going to merge. Can follow up if needed

@mroeschke mroeschke merged commit 55b969b into pandas-dev:main Dec 28, 2023
45 checks passed
@mroeschke mroeschke deleted the bug/arrow/rolling_dt branch December 28, 2023 19:32
meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Dec 28, 2023
phofl pushed a commit that referenced this pull request Dec 28, 2023
…type) (#56665)

Backport PR #56370: BUG: rolling with datetime ArrowDtype

Co-authored-by: Matthew Roeschke <[email protected]>
cbpygit pushed a commit to cbpygit/pandas that referenced this pull request Jan 2, 2024
* BUG: rolling with datetime ArrowDtype

* Dont modify needs_i8_conversion

* More explicit tests

* Fix arrow to_numpy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Datetime Datetime data dtype Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: rolling does not work with timestamp[ns][pyarrow] index type
2 participants