Skip to content

CLN: datetimelike EA and Index cleanups #30591

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 2 commits into from
Jan 1, 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
16 changes: 8 additions & 8 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,6 @@ def to_timestamp(self, freq=None, how="start"):
# --------------------------------------------------------------------
# Array-like / EA-Interface Methods

def _formatter(self, boxed=False):
if boxed:
return str
return "'{}'".format

@Appender(dtl.DatetimeLikeArrayMixin._validate_fill_value.__doc__)
def _validate_fill_value(self, fill_value):
if isna(fill_value):
Expand All @@ -492,6 +487,9 @@ def _validate_fill_value(self, fill_value):
raise ValueError(f"'fill_value' should be a Period. Got '{fill_value}'.")
return fill_value

def _values_for_argsort(self):
return self._data

# --------------------------------------------------------------------

def _time_shift(self, periods, freq=None):
Expand Down Expand Up @@ -582,6 +580,11 @@ def asfreq(self, freq=None, how="E"):
# ------------------------------------------------------------------
# Rendering Methods

def _formatter(self, boxed=False):
if boxed:
return str
return "'{}'".format

def _format_native_types(self, na_rep="NaT", date_format=None, **kwargs):
"""
actually format my specific types
Expand Down Expand Up @@ -774,9 +777,6 @@ def _check_timedeltalike_freq_compat(self, other):

_raise_on_incompatible(self, other)

def _values_for_argsort(self):
return self._data


PeriodArray._add_comparison_ops()

Expand Down
3 changes: 3 additions & 0 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ def astype(self, dtype, copy=True):
return self
return dtl.DatetimeLikeArrayMixin.astype(self, dtype, copy=copy)

# ----------------------------------------------------------------
# Reductions

def sum(
self,
axis=None,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ class IndexOpsMixin:
# ndarray compatibility
__array_priority__ = 1000
_deprecations: FrozenSet[str] = frozenset(
["tolist", "item"] # tolist is not deprecated, just suppressed in the __dir__
["tolist"] # tolist is not deprecated, just suppressed in the __dir__
)

def transpose(self, *args, **kwargs):
Expand Down
1 change: 0 additions & 1 deletion pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ class DatetimeIndexOpsMixin(ExtensionOpsMixin):
)
resolution = cache_readonly(DatetimeLikeArrayMixin.resolution.fget) # type: ignore

_maybe_mask_results = ea_passthrough(DatetimeLikeArrayMixin._maybe_mask_results)
__iter__ = ea_passthrough(DatetimeLikeArrayMixin.__iter__)
mean = ea_passthrough(DatetimeLikeArrayMixin.mean)

Expand Down
4 changes: 1 addition & 3 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
DatetimeIndexOpsMixin,
DatetimelikeDelegateMixin,
DatetimeTimedeltaMixin,
ea_passthrough,
)
from pandas.core.indexes.numeric import Int64Index
from pandas.core.ops import get_op_result_name
Expand Down Expand Up @@ -1135,8 +1134,6 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
is_normalized = cache_readonly(DatetimeArray.is_normalized.fget) # type: ignore
_resolution = cache_readonly(DatetimeArray._resolution.fget) # type: ignore

_has_same_tz = ea_passthrough(DatetimeArray._has_same_tz)

def __getitem__(self, key):
result = self._data.__getitem__(key)
if is_scalar(result):
Expand Down Expand Up @@ -1202,6 +1199,7 @@ def insert(self, loc, item):
self._assert_can_do_op(item)
if not self._has_same_tz(item) and not isna(item):
raise ValueError("Passed item and index have different timezone")

# check freq can be preserved on edge cases
if self.size and self.freq is not None:
if item is NaT:
Expand Down
13 changes: 0 additions & 13 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
)

from pandas.core.accessor import delegate_names
from pandas.core.algorithms import unique1d
from pandas.core.arrays.period import PeriodArray, period_array, validate_dtype_freq
from pandas.core.base import _shared_docs
import pandas.core.common as com
Expand Down Expand Up @@ -622,18 +621,6 @@ def _get_unique_index(self, dropna=False):
res = res.dropna()
return res

@Appender(Index.unique.__doc__)
def unique(self, level=None):
# override the Index.unique method for performance GH#23083
if level is not None:
# this should never occur, but is retained to make the signature
# match Index.unique
self._validate_index_level(level)

values = self._ndarray_values
result = unique1d(values)
return self._shallow_copy(result)

def get_loc(self, key, method=None, tolerance=None):
"""
Get integer location for requested label
Expand Down
9 changes: 4 additions & 5 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
DatetimeIndexOpsMixin,
DatetimelikeDelegateMixin,
DatetimeTimedeltaMixin,
ea_passthrough,
)
from pandas.core.indexes.numeric import Int64Index
from pandas.core.ops import get_op_result_name
Expand All @@ -50,9 +49,12 @@ class TimedeltaDelegateMixin(DatetimelikeDelegateMixin):
"__neg__",
"__pos__",
"__abs__",
"sum",
"std",
"median",
]
_raw_properties = {"components"}
_raw_methods = {"to_pytimedelta"}
_raw_methods = {"to_pytimedelta", "sum", "std", "median"}


@delegate_names(
Expand Down Expand Up @@ -151,9 +153,6 @@ def _join_i8_wrapper(joinf, **kwargs):
_datetimelike_ops = TimedeltaArray._datetimelike_ops
_datetimelike_methods = TimedeltaArray._datetimelike_methods
_other_ops = TimedeltaArray._other_ops
sum = ea_passthrough(TimedeltaArray.sum)
std = ea_passthrough(TimedeltaArray.std)
median = ea_passthrough(TimedeltaArray.median)

# -------------------------------------------------------------------
# Constructors
Expand Down
1 change: 0 additions & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ def apply(self, func, **kwargs):
return nbs

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

return result
Expand Down