-
-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Preserve freq in TimedeltaIndex subtraction #62214
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
base: main
Are you sure you want to change the base?
Conversation
eec1039
to
2e1bf0c
Compare
pandas/core/arrays/datetimelike.py
Outdated
elif ( | ||
lib.is_np_dtype(self.dtype, "M") | ||
and isinstance(other, Timestamp) | ||
and cast("DatetimeArray", self).tz == other.tz |
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.
Tz check should be unnecessary; this should only work for Day freqs.
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.
ok, on it.
Can you add a test for the fix |
2e1bf0c
to
e45f984
Compare
e45f984
to
a956f9b
Compare
Certainly. I've added a test case and updated the PR. Please let me know if anything else is needed. |
@@ -1089,6 +1089,8 @@ def _get_arithmetic_result_freq(self, other) -> BaseOffset | None: | |||
# e.g. TestTimedelta64ArithmeticUnsorted::test_timedelta | |||
# Day is unambiguously 24h | |||
return self.freq | |||
elif lib.is_np_dtype(self.dtype, "M") and isinstance(other, Timestamp): |
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.
Only in case where freq is Day
], | ||
) | ||
@pytest.mark.parametrize("periods", [1, -2, 0]) | ||
def test_shift_after_dti_sub_timestamp_various_inputs(dti, ts, periods): |
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.
You don’t need all this. Just one test in tests.indexes.dattimes.arithmetic for datetimeindex-timestamp retaining freq
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.