-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
BUG: Preserve day freq on DatetimeIndex subtraction #62096
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?
BUG: Preserve day freq on DatetimeIndex subtraction #62096
Conversation
7280c6a
to
ed516d9
Compare
@mroeschke @jbrockmendel Please review. |
@@ -758,6 +758,10 @@ Datetimelike | |||
- Bug in :meth:`to_datetime` reports incorrect index in case of any failure scenario. (:issue:`58298`) | |||
- Bug in :meth:`to_datetime` with ``format="ISO8601"`` and ``utc=True`` where naive timestamps incorrectly inherited timezone offset from previous timestamps in a series. (:issue:`61389`) | |||
- Bug in :meth:`to_datetime` wrongly converts when ``arg`` is a ``np.datetime64`` object with unit of ``ps``. (:issue:`60341`) | |||
- Bug in subtracting a :class:`Timestamp` from a :class:`DatetimeIndex` with |
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.
the note isn't necessary bc the bug is not present in a released version
and isinstance(other, Timestamp) | ||
): | ||
self = cast("DatetimeArray", self) | ||
if (self.tz is None or timezones.is_utc(self.tz)) and ( |
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.
self.tz is None is implied by lib.is_np_dtype(self.dtype, "M")
check above
): | ||
self = cast("DatetimeArray", self) | ||
if (self.tz is None or timezones.is_utc(self.tz)) and ( | ||
other.tz is None or timezones.is_utc(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.
other.tz will always be None here
@@ -74,3 +74,10 @@ def test_shift_no_freq(self): | |||
tdi = TimedeltaIndex(["1 days 01:00:00", "2 days 01:00:00"], freq=None) | |||
with pytest.raises(NullFrequencyError, match="Cannot shift with no freq"): | |||
tdi.shift(2) | |||
|
|||
def test_shift_after_dti_sub_timestamp(self): |
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.
instead of testing this, test the subtraction op directly in tests.indexes.datetimes.test_arithmetic
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.