Skip to content

CLN: inherit PeriodIndex._box_func #31512

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 7 commits into from
Feb 2, 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
11 changes: 10 additions & 1 deletion pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ def wrapper(left, right):
cache=True,
)
@inherit_names(
["__iter__", "mean", "freq", "freqstr", "_ndarray_values", "asi8", "_box_values"],
[
"__iter__",
"mean",
"freq",
"freqstr",
"_ndarray_values",
"asi8",
"_box_values",
"_box_func",
],
DatetimeLikeArrayMixin,
)
class DatetimeIndexOpsMixin(ExtensionIndex):
Expand Down
1 change: 0 additions & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def _new_DatetimeIndex(cls, d):
"_field_ops",
"_datetimelike_ops",
"_datetimelike_methods",
"_box_func",
"tz",
"tzinfo",
"dtype",
Expand Down
16 changes: 0 additions & 16 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,22 +280,6 @@ def _shallow_copy_with_infer(self, values=None, **kwargs):
""" we always want to return a PeriodIndex """
return self._shallow_copy(values=values, **kwargs)

@property
def _box_func(self):
"""Maybe box an ordinal or Period"""
# TODO(DatetimeArray): Avoid double-boxing
# PeriodArray takes care of boxing already, so we need to check
# whether we're given an ordinal or a Period. It seems like some
# places outside of indexes/period.py are calling this _box_func,
# but passing data that's already boxed.
def func(x):
if isinstance(x, Period) or x is NaT:
return x
else:
return Period._from_ordinal(ordinal=x, freq=self.freq)

return func

def _maybe_convert_timedelta(self, other):
"""
Convert timedelta-like input to an integer multiple of self.freq
Expand Down
1 change: 0 additions & 1 deletion pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"_datetimelike_methods",
"_other_ops",
"components",
"_box_func",
"to_pytimedelta",
"sum",
"std",
Expand Down