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: Overflow warning when using Series.diff() on Series with Periods #58447
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1303,16 +1303,18 @@ def _sub_periodlike(self, other: Period | PeriodArray) -> npt.NDArray[np.object_ | |
self._check_compatible_with(other) | ||
|
||
other_i8, o_mask = self._get_i8_values_and_mask(other) | ||
new_i8_data = add_overflowsafe(self.asi8, np.asarray(-other_i8, dtype="i8")) | ||
new_data = np.array([self.freq.base * x for x in new_i8_data]) | ||
|
||
new_data = add_overflowsafe( | ||
self.asi8, np.asarray(-other_i8, dtype="i8") | ||
).astype(object) | ||
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. Not a great solution if this always needs to be cast to 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. Why not? The comment says "we return an object-dtype ndarray" so it makes sense to cast it to I could add an optional argument 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. I agree this seems suboptimal, and that comment seems pretty far detached from where the object conversion happens right? I agree this is a bit suspect; the old code seems to use primitive types so overall this is adding a good deal of overhead. Do you know where the cast to object is actually occurring? 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. new_data = np.array([self.freq.base * x for x in new_i8_data]) Here, |
||
if o_mask is None: | ||
# i.e. Period scalar | ||
mask = self._isnan | ||
else: | ||
# i.e. PeriodArray | ||
mask = self._isnan | o_mask | ||
|
||
new_data[mask] = NaT | ||
new_data[~mask] *= self.freq.base | ||
return new_data | ||
|
||
@final | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,6 @@ | |
Period, | ||
iNaT, | ||
) | ||
from pandas.compat import is_platform_windows | ||
from pandas.compat.numpy import np_version_gte1p24 | ||
|
||
from pandas.core.dtypes.dtypes import PeriodDtype | ||
|
||
|
@@ -104,11 +102,7 @@ def check_reduce(self, ser: pd.Series, op_name: str, skipna: bool): | |
|
||
@pytest.mark.parametrize("periods", [1, -2]) | ||
def test_diff(self, data, periods): | ||
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. I think this whole test function can be removed if its just calling super |
||
if is_platform_windows() and np_version_gte1p24: | ||
with tm.assert_produces_warning(RuntimeWarning, check_stacklevel=False): | ||
super().test_diff(data, periods) | ||
else: | ||
super().test_diff(data, periods) | ||
super().test_diff(data, periods) | ||
|
||
@pytest.mark.parametrize("na_action", [None, "ignore"]) | ||
def test_map(self, data, na_action): | ||
|
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.
Should I mention this happens on Windows only?