diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 495dcc5700241..3adae989af58a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -104,6 +104,7 @@ from pandas.io.formats.format import DataFrameFormatter, format_percentiles from pandas.io.formats.printing import pprint_thing from pandas.tseries.frequencies import to_offset +from pandas.tseries.offsets import Tick if TYPE_CHECKING: from pandas.core.resample import Resampler @@ -8068,7 +8069,7 @@ def first(self: FrameOrSeries, offset) -> FrameOrSeries: end_date = end = self.index[0] + offset # Tick-like, e.g. 3 weeks - if not offset.is_anchored() and hasattr(offset, "_inc"): + if isinstance(offset, Tick): if end_date in self.index: end = self.index.searchsorted(end_date, side="left") return self.iloc[:end] diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 044dfa703c081..0a7eaa7b7be3e 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -4315,6 +4315,13 @@ def test_valid_month_attributes(kwd, month_classes): cls(**{kwd: 3}) +def test_month_offset_name(month_classes): + # GH#33757 off.name with n != 1 should not raise AttributeError + obj = month_classes(1) + obj2 = month_classes(2) + assert obj2.name == obj.name + + @pytest.mark.parametrize("kwd", sorted(liboffsets.relativedelta_kwds)) def test_valid_relativedelta_kwargs(kwd): # Check that all the arguments specified in liboffsets.relativedelta_kwds diff --git a/pandas/tseries/offsets.py b/pandas/tseries/offsets.py index 8ba10f56f163c..effd923cedd17 100644 --- a/pandas/tseries/offsets.py +++ b/pandas/tseries/offsets.py @@ -1125,14 +1125,6 @@ class MonthOffset(SingleConstructorOffset): __init__ = BaseOffset.__init__ - @property - def name(self) -> str: - if self.is_anchored: - return self.rule_code - else: - month = ccalendar.MONTH_ALIASES[self.n] - return f"{self.code_rule}-{month}" - def is_on_offset(self, dt: datetime) -> bool: if self.normalize and not _is_normalized(dt): return False