Skip to content

Commit db16a8f

Browse files
authored
CLN: inherit PeriodIndex._box_func (#31512)
1 parent e2ae57c commit db16a8f

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

pandas/core/indexes/datetimelike.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,16 @@ def wrapper(left, right):
8080
cache=True,
8181
)
8282
@inherit_names(
83-
["__iter__", "mean", "freq", "freqstr", "_ndarray_values", "asi8", "_box_values"],
83+
[
84+
"__iter__",
85+
"mean",
86+
"freq",
87+
"freqstr",
88+
"_ndarray_values",
89+
"asi8",
90+
"_box_values",
91+
"_box_func",
92+
],
8493
DatetimeLikeArrayMixin,
8594
)
8695
class DatetimeIndexOpsMixin(ExtensionIndex):

pandas/core/indexes/datetimes.py

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def _new_DatetimeIndex(cls, d):
7070
"_field_ops",
7171
"_datetimelike_ops",
7272
"_datetimelike_methods",
73-
"_box_func",
7473
"tz",
7574
"tzinfo",
7675
"dtype",

pandas/core/indexes/period.py

-16
Original file line numberDiff line numberDiff line change
@@ -280,22 +280,6 @@ def _shallow_copy_with_infer(self, values=None, **kwargs):
280280
""" we always want to return a PeriodIndex """
281281
return self._shallow_copy(values=values, **kwargs)
282282

283-
@property
284-
def _box_func(self):
285-
"""Maybe box an ordinal or Period"""
286-
# TODO(DatetimeArray): Avoid double-boxing
287-
# PeriodArray takes care of boxing already, so we need to check
288-
# whether we're given an ordinal or a Period. It seems like some
289-
# places outside of indexes/period.py are calling this _box_func,
290-
# but passing data that's already boxed.
291-
def func(x):
292-
if isinstance(x, Period) or x is NaT:
293-
return x
294-
else:
295-
return Period._from_ordinal(ordinal=x, freq=self.freq)
296-
297-
return func
298-
299283
def _maybe_convert_timedelta(self, other):
300284
"""
301285
Convert timedelta-like input to an integer multiple of self.freq

pandas/core/indexes/timedeltas.py

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"_datetimelike_methods",
5252
"_other_ops",
5353
"components",
54-
"_box_func",
5554
"to_pytimedelta",
5655
"sum",
5756
"std",

0 commit comments

Comments
 (0)