-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: rolling with datetime ArrowDtype #56370
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c232efd
BUG: rolling with datetime ArrowDtype
mroeschke 15e0869
Dont modify needs_i8_conversion
mroeschke ecc8f4d
Merge remote-tracking branch 'upstream/main' into bug/arrow/rolling_dt
mroeschke baa6b15
Merge remote-tracking branch 'upstream/main' into bug/arrow/rolling_dt
mroeschke c844b18
More explicit tests
mroeschke ca57b50
Merge remote-tracking branch 'upstream/main' into bug/arrow/rolling_dt
mroeschke c57585e
Merge remote-tracking branch 'upstream/main' into bug/arrow/rolling_dt
mroeschke 45d7a7c
Fix arrow to_numpy
mroeschke 056268a
Merge remote-tracking branch 'upstream/main' into bug/arrow/rolling_dt
mroeschke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
Any, | ||
Callable, | ||
Literal, | ||
cast, | ||
) | ||
|
||
import numpy as np | ||
|
@@ -39,6 +38,7 @@ | |
is_numeric_dtype, | ||
needs_i8_conversion, | ||
) | ||
from pandas.core.dtypes.dtypes import ArrowDtype | ||
from pandas.core.dtypes.generic import ( | ||
ABCDataFrame, | ||
ABCSeries, | ||
|
@@ -104,6 +104,7 @@ | |
NDFrameT, | ||
QuantileInterpolation, | ||
WindowingRankType, | ||
npt, | ||
) | ||
|
||
from pandas import ( | ||
|
@@ -404,11 +405,12 @@ def _insert_on_column(self, result: DataFrame, obj: DataFrame) -> None: | |
result[name] = extra_col | ||
|
||
@property | ||
def _index_array(self): | ||
def _index_array(self) -> npt.NDArray[np.int64] | None: | ||
# TODO: why do we get here with e.g. MultiIndex? | ||
if needs_i8_conversion(self._on.dtype): | ||
idx = cast("PeriodIndex | DatetimeIndex | TimedeltaIndex", self._on) | ||
return idx.asi8 | ||
if isinstance(self._on, (PeriodIndex, DatetimeIndex, TimedeltaIndex)): | ||
return self._on.asi8 | ||
elif isinstance(self._on.dtype, ArrowDtype) and self._on.dtype.kind in "mM": | ||
return self._on.to_numpy(dtype=np.int64) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yup good point. Added a kind check |
||
return None | ||
|
||
def _resolve_output(self, out: DataFrame, obj: DataFrame) -> DataFrame: | ||
|
@@ -439,7 +441,7 @@ def _apply_series( | |
self, homogeneous_func: Callable[..., ArrayLike], name: str | None = None | ||
) -> Series: | ||
""" | ||
Series version of _apply_blockwise | ||
Series version of _apply_columnwise | ||
""" | ||
obj = self._create_data(self._selected_obj) | ||
|
||
|
@@ -455,7 +457,7 @@ def _apply_series( | |
index = self._slice_axis_for_step(obj.index, result) | ||
return obj._constructor(result, index=index, name=obj.name) | ||
|
||
def _apply_blockwise( | ||
def _apply_columnwise( | ||
self, | ||
homogeneous_func: Callable[..., ArrayLike], | ||
name: str, | ||
|
@@ -614,7 +616,7 @@ def calc(x): | |
return result | ||
|
||
if self.method == "single": | ||
return self._apply_blockwise(homogeneous_func, name, numeric_only) | ||
return self._apply_columnwise(homogeneous_func, name, numeric_only) | ||
else: | ||
return self._apply_tablewise(homogeneous_func, name, numeric_only) | ||
|
||
|
@@ -1232,7 +1234,9 @@ def calc(x): | |
|
||
return result | ||
|
||
return self._apply_blockwise(homogeneous_func, name, numeric_only)[:: self.step] | ||
return self._apply_columnwise(homogeneous_func, name, numeric_only)[ | ||
:: self.step | ||
] | ||
|
||
@doc( | ||
_shared_docs["aggregate"], | ||
|
@@ -1868,6 +1872,7 @@ def _validate(self): | |
if ( | ||
self.obj.empty | ||
or isinstance(self._on, (DatetimeIndex, TimedeltaIndex, PeriodIndex)) | ||
or (isinstance(self._on.dtype, ArrowDtype) and self._on.dtype.kind in "mM") | ||
) and isinstance(self.window, (str, BaseOffset, timedelta)): | ||
self._validate_datetimelike_monotonic() | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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!