Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

akshat62
Copy link

@akshat62 akshat62 commented Aug 12, 2025

@akshat62 akshat62 changed the title Preserve day freq on DatetimeIndex subtraction BUG: Preserve day freq on DatetimeIndex subtraction Aug 12, 2025
@akshat62 akshat62 force-pushed the bug-62094/freq-required-TimedeltaIndex.shift branch from 7280c6a to ed516d9 Compare August 12, 2025 18:26
@akshat62
Copy link
Author

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

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

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

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: In main, TimedeltaIndex.shift() requires freq in the index, but it may not be available because it was computed
2 participants