Skip to content

Commit 2b00764

Browse files
jbrockmendelrhshadrach
authored andcommitted
BUG: freq not retained on apply_index (pandas-dev#33779)
* BUG: freq not retained on apply_index * whatsnew
1 parent 452f88c commit 2b00764

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

doc/source/whatsnew/v1.1.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ Datetimelike
462462
- Bug in :meth:`DatetimeIndex.to_period` not infering the frequency when called with no arguments (:issue:`33358`)
463463
- Bug in :meth:`DatetimeIndex.tz_localize` incorrectly retaining ``freq`` in some cases where the original freq is no longer valid (:issue:`30511`)
464464
- Bug in :meth:`DatetimeIndex.intersection` losing ``freq`` and timezone in some cases (:issue:`33604`)
465+
- Bug in :class:`DatetimeIndex` addition and subtraction with some types of :class:`DateOffset` objects incorrectly retaining an invalid ``freq`` attribute (:issue:`33779`)
465466

466467
Timedelta
467468
^^^^^^^^^

pandas/tests/tseries/offsets/test_yqm_offsets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def test_apply_index(cls, n):
6464
ser = pd.Series(rng)
6565

6666
res = rng + offset
67+
assert res.freq is None # not retained
6768
res_v2 = offset.apply_index(rng)
6869
assert (res == res_v2).all()
6970
assert res[0] == rng[0] + offset

pandas/tseries/offsets.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,9 +1147,7 @@ def apply(self, other):
11471147
@apply_index_wraps
11481148
def apply_index(self, i):
11491149
shifted = liboffsets.shift_months(i.asi8, self.n, self._day_opt)
1150-
# TODO: going through __new__ raises on call to _validate_frequency;
1151-
# are we passing incorrect freq?
1152-
return type(i)._simple_new(shifted, freq=i.freq, dtype=i.dtype)
1150+
return type(i)._simple_new(shifted, dtype=i.dtype)
11531151

11541152

11551153
class MonthEnd(MonthOffset):
@@ -1868,11 +1866,7 @@ def apply_index(self, dtindex):
18681866
shifted = liboffsets.shift_quarters(
18691867
dtindex.asi8, self.n, self.startingMonth, self._day_opt
18701868
)
1871-
# TODO: going through __new__ raises on call to _validate_frequency;
1872-
# are we passing incorrect freq?
1873-
return type(dtindex)._simple_new(
1874-
shifted, freq=dtindex.freq, dtype=dtindex.dtype
1875-
)
1869+
return type(dtindex)._simple_new(shifted, dtype=dtindex.dtype)
18761870

18771871

18781872
class BQuarterEnd(QuarterOffset):
@@ -1954,11 +1948,7 @@ def apply_index(self, dtindex):
19541948
shifted = liboffsets.shift_quarters(
19551949
dtindex.asi8, self.n, self.month, self._day_opt, modby=12
19561950
)
1957-
# TODO: going through __new__ raises on call to _validate_frequency;
1958-
# are we passing incorrect freq?
1959-
return type(dtindex)._simple_new(
1960-
shifted, freq=dtindex.freq, dtype=dtindex.dtype
1961-
)
1951+
return type(dtindex)._simple_new(shifted, dtype=dtindex.dtype)
19621952

19631953
def is_on_offset(self, dt: datetime) -> bool:
19641954
if self.normalize and not _is_normalized(dt):

0 commit comments

Comments
 (0)