File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,28 @@ def freq(self) -> BaseOffset | None:
123123 >>> datetimeindex.freq
124124 <Hour>
125125 """
126+ """# Conceptual fix (not in the provided file)
127+ # In the DatetimeIndex class definition:
128+
129+ def __sub__(self, other):
130+ if isinstance(other, DatetimeIndex):
131+ # ... existing code for subtraction ...
132+ pass
133+
134+ if isinstance(other, Timestamp):
135+ # Perform the subtraction
136+ # The result of the subtraction is a TimedeltaArray
137+ result_array = self._data - other
138+
139+ # Check if the original DatetimeIndex has a frequency.
140+ # This is the key part of the fix.
141+ freq = self.freq
142+
143+ # Create the new TimedeltaIndex with the propagated frequency.
144+ # This ensures the `freq` attribute is not None.
145+ result_index = TimedeltaIndex(result_array, freq=freq)
146+ return result_index
147+ # ... other subtraction logic ..."""
126148 return self ._data .freq
127149
128150 @freq .setter
You can’t perform that action at this time.
0 commit comments