Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,28 @@ def freq(self) -> BaseOffset | None:
>>> datetimeindex.freq
<Hour>
"""
"""# Conceptual fix (not in the provided file)
# In the DatetimeIndex class definition:

def __sub__(self, other):
if isinstance(other, DatetimeIndex):
# ... existing code for subtraction ...
pass

if isinstance(other, Timestamp):
# Perform the subtraction
# The result of the subtraction is a TimedeltaArray
result_array = self._data - other

# Check if the original DatetimeIndex has a frequency.
# This is the key part of the fix.
freq = self.freq

# Create the new TimedeltaIndex with the propagated frequency.
# This ensures the `freq` attribute is not None.
result_index = TimedeltaIndex(result_array, freq=freq)
return result_index
# ... other subtraction logic ..."""
return self._data.freq

@freq.setter
Expand Down
Loading