From 5006372b8708347cb04dbd1bd9ec5e2fe8175a8d Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 3 May 2020 12:00:05 -0700 Subject: [PATCH] CLN: remove ABCSparseArray --- pandas/core/arrays/sparse/array.py | 6 +++--- pandas/core/dtypes/generic.py | 1 - pandas/core/ops/methods.py | 10 ++-------- pandas/tests/dtypes/test_generic.py | 2 +- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index e327e11a17f4f..0877e98e55311 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -35,7 +35,7 @@ is_string_dtype, pandas_dtype, ) -from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries, ABCSparseArray +from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries from pandas.core.dtypes.missing import isna, na_value_for_dtype, notna import pandas.core.algorithms as algos @@ -58,7 +58,7 @@ _sparray_doc_kwargs = dict(klass="SparseArray") -def _get_fill(arr: ABCSparseArray) -> np.ndarray: +def _get_fill(arr: "SparseArray") -> np.ndarray: """ Create a 0-dim ndarray containing the fill value @@ -83,7 +83,7 @@ def _get_fill(arr: ABCSparseArray) -> np.ndarray: def _sparse_array_op( - left: ABCSparseArray, right: ABCSparseArray, op: Callable, name: str + left: "SparseArray", right: "SparseArray", op: Callable, name: str ) -> Any: """ Perform a binary operation between two arrays. diff --git a/pandas/core/dtypes/generic.py b/pandas/core/dtypes/generic.py index 7f98ca3d402bc..ea6ce2618c7ff 100644 --- a/pandas/core/dtypes/generic.py +++ b/pandas/core/dtypes/generic.py @@ -56,7 +56,6 @@ def _check(cls, inst) -> bool: ABCSeries = create_pandas_abc_type("ABCSeries", "_typ", ("series",)) ABCDataFrame = create_pandas_abc_type("ABCDataFrame", "_typ", ("dataframe",)) -ABCSparseArray = create_pandas_abc_type("ABCSparseArray", "_subtyp", ("sparse_array",)) ABCCategorical = create_pandas_abc_type("ABCCategorical", "_typ", ("categorical")) ABCDatetimeArray = create_pandas_abc_type("ABCDatetimeArray", "_typ", ("datetimearray")) ABCTimedeltaArray = create_pandas_abc_type( diff --git a/pandas/core/ops/methods.py b/pandas/core/ops/methods.py index 7c63bc43de67e..63086f62b6445 100644 --- a/pandas/core/ops/methods.py +++ b/pandas/core/ops/methods.py @@ -3,7 +3,7 @@ """ import operator -from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries, ABCSparseArray +from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries from pandas.core.ops.roperator import ( radd, @@ -225,10 +225,4 @@ def _create_methods(cls, arith_method, comp_method, bool_method, special): def _add_methods(cls, new_methods): for name, method in new_methods.items(): - # For most methods, if we find that the class already has a method - # of the same name, it is OK to over-write it. The exception is - # inplace methods (__iadd__, __isub__, ...) for SparseArray, which - # retain the np.ndarray versions. - force = not (issubclass(cls, ABCSparseArray) and name.startswith("__i")) - if force or name not in cls.__dict__: - setattr(cls, name, method) + setattr(cls, name, method) diff --git a/pandas/tests/dtypes/test_generic.py b/pandas/tests/dtypes/test_generic.py index f9ee943d9e6bf..8023b4e2c19d9 100644 --- a/pandas/tests/dtypes/test_generic.py +++ b/pandas/tests/dtypes/test_generic.py @@ -35,7 +35,7 @@ def test_abc_types(self): assert isinstance(pd.Int64Index([1, 2, 3]), gt.ABCIndexClass) assert isinstance(pd.Series([1, 2, 3]), gt.ABCSeries) assert isinstance(self.df, gt.ABCDataFrame) - assert isinstance(self.sparse_array, gt.ABCSparseArray) + assert isinstance(self.sparse_array, gt.ABCExtensionArray) assert isinstance(self.categorical, gt.ABCCategorical) assert isinstance(pd.DateOffset(), gt.ABCDateOffset)