Skip to content

Commit 25e2ef3

Browse files
jbrockmendelrhshadrach
authored andcommitted
BUG: MonthOffset.name (pandas-dev#33757)
* BUG: MonthOffset.name * GH ref
1 parent 2b00764 commit 25e2ef3

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

pandas/core/generic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
from pandas.io.formats.format import DataFrameFormatter, format_percentiles
105105
from pandas.io.formats.printing import pprint_thing
106106
from pandas.tseries.frequencies import to_offset
107+
from pandas.tseries.offsets import Tick
107108

108109
if TYPE_CHECKING:
109110
from pandas.core.resample import Resampler
@@ -8068,7 +8069,7 @@ def first(self: FrameOrSeries, offset) -> FrameOrSeries:
80688069
end_date = end = self.index[0] + offset
80698070

80708071
# Tick-like, e.g. 3 weeks
8071-
if not offset.is_anchored() and hasattr(offset, "_inc"):
8072+
if isinstance(offset, Tick):
80728073
if end_date in self.index:
80738074
end = self.index.searchsorted(end_date, side="left")
80748075
return self.iloc[:end]

pandas/tests/tseries/offsets/test_offsets.py

+7
Original file line numberDiff line numberDiff line change
@@ -4315,6 +4315,13 @@ def test_valid_month_attributes(kwd, month_classes):
43154315
cls(**{kwd: 3})
43164316

43174317

4318+
def test_month_offset_name(month_classes):
4319+
# GH#33757 off.name with n != 1 should not raise AttributeError
4320+
obj = month_classes(1)
4321+
obj2 = month_classes(2)
4322+
assert obj2.name == obj.name
4323+
4324+
43184325
@pytest.mark.parametrize("kwd", sorted(liboffsets.relativedelta_kwds))
43194326
def test_valid_relativedelta_kwargs(kwd):
43204327
# Check that all the arguments specified in liboffsets.relativedelta_kwds

pandas/tseries/offsets.py

-8
Original file line numberDiff line numberDiff line change
@@ -1125,14 +1125,6 @@ class MonthOffset(SingleConstructorOffset):
11251125

11261126
__init__ = BaseOffset.__init__
11271127

1128-
@property
1129-
def name(self) -> str:
1130-
if self.is_anchored:
1131-
return self.rule_code
1132-
else:
1133-
month = ccalendar.MONTH_ALIASES[self.n]
1134-
return f"{self.code_rule}-{month}"
1135-
11361128
def is_on_offset(self, dt: datetime) -> bool:
11371129
if self.normalize and not _is_normalized(dt):
11381130
return False

0 commit comments

Comments
 (0)