Skip to content

CLN: Follow-ups to #24024 #24573

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 4 commits into from
Jan 3, 2019
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
3 changes: 0 additions & 3 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,6 @@ def unique(values):
if is_extension_array_dtype(values):
# Dispatch to extension dtype's unique.
return values.unique()
elif is_datetime64tz_dtype(values):
# TODO: merge this check into the previous one following #24024
return values.unique()

original = values
htable, _, values, dtype, ndtype = _get_hashtable_algo(values)
Expand Down
8 changes: 0 additions & 8 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ def cmp_method(self, other):
if isinstance(other, ABCDataFrame):
return NotImplemented

if isinstance(other, (np.ndarray, ABCIndexClass, ABCSeries, cls)):
if other.ndim > 0 and len(self) != len(other):
raise ValueError('Lengths must match to compare')

if needs_i8_conversion(self) and needs_i8_conversion(other):
# we may need to directly compare underlying
# representations
Expand Down Expand Up @@ -586,10 +582,6 @@ def view(self, dtype=None):

# ------------------------------------------------------------------
# ExtensionArray Interface
# TODO:
# * _from_sequence
# * argsort / _values_for_argsort
# * _reduce

def unique(self):
result = unique1d(self.asi8)
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ def __init__(self, values, dtype=_NS_DTYPE, freq=None, copy=False):
)
raise ValueError(msg.format(values.dtype))

dtype = pandas_dtype(dtype)
_validate_dt64_dtype(dtype)
dtype = _validate_dt64_dtype(dtype)

if freq == "infer":
msg = (
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3082,7 +3082,7 @@ def _box_item_values(self, key, values):
def _maybe_cache_changed(self, item, value):
"""The object has called back to us saying maybe it has changed.
"""
self._data.set(item, value, check=False)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check is never True, removed the corresponding code in internals.managers and internals.blocks

self._data.set(item, value)

@property
def _is_cached(self):
Expand Down
14 changes: 5 additions & 9 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def cmp_method(self, other):
if other.ndim > 0 and len(self) != len(other):
raise ValueError('Lengths must match to compare')

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

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

if level is not None and not is_list_like(level) and is_list_like(
Expand Down Expand Up @@ -3145,9 +3143,8 @@ def _reindex_non_unique(self, target):
@Appender(_index_shared_docs['join'])
def join(self, other, how='left', level=None, return_indexers=False,
sort=False):
from .multi import MultiIndex
self_is_mi = isinstance(self, MultiIndex)
other_is_mi = isinstance(other, MultiIndex)
self_is_mi = isinstance(self, ABCMultiIndex)
other_is_mi = isinstance(other, ABCMultiIndex)

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

# TODO: if we are a MultiIndex, we can do better
# that converting to tuples
from .multi import MultiIndex
if isinstance(values, MultiIndex):
if isinstance(values, ABCMultiIndex):
values = values.values
values = ensure_categorical(values)
result = values._reverse_indexer()
Expand Down
29 changes: 10 additions & 19 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,24 @@
_index_doc_kwargs = dict(ibase._index_doc_kwargs)


def ea_passthrough(name):
def ea_passthrough(array_method):
"""
Make an alias for a method of the underlying ExtensionArray.

Parameters
----------
name : str
array_method : method on an Array class

Returns
-------
method
"""

def method(self, *args, **kwargs):
return getattr(self._eadata, name)(*args, **kwargs)
return array_method(self._data, *args, **kwargs)

method.__name__ = name
# TODO: docstrings
method.__name__ = array_method.__name__
method.__doc__ = array_method.__doc__
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should address @jorisvandenbossche's point that docstrings are lost in the existing implementation

return method


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

_box_values = ea_passthrough("_box_values")
_maybe_mask_results = ea_passthrough("_maybe_mask_results")
__iter__ = ea_passthrough("__iter__")
_box_values = ea_passthrough(DatetimeLikeArrayMixin._box_values)
_maybe_mask_results = ea_passthrough(
DatetimeLikeArrayMixin._maybe_mask_results)
__iter__ = ea_passthrough(DatetimeLikeArrayMixin.__iter__)

@property
def _eadata(self):
Expand Down Expand Up @@ -275,9 +277,6 @@ def sort_values(self, return_indexer=False, ascending=True):
if not ascending:
sorted_values = sorted_values[::-1]

sorted_values = self._maybe_box_as_values(sorted_values,
**attribs)

return self._simple_new(sorted_values, **attribs)

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

def _maybe_box_as_values(self, values, **attribs):
# TODO(DatetimeArray): remove
# This is a temporary shim while PeriodArray is an ExtensoinArray,
# but others are not. When everyone is an ExtensionArray, this can
# be removed. Currently used in
# - sort_values
return values

@Appender(_index_shared_docs['astype'])
def astype(self, dtype, copy=True):
if is_dtype_equal(self.dtype, dtype) and copy is False:
Expand Down
40 changes: 5 additions & 35 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,36 +356,6 @@ def tz(self, value):

tzinfo = tz

@property
def size(self):
# TODO: Remove this when we have a DatetimeTZArray
# Necessary to avoid recursion error since DTI._values is a DTI
# for TZ-aware
return self._ndarray_values.size

@property
def shape(self):
# TODO: Remove this when we have a DatetimeTZArray
# Necessary to avoid recursion error since DTI._values is a DTI
# for TZ-aware
return self._ndarray_values.shape

@property
def nbytes(self):
# TODO: Remove this when we have a DatetimeTZArray
# Necessary to avoid recursion error since DTI._values is a DTI
# for TZ-aware
return self._ndarray_values.nbytes

def memory_usage(self, deep=False):
# TODO: Remove this when we have a DatetimeTZArray
# Necessary to avoid recursion error since DTI._values is a DTI
# for TZ-aware
result = self._ndarray_values.nbytes
# include our engine hashtable
result += self._engine.sizeof(deep=deep)
return result

@cache_readonly
def _is_dates_only(self):
"""Return a boolean if we are only dates (and don't have a timezone)"""
Expand Down Expand Up @@ -455,11 +425,11 @@ def _mpl_repr(self):

def _format_native_types(self, na_rep='NaT', date_format=None, **kwargs):
from pandas.io.formats.format import _get_format_datetime64_from_values
format = _get_format_datetime64_from_values(self, date_format)
fmt = _get_format_datetime64_from_values(self, date_format)

return libts.format_array_from_datetime(self.asi8,
tz=self.tz,
format=format,
format=fmt,
na_rep=na_rep)

@property
Expand Down Expand Up @@ -1142,9 +1112,9 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
is_normalized = cache_readonly(DatetimeArray.is_normalized.fget)
_resolution = cache_readonly(DatetimeArray._resolution.fget)

strftime = ea_passthrough("strftime")
_has_same_tz = ea_passthrough("_has_same_tz")
__array__ = ea_passthrough("__array__")
strftime = ea_passthrough(DatetimeArray.strftime)
_has_same_tz = ea_passthrough(DatetimeArray._has_same_tz)
__array__ = ea_passthrough(DatetimeArray.__array__)

@property
def offset(self):
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,9 +1468,9 @@ def to_frame(self, index=True, name=None):
# Guarantee resulting column order
result = DataFrame(
OrderedDict([
((level if name is None else name),
((level if lvlname is None else lvlname),
self._get_level_values(level))
for name, level in zip(idx_names, range(len(self.levels)))
for lvlname, level in zip(idx_names, range(len(self.levels)))
]),
copy=False
)
Expand Down
11 changes: 0 additions & 11 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,17 +357,6 @@ def func(x):
return Period._from_ordinal(ordinal=x, freq=self.freq)
return func

def _maybe_box_as_values(self, values, **attribs):
"""Box an array of ordinals to a PeriodArray

This is purely for compatibility between PeriodIndex
and Datetime/TimedeltaIndex. Once these are all backed by
an ExtensionArray, this can be removed
"""
# TODO(DatetimeArray): remove
freq = attribs['freq']
return PeriodArray(values, freq=freq)

def _maybe_convert_timedelta(self, other):
"""
Convert timedelta-like input to an integer multiple of self.freq
Expand Down
5 changes: 0 additions & 5 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,6 @@ def _format_native_types(self, na_rep='NaT', date_format=None, **kwargs):
_is_monotonic_decreasing = Index.is_monotonic_decreasing
_is_unique = Index.is_unique

_create_comparison_method = DatetimeIndexOpsMixin._create_comparison_method
# TODO: make sure we have a test for name retention analogous
# to series.test_arithmetic.test_ser_cmp_result_names;
# also for PeriodIndex which I think may be missing one

@property
def _box_func(self):
return lambda x: Timedelta(x, unit='ns')
Expand Down
17 changes: 4 additions & 13 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def concat_same_type(self, to_concat, placement=None):
def iget(self, i):
return self.values[i]

def set(self, locs, values, check=False):
def set(self, locs, values):
"""
Modify Block in-place with new item value

Expand Down Expand Up @@ -2416,22 +2416,14 @@ def f(m, v, i):

return blocks

def set(self, locs, values, check=False):
def set(self, locs, values):
"""
Modify Block in-place with new item value

Returns
-------
None
"""

# GH6026
if check:
try:
if (self.values[locs] == values).all():
return
except (IndexError, ValueError):
pass
try:
self.values[locs] = values
except (ValueError):
Expand Down Expand Up @@ -2902,7 +2894,7 @@ def should_store(self, value):
not is_datetime64tz_dtype(value) and
not is_extension_array_dtype(value))

def set(self, locs, values, check=False):
def set(self, locs, values):
"""
Modify Block in-place with new item value

Expand Down Expand Up @@ -3053,8 +3045,7 @@ def _try_coerce_args(self, values, other):
elif (is_null_datelike_scalar(other) or
(lib.is_scalar(other) and isna(other))):
other = tslibs.iNaT
elif isinstance(other, (self._holder, DatetimeArray)):
# TODO: DatetimeArray check will be redundant after GH#24024
elif isinstance(other, self._holder):
if other.tz != self.values.tz:
raise ValueError("incompatible or non tz-aware value")
other = _block_shape(other.asi8, ndim=self.ndim)
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,11 +1009,10 @@ def delete(self, item):
self._shape = None
self._rebuild_blknos_and_blklocs()

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