Skip to content

Commit e27bbea

Browse files
jbrockmendelhweecat
authored andcommitted
CLN: datetimelike EA and Index cleanups (pandas-dev#30591)
1 parent 6ff12ee commit e27bbea

File tree

8 files changed

+17
-32
lines changed

8 files changed

+17
-32
lines changed

pandas/core/arrays/period.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,6 @@ def to_timestamp(self, freq=None, how="start"):
476476
# --------------------------------------------------------------------
477477
# Array-like / EA-Interface Methods
478478

479-
def _formatter(self, boxed=False):
480-
if boxed:
481-
return str
482-
return "'{}'".format
483-
484479
@Appender(dtl.DatetimeLikeArrayMixin._validate_fill_value.__doc__)
485480
def _validate_fill_value(self, fill_value):
486481
if isna(fill_value):
@@ -492,6 +487,9 @@ def _validate_fill_value(self, fill_value):
492487
raise ValueError(f"'fill_value' should be a Period. Got '{fill_value}'.")
493488
return fill_value
494489

490+
def _values_for_argsort(self):
491+
return self._data
492+
495493
# --------------------------------------------------------------------
496494

497495
def _time_shift(self, periods, freq=None):
@@ -582,6 +580,11 @@ def asfreq(self, freq=None, how="E"):
582580
# ------------------------------------------------------------------
583581
# Rendering Methods
584582

583+
def _formatter(self, boxed=False):
584+
if boxed:
585+
return str
586+
return "'{}'".format
587+
585588
def _format_native_types(self, na_rep="NaT", date_format=None, **kwargs):
586589
"""
587590
actually format my specific types
@@ -774,9 +777,6 @@ def _check_timedeltalike_freq_compat(self, other):
774777

775778
_raise_on_incompatible(self, other)
776779

777-
def _values_for_argsort(self):
778-
return self._data
779-
780780

781781
PeriodArray._add_comparison_ops()
782782

pandas/core/arrays/timedeltas.py

+3
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ def astype(self, dtype, copy=True):
378378
return self
379379
return dtl.DatetimeLikeArrayMixin.astype(self, dtype, copy=copy)
380380

381+
# ----------------------------------------------------------------
382+
# Reductions
383+
381384
def sum(
382385
self,
383386
axis=None,

pandas/core/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ class IndexOpsMixin:
625625
# ndarray compatibility
626626
__array_priority__ = 1000
627627
_deprecations: FrozenSet[str] = frozenset(
628-
["tolist", "item"] # tolist is not deprecated, just suppressed in the __dir__
628+
["tolist"] # tolist is not deprecated, just suppressed in the __dir__
629629
)
630630

631631
def transpose(self, *args, **kwargs):

pandas/core/indexes/datetimelike.py

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ class DatetimeIndexOpsMixin(ExtensionOpsMixin):
122122
)
123123
resolution = cache_readonly(DatetimeLikeArrayMixin.resolution.fget) # type: ignore
124124

125-
_maybe_mask_results = ea_passthrough(DatetimeLikeArrayMixin._maybe_mask_results)
126125
__iter__ = ea_passthrough(DatetimeLikeArrayMixin.__iter__)
127126
mean = ea_passthrough(DatetimeLikeArrayMixin.mean)
128127

pandas/core/indexes/datetimes.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
DatetimeIndexOpsMixin,
3636
DatetimelikeDelegateMixin,
3737
DatetimeTimedeltaMixin,
38-
ea_passthrough,
3938
)
4039
from pandas.core.indexes.numeric import Int64Index
4140
from pandas.core.ops import get_op_result_name
@@ -1135,8 +1134,6 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
11351134
is_normalized = cache_readonly(DatetimeArray.is_normalized.fget) # type: ignore
11361135
_resolution = cache_readonly(DatetimeArray._resolution.fget) # type: ignore
11371136

1138-
_has_same_tz = ea_passthrough(DatetimeArray._has_same_tz)
1139-
11401137
def __getitem__(self, key):
11411138
result = self._data.__getitem__(key)
11421139
if is_scalar(result):
@@ -1202,6 +1199,7 @@ def insert(self, loc, item):
12021199
self._assert_can_do_op(item)
12031200
if not self._has_same_tz(item) and not isna(item):
12041201
raise ValueError("Passed item and index have different timezone")
1202+
12051203
# check freq can be preserved on edge cases
12061204
if self.size and self.freq is not None:
12071205
if item is NaT:

pandas/core/indexes/period.py

-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
)
2121

2222
from pandas.core.accessor import delegate_names
23-
from pandas.core.algorithms import unique1d
2423
from pandas.core.arrays.period import PeriodArray, period_array, validate_dtype_freq
2524
from pandas.core.base import _shared_docs
2625
import pandas.core.common as com
@@ -622,18 +621,6 @@ def _get_unique_index(self, dropna=False):
622621
res = res.dropna()
623622
return res
624623

625-
@Appender(Index.unique.__doc__)
626-
def unique(self, level=None):
627-
# override the Index.unique method for performance GH#23083
628-
if level is not None:
629-
# this should never occur, but is retained to make the signature
630-
# match Index.unique
631-
self._validate_index_level(level)
632-
633-
values = self._ndarray_values
634-
result = unique1d(values)
635-
return self._shallow_copy(result)
636-
637624
def get_loc(self, key, method=None, tolerance=None):
638625
"""
639626
Get integer location for requested label

pandas/core/indexes/timedeltas.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
DatetimeIndexOpsMixin,
3131
DatetimelikeDelegateMixin,
3232
DatetimeTimedeltaMixin,
33-
ea_passthrough,
3433
)
3534
from pandas.core.indexes.numeric import Int64Index
3635
from pandas.core.ops import get_op_result_name
@@ -50,9 +49,12 @@ class TimedeltaDelegateMixin(DatetimelikeDelegateMixin):
5049
"__neg__",
5150
"__pos__",
5251
"__abs__",
52+
"sum",
53+
"std",
54+
"median",
5355
]
5456
_raw_properties = {"components"}
55-
_raw_methods = {"to_pytimedelta"}
57+
_raw_methods = {"to_pytimedelta", "sum", "std", "median"}
5658

5759

5860
@delegate_names(
@@ -151,9 +153,6 @@ def _join_i8_wrapper(joinf, **kwargs):
151153
_datetimelike_ops = TimedeltaArray._datetimelike_ops
152154
_datetimelike_methods = TimedeltaArray._datetimelike_methods
153155
_other_ops = TimedeltaArray._other_ops
154-
sum = ea_passthrough(TimedeltaArray.sum)
155-
std = ea_passthrough(TimedeltaArray.std)
156-
median = ea_passthrough(TimedeltaArray.median)
157156

158157
# -------------------------------------------------------------------
159158
# Constructors

pandas/core/internals/blocks.py

-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ def apply(self, func, **kwargs):
380380
return nbs
381381

382382
if not isinstance(result, Block):
383-
# Exclude the 0-dim case so we can do reductions
384383
result = self.make_block(values=_block_shape(result, ndim=self.ndim))
385384

386385
return result

0 commit comments

Comments
 (0)