From 4d897f866b500a0988ef74a455e572080b8d464b Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Wed, 13 May 2020 22:40:05 +0200 Subject: [PATCH 1/3] CLN: remove methods of ExtensionIndex that duplicate base Index --- pandas/core/indexes/extension.py | 42 +------------------------------- 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/pandas/core/indexes/extension.py b/pandas/core/indexes/extension.py index 6e965ecea7cd8..664e49313507f 100644 --- a/pandas/core/indexes/extension.py +++ b/pandas/core/indexes/extension.py @@ -9,11 +9,7 @@ from pandas.errors import AbstractMethodError from pandas.util._decorators import cache_readonly, doc -from pandas.core.dtypes.common import ( - ensure_platform_int, - is_dtype_equal, - is_object_dtype, -) +from pandas.core.dtypes.common import is_dtype_equal, is_object_dtype from pandas.core.dtypes.generic import ABCSeries from pandas.core.arrays import ExtensionArray @@ -223,29 +219,14 @@ def __getitem__(self, key): deprecate_ndim_indexing(result) return result - def __iter__(self): - return self._data.__iter__() - # --------------------------------------------------------------------- - def __array__(self, dtype=None) -> np.ndarray: - return np.asarray(self._data, dtype=dtype) - def _get_engine_target(self) -> np.ndarray: # NB: _values_for_argsort happens to match the desired engine targets # for all of our existing EA-backed indexes, but in general # cannot be relied upon to exist. return self._data._values_for_argsort() - @doc(Index.dropna) - def dropna(self, how="any"): - if how not in ("any", "all"): - raise ValueError(f"invalid how option: {how}") - - if self.hasnans: - return self._shallow_copy(self._data[~self._isnan]) - return self._shallow_copy() - def repeat(self, repeats, axis=None): nv.validate_repeat(tuple(), dict(axis=axis)) result = self._data.repeat(repeats, axis=axis) @@ -259,27 +240,6 @@ def _concat_same_dtype(self, to_concat, name): arr = type(self._data)._concat_same_type(to_concat) return type(self)._simple_new(arr, name=name) - @doc(Index.take) - def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs): - nv.validate_take(tuple(), kwargs) - indices = ensure_platform_int(indices) - - taken = self._assert_take_fillable( - self._data, - indices, - allow_fill=allow_fill, - fill_value=fill_value, - na_value=self._na_value, - ) - return type(self)(taken, name=self.name) - - def unique(self, level=None): - if level is not None: - self._validate_index_level(level) - - result = self._data.unique() - return self._shallow_copy(result) - def _get_unique_index(self, dropna=False): if self.is_unique and not dropna: return self From 244ddc7394892f12570ecac3325a112c0668d6d8 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 14 May 2020 08:28:37 +0200 Subject: [PATCH 2/3] check the values instead of hasattr --- pandas/core/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 309b6e0ad5e1a..6702458005ca2 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -1257,8 +1257,7 @@ def value_counts( def unique(self): values = self._values - if hasattr(values, "unique"): - + if not isinstance(self._values, np.ndarray): result = values.unique() if self.dtype.kind in ["m", "M"] and isinstance(self, ABCSeries): # GH#31182 Series._values returns EA, unpack for backward-compat From cb05175d2cf2648a7fe4925815049a644873547b Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 15 May 2020 09:18:17 +0200 Subject: [PATCH 3/3] reuse values --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 6702458005ca2..a8a736b6aafdf 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -1257,7 +1257,7 @@ def value_counts( def unique(self): values = self._values - if not isinstance(self._values, np.ndarray): + if not isinstance(values, np.ndarray): result = values.unique() if self.dtype.kind in ["m", "M"] and isinstance(self, ABCSeries): # GH#31182 Series._values returns EA, unpack for backward-compat