Skip to content

BUG: MonthOffset.name #33757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 25, 2020
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/tseries/offsets/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down