Skip to content

Commit 1fc76b8

Browse files
jbrockmendeljreback
authored andcommitted
CLN: Follow-ups to #24024 (#24573)
1 parent 588b558 commit 1fc76b8

13 files changed

+44
-126
lines changed

pandas/core/algorithms.py

-3
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,6 @@ def unique(values):
350350
if is_extension_array_dtype(values):
351351
# Dispatch to extension dtype's unique.
352352
return values.unique()
353-
elif is_datetime64tz_dtype(values):
354-
# TODO: merge this check into the previous one following #24024
355-
return values.unique()
356353

357354
original = values
358355
htable, _, values, dtype, ndtype = _get_hashtable_algo(values)

pandas/core/arrays/datetimelike.py

-8
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ def cmp_method(self, other):
4747
if isinstance(other, ABCDataFrame):
4848
return NotImplemented
4949

50-
if isinstance(other, (np.ndarray, ABCIndexClass, ABCSeries, cls)):
51-
if other.ndim > 0 and len(self) != len(other):
52-
raise ValueError('Lengths must match to compare')
53-
5450
if needs_i8_conversion(self) and needs_i8_conversion(other):
5551
# we may need to directly compare underlying
5652
# representations
@@ -586,10 +582,6 @@ def view(self, dtype=None):
586582

587583
# ------------------------------------------------------------------
588584
# ExtensionArray Interface
589-
# TODO:
590-
# * _from_sequence
591-
# * argsort / _values_for_argsort
592-
# * _reduce
593585

594586
def unique(self):
595587
result = unique1d(self.asi8)

pandas/core/arrays/datetimes.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ def __init__(self, values, dtype=_NS_DTYPE, freq=None, copy=False):
280280
)
281281
raise ValueError(msg.format(values.dtype))
282282

283-
dtype = pandas_dtype(dtype)
284-
_validate_dt64_dtype(dtype)
283+
dtype = _validate_dt64_dtype(dtype)
285284

286285
if freq == "infer":
287286
msg = (

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3082,7 +3082,7 @@ def _box_item_values(self, key, values):
30823082
def _maybe_cache_changed(self, item, value):
30833083
"""The object has called back to us saying maybe it has changed.
30843084
"""
3085-
self._data.set(item, value, check=False)
3085+
self._data.set(item, value)
30863086

30873087
@property
30883088
def _is_cached(self):

pandas/core/indexes/base.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def cmp_method(self, other):
6868
if other.ndim > 0 and len(self) != len(other):
6969
raise ValueError('Lengths must match to compare')
7070

71-
from .multi import MultiIndex
72-
if is_object_dtype(self) and not isinstance(self, MultiIndex):
71+
if is_object_dtype(self) and not isinstance(self, ABCMultiIndex):
7372
# don't pass MultiIndex
7473
with np.errstate(all='ignore'):
7574
result = ops._comp_method_OBJECT_ARRAY(op, self.values, other)
@@ -1307,8 +1306,7 @@ def set_names(self, names, level=None, inplace=False):
13071306
names=['species', 'year'])
13081307
"""
13091308

1310-
from .multi import MultiIndex
1311-
if level is not None and not isinstance(self, MultiIndex):
1309+
if level is not None and not isinstance(self, ABCMultiIndex):
13121310
raise ValueError('Level must be None for non-MultiIndex')
13131311

13141312
if level is not None and not is_list_like(level) and is_list_like(
@@ -3145,9 +3143,8 @@ def _reindex_non_unique(self, target):
31453143
@Appender(_index_shared_docs['join'])
31463144
def join(self, other, how='left', level=None, return_indexers=False,
31473145
sort=False):
3148-
from .multi import MultiIndex
3149-
self_is_mi = isinstance(self, MultiIndex)
3150-
other_is_mi = isinstance(other, MultiIndex)
3146+
self_is_mi = isinstance(self, ABCMultiIndex)
3147+
other_is_mi = isinstance(other, ABCMultiIndex)
31513148

31523149
# try to figure out the join level
31533150
# GH3662
@@ -4394,8 +4391,7 @@ def groupby(self, values):
43944391

43954392
# TODO: if we are a MultiIndex, we can do better
43964393
# that converting to tuples
4397-
from .multi import MultiIndex
4398-
if isinstance(values, MultiIndex):
4394+
if isinstance(values, ABCMultiIndex):
43994395
values = values.values
44004396
values = ensure_categorical(values)
44014397
result = values._reverse_indexer()

pandas/core/indexes/datetimelike.py

+10-19
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,24 @@
3131
_index_doc_kwargs = dict(ibase._index_doc_kwargs)
3232

3333

34-
def ea_passthrough(name):
34+
def ea_passthrough(array_method):
3535
"""
3636
Make an alias for a method of the underlying ExtensionArray.
3737
3838
Parameters
3939
----------
40-
name : str
40+
array_method : method on an Array class
4141
4242
Returns
4343
-------
4444
method
4545
"""
46+
4647
def method(self, *args, **kwargs):
47-
return getattr(self._eadata, name)(*args, **kwargs)
48+
return array_method(self._data, *args, **kwargs)
4849

49-
method.__name__ = name
50-
# TODO: docstrings
50+
method.__name__ = array_method.__name__
51+
method.__doc__ = array_method.__doc__
5152
return method
5253

5354

@@ -67,9 +68,10 @@ class DatetimeIndexOpsMixin(ExtensionOpsMixin):
6768
_resolution = cache_readonly(DatetimeLikeArrayMixin._resolution.fget)
6869
resolution = cache_readonly(DatetimeLikeArrayMixin.resolution.fget)
6970

70-
_box_values = ea_passthrough("_box_values")
71-
_maybe_mask_results = ea_passthrough("_maybe_mask_results")
72-
__iter__ = ea_passthrough("__iter__")
71+
_box_values = ea_passthrough(DatetimeLikeArrayMixin._box_values)
72+
_maybe_mask_results = ea_passthrough(
73+
DatetimeLikeArrayMixin._maybe_mask_results)
74+
__iter__ = ea_passthrough(DatetimeLikeArrayMixin.__iter__)
7375

7476
@property
7577
def _eadata(self):
@@ -275,9 +277,6 @@ def sort_values(self, return_indexer=False, ascending=True):
275277
if not ascending:
276278
sorted_values = sorted_values[::-1]
277279

278-
sorted_values = self._maybe_box_as_values(sorted_values,
279-
**attribs)
280-
281280
return self._simple_new(sorted_values, **attribs)
282281

283282
@Appender(_index_shared_docs['take'] % _index_doc_kwargs)
@@ -613,14 +612,6 @@ def _concat_same_dtype(self, to_concat, name):
613612
new_data = type(self._values)._concat_same_type(to_concat).asi8
614613
return self._simple_new(new_data, **attribs)
615614

616-
def _maybe_box_as_values(self, values, **attribs):
617-
# TODO(DatetimeArray): remove
618-
# This is a temporary shim while PeriodArray is an ExtensoinArray,
619-
# but others are not. When everyone is an ExtensionArray, this can
620-
# be removed. Currently used in
621-
# - sort_values
622-
return values
623-
624615
@Appender(_index_shared_docs['astype'])
625616
def astype(self, dtype, copy=True):
626617
if is_dtype_equal(self.dtype, dtype) and copy is False:

pandas/core/indexes/datetimes.py

+5-35
Original file line numberDiff line numberDiff line change
@@ -356,36 +356,6 @@ def tz(self, value):
356356

357357
tzinfo = tz
358358

359-
@property
360-
def size(self):
361-
# TODO: Remove this when we have a DatetimeTZArray
362-
# Necessary to avoid recursion error since DTI._values is a DTI
363-
# for TZ-aware
364-
return self._ndarray_values.size
365-
366-
@property
367-
def shape(self):
368-
# TODO: Remove this when we have a DatetimeTZArray
369-
# Necessary to avoid recursion error since DTI._values is a DTI
370-
# for TZ-aware
371-
return self._ndarray_values.shape
372-
373-
@property
374-
def nbytes(self):
375-
# TODO: Remove this when we have a DatetimeTZArray
376-
# Necessary to avoid recursion error since DTI._values is a DTI
377-
# for TZ-aware
378-
return self._ndarray_values.nbytes
379-
380-
def memory_usage(self, deep=False):
381-
# TODO: Remove this when we have a DatetimeTZArray
382-
# Necessary to avoid recursion error since DTI._values is a DTI
383-
# for TZ-aware
384-
result = self._ndarray_values.nbytes
385-
# include our engine hashtable
386-
result += self._engine.sizeof(deep=deep)
387-
return result
388-
389359
@cache_readonly
390360
def _is_dates_only(self):
391361
"""Return a boolean if we are only dates (and don't have a timezone)"""
@@ -455,11 +425,11 @@ def _mpl_repr(self):
455425

456426
def _format_native_types(self, na_rep='NaT', date_format=None, **kwargs):
457427
from pandas.io.formats.format import _get_format_datetime64_from_values
458-
format = _get_format_datetime64_from_values(self, date_format)
428+
fmt = _get_format_datetime64_from_values(self, date_format)
459429

460430
return libts.format_array_from_datetime(self.asi8,
461431
tz=self.tz,
462-
format=format,
432+
format=fmt,
463433
na_rep=na_rep)
464434

465435
@property
@@ -1142,9 +1112,9 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
11421112
is_normalized = cache_readonly(DatetimeArray.is_normalized.fget)
11431113
_resolution = cache_readonly(DatetimeArray._resolution.fget)
11441114

1145-
strftime = ea_passthrough("strftime")
1146-
_has_same_tz = ea_passthrough("_has_same_tz")
1147-
__array__ = ea_passthrough("__array__")
1115+
strftime = ea_passthrough(DatetimeArray.strftime)
1116+
_has_same_tz = ea_passthrough(DatetimeArray._has_same_tz)
1117+
__array__ = ea_passthrough(DatetimeArray.__array__)
11481118

11491119
@property
11501120
def offset(self):

pandas/core/indexes/multi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1468,9 +1468,9 @@ def to_frame(self, index=True, name=None):
14681468
# Guarantee resulting column order
14691469
result = DataFrame(
14701470
OrderedDict([
1471-
((level if name is None else name),
1471+
((level if lvlname is None else lvlname),
14721472
self._get_level_values(level))
1473-
for name, level in zip(idx_names, range(len(self.levels)))
1473+
for lvlname, level in zip(idx_names, range(len(self.levels)))
14741474
]),
14751475
copy=False
14761476
)

pandas/core/indexes/period.py

-11
Original file line numberDiff line numberDiff line change
@@ -357,17 +357,6 @@ def func(x):
357357
return Period._from_ordinal(ordinal=x, freq=self.freq)
358358
return func
359359

360-
def _maybe_box_as_values(self, values, **attribs):
361-
"""Box an array of ordinals to a PeriodArray
362-
363-
This is purely for compatibility between PeriodIndex
364-
and Datetime/TimedeltaIndex. Once these are all backed by
365-
an ExtensionArray, this can be removed
366-
"""
367-
# TODO(DatetimeArray): remove
368-
freq = attribs['freq']
369-
return PeriodArray(values, freq=freq)
370-
371360
def _maybe_convert_timedelta(self, other):
372361
"""
373362
Convert timedelta-like input to an integer multiple of self.freq

pandas/core/indexes/timedeltas.py

-5
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,6 @@ def _format_native_types(self, na_rep='NaT', date_format=None, **kwargs):
303303
_is_monotonic_decreasing = Index.is_monotonic_decreasing
304304
_is_unique = Index.is_unique
305305

306-
_create_comparison_method = DatetimeIndexOpsMixin._create_comparison_method
307-
# TODO: make sure we have a test for name retention analogous
308-
# to series.test_arithmetic.test_ser_cmp_result_names;
309-
# also for PeriodIndex which I think may be missing one
310-
311306
@property
312307
def _box_func(self):
313308
return lambda x: Timedelta(x, unit='ns')

pandas/core/internals/blocks.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def concat_same_type(self, to_concat, placement=None):
338338
def iget(self, i):
339339
return self.values[i]
340340

341-
def set(self, locs, values, check=False):
341+
def set(self, locs, values):
342342
"""
343343
Modify Block in-place with new item value
344344
@@ -2416,22 +2416,14 @@ def f(m, v, i):
24162416

24172417
return blocks
24182418

2419-
def set(self, locs, values, check=False):
2419+
def set(self, locs, values):
24202420
"""
24212421
Modify Block in-place with new item value
24222422
24232423
Returns
24242424
-------
24252425
None
24262426
"""
2427-
2428-
# GH6026
2429-
if check:
2430-
try:
2431-
if (self.values[locs] == values).all():
2432-
return
2433-
except (IndexError, ValueError):
2434-
pass
24352427
try:
24362428
self.values[locs] = values
24372429
except (ValueError):
@@ -2902,7 +2894,7 @@ def should_store(self, value):
29022894
not is_datetime64tz_dtype(value) and
29032895
not is_extension_array_dtype(value))
29042896

2905-
def set(self, locs, values, check=False):
2897+
def set(self, locs, values):
29062898
"""
29072899
Modify Block in-place with new item value
29082900
@@ -3053,8 +3045,7 @@ def _try_coerce_args(self, values, other):
30533045
elif (is_null_datelike_scalar(other) or
30543046
(lib.is_scalar(other) and isna(other))):
30553047
other = tslibs.iNaT
3056-
elif isinstance(other, (self._holder, DatetimeArray)):
3057-
# TODO: DatetimeArray check will be redundant after GH#24024
3048+
elif isinstance(other, self._holder):
30583049
if other.tz != self.values.tz:
30593050
raise ValueError("incompatible or non tz-aware value")
30603051
other = _block_shape(other.asi8, ndim=self.ndim)

pandas/core/internals/managers.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1009,11 +1009,10 @@ def delete(self, item):
10091009
self._shape = None
10101010
self._rebuild_blknos_and_blklocs()
10111011

1012-
def set(self, item, value, check=False):
1012+
def set(self, item, value):
10131013
"""
10141014
Set new item in-place. Does not consolidate. Adds new Block if not
10151015
contained in the current set of items
1016-
if check, then validate that we are not setting the same data in-place
10171016
"""
10181017
# FIXME: refactor, clearly separate broadcasting & zip-like assignment
10191018
# can prob also fix the various if tests for sparse/categorical
@@ -1065,7 +1064,7 @@ def value_getitem(placement):
10651064
blk = self.blocks[blkno]
10661065
blk_locs = blklocs[val_locs.indexer]
10671066
if blk.should_store(value):
1068-
blk.set(blk_locs, value_getitem(val_locs), check=check)
1067+
blk.set(blk_locs, value_getitem(val_locs))
10691068
else:
10701069
unfit_mgr_locs.append(blk.mgr_locs.as_array[blk_locs])
10711070
unfit_val_locs.append(val_locs)

0 commit comments

Comments
 (0)