diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 67a0e02fc2d4d4..aa69f57336f68f 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -50,7 +50,7 @@ from pandas.core.dtypes.generic import ( ABCDatetimeArray, ABCExtensionArray, - ABCIndexClass, + ABCIndex, ABCMultiIndex, ABCRangeIndex, ABCSeries, @@ -63,6 +63,7 @@ if TYPE_CHECKING: from pandas import Categorical, DataFrame, Index, Series + from pandas.core.arrays import DatetimeArray, TimedeltaArray _shared_docs: Dict[str, str] = {} @@ -215,7 +216,7 @@ def _reconstruct_data( values = values.astype(dtype, copy=False) # we only support object dtypes bool Index - if isinstance(original, ABCIndexClass): + if isinstance(original, ABCIndex): values = values.astype(object, copy=False) elif dtype is not None: if is_datetime64_dtype(dtype): @@ -437,9 +438,7 @@ def isin(comps: AnyArrayLike, values: AnyArrayLike) -> np.ndarray: f"to isin(), you passed a [{type(values).__name__}]" ) - if not isinstance( - values, (ABCIndexClass, ABCSeries, ABCExtensionArray, np.ndarray) - ): + if not isinstance(values, (ABCIndex, ABCSeries, ABCExtensionArray, np.ndarray)): values = _ensure_arraylike(list(values)) elif isinstance(values, ABCMultiIndex): # Avoid raising in extract_array @@ -700,7 +699,7 @@ def factorize( and values.freq is not None ): codes, uniques = values.factorize(sort=sort) - if isinstance(original, ABCIndexClass): + if isinstance(original, ABCIndex): uniques = original._shallow_copy(uniques, name=None) elif isinstance(original, ABCSeries): from pandas import Index @@ -739,8 +738,11 @@ def factorize( uniques = _reconstruct_data(uniques, dtype, original) # return original tenor - if isinstance(original, ABCIndexClass): + if isinstance(original, ABCIndex): if original.dtype.kind in ["m", "M"] and isinstance(uniques, np.ndarray): + original._data = cast( + "Union[DatetimeArray, TimedeltaArray]", original._data + ) uniques = type(original._data)._simple_new(uniques, dtype=original.dtype) uniques = original._shallow_copy(uniques, name=None) elif isinstance(original, ABCSeries): diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 95470422f2ccd3..bd5cf43e19e9f7 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -41,7 +41,7 @@ pandas_dtype, ) from pandas.core.dtypes.dtypes import ExtensionDtype -from pandas.core.dtypes.generic import ABCDataFrame, ABCIndexClass, ABCSeries +from pandas.core.dtypes.generic import ABCDataFrame, ABCIndex, ABCSeries from pandas.core.dtypes.missing import isna from pandas.core import ops @@ -1361,7 +1361,7 @@ def convert_values(param): ovalues = [param] * len(self) return ovalues - if isinstance(other, (ABCSeries, ABCIndexClass, ABCDataFrame)): + if isinstance(other, (ABCSeries, ABCIndex, ABCDataFrame)): # rely on pandas to unbox and dispatch to us return NotImplemented diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 3995e7b251184b..0a2ef2fb29b960 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -38,7 +38,7 @@ needs_i8_conversion, ) from pandas.core.dtypes.dtypes import CategoricalDtype -from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries +from pandas.core.dtypes.generic import ABCIndex, ABCSeries from pandas.core.dtypes.missing import is_valid_nat_for_dtype, isna, notna from pandas.core import ops @@ -321,7 +321,7 @@ def __init__( if is_categorical_dtype(values): if dtype.categories is None: dtype = CategoricalDtype(values.categories, dtype.ordered) - elif not isinstance(values, (ABCIndexClass, ABCSeries)): + elif not isinstance(values, (ABCIndex, ABCSeries)): # sanitize_array coerces np.nan to a string under certain versions # of numpy values = maybe_infer_to_datetimelike(values, convert_dates=True) @@ -2514,7 +2514,7 @@ def _get_codes_for_values(values, categories) -> np.ndarray: values = ensure_object(values) categories = ensure_object(categories) - if isinstance(categories, ABCIndexClass): + if isinstance(categories, ABCIndex): return coerce_indexer_dtype(categories.get_indexer_for(values), categories) # Only hit here when we've already coerced to object dtypee. diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index f073fc2d704575..8c94a1a080dca8 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -44,7 +44,7 @@ pandas_dtype, ) from pandas.core.dtypes.dtypes import DatetimeTZDtype -from pandas.core.dtypes.generic import ABCIndexClass, ABCPandasArray, ABCSeries +from pandas.core.dtypes.generic import ABCIndex, ABCPandasArray, ABCSeries from pandas.core.dtypes.missing import isna from pandas.core.algorithms import checked_add_with_arr @@ -216,7 +216,7 @@ class DatetimeArray(dtl.TimelikeOps, dtl.DatelikeOps): _freq = None def __init__(self, values, dtype=DT64NS_DTYPE, freq=None, copy=False): - if isinstance(values, (ABCSeries, ABCIndexClass)): + if isinstance(values, (ABCSeries, ABCIndex)): values = values._values inferred_freq = getattr(values, "_freq", None) @@ -1947,7 +1947,7 @@ def sequence_to_dt64ns( # if dtype has an embedded tz, capture it tz = validate_tz_from_dtype(dtype, tz) - if isinstance(data, ABCIndexClass): + if isinstance(data, ABCIndex): if data.nlevels > 1: # Without this check, data._data below is None raise TypeError("Cannot create a DatetimeArray from a MultiIndex.") diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 7b0e4ce5b0748a..257baf20ce9110 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -40,7 +40,7 @@ ) from pandas.core.dtypes.dtypes import PeriodDtype from pandas.core.dtypes.generic import ( - ABCIndexClass, + ABCIndex, ABCPeriodIndex, ABCSeries, ABCTimedeltaArray, @@ -964,14 +964,14 @@ def dt64arr_to_periodarr(data, freq, tz=None): raise ValueError(f"Wrong dtype: {data.dtype}") if freq is None: - if isinstance(data, ABCIndexClass): + if isinstance(data, ABCIndex): data, freq = data._values, data.freq elif isinstance(data, ABCSeries): data, freq = data._values, data.dt.freq freq = Period._maybe_convert_freq(freq) - if isinstance(data, (ABCIndexClass, ABCSeries)): + if isinstance(data, (ABCIndex, ABCSeries)): data = data._values base = freq._period_dtype_code diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 76c9d013575f00..8268ebb48a0176 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 +from pandas.core.dtypes.generic import ABCIndex, ABCSeries from pandas.core.dtypes.missing import isna, na_value_for_dtype, notna import pandas.core.algorithms as algos @@ -746,7 +746,7 @@ def value_counts(self, dropna=True): keys = np.insert(keys, 0, self.fill_value) counts = np.insert(counts, 0, fcounts) - if not isinstance(keys, ABCIndexClass): + if not isinstance(keys, ABCIndex): keys = Index(keys) return Series(counts, index=keys) diff --git a/pandas/core/base.py b/pandas/core/base.py index f333ee0f71e46d..54dec90c08aa24 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -32,7 +32,7 @@ is_object_dtype, is_scalar, ) -from pandas.core.dtypes.generic import ABCDataFrame, ABCIndexClass, ABCSeries +from pandas.core.dtypes.generic import ABCDataFrame, ABCIndex, ABCSeries from pandas.core.dtypes.missing import isna, remove_na_arraylike from pandas.core import algorithms @@ -199,7 +199,7 @@ def _selection_name(self): @property def _selection_list(self): if not isinstance( - self._selection, (list, tuple, ABCSeries, ABCIndexClass, np.ndarray) + self._selection, (list, tuple, ABCSeries, ABCIndex, np.ndarray) ): return [self._selection] return self._selection @@ -254,7 +254,7 @@ def __getitem__(self, key): if self._selection is not None: raise IndexError(f"Column(s) {self._selection} already selected") - if isinstance(key, (list, tuple, ABCSeries, ABCIndexClass, np.ndarray)): + if isinstance(key, (list, tuple, ABCSeries, ABCIndex, np.ndarray)): # pandas\core\base.py:217: error: "SelectionMixin" has no attribute # "obj" [attr-defined] if len( diff --git a/pandas/core/common.py b/pandas/core/common.py index cdcbc430550520..622d903b03579a 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -24,7 +24,7 @@ is_extension_array_dtype, is_integer, ) -from pandas.core.dtypes.generic import ABCExtensionArray, ABCIndexClass, ABCSeries +from pandas.core.dtypes.generic import ABCExtensionArray, ABCIndex, ABCSeries from pandas.core.dtypes.inference import iterable_not_string from pandas.core.dtypes.missing import isna, isnull, notnull # noqa @@ -100,7 +100,7 @@ def is_bool_indexer(key: Any) -> bool: check_array_indexer : Check that `key` is a valid array to index, and convert to an ndarray. """ - if isinstance(key, (ABCSeries, np.ndarray, ABCIndexClass)) or ( + if isinstance(key, (ABCSeries, np.ndarray, ABCIndex)) or ( is_array_like(key) and is_extension_array_dtype(key.dtype) ): if key.dtype == np.object_: @@ -199,7 +199,7 @@ def asarray_tuplesafe(values, dtype=None): if not (isinstance(values, (list, tuple)) or hasattr(values, "__array__")): values = list(values) - elif isinstance(values, ABCIndexClass): + elif isinstance(values, ABCIndex): return values._values if isinstance(values, list) and dtype in [np.object_, object]: @@ -466,9 +466,7 @@ def convert_to_list_like( Convert list-like or scalar input to list-like. List, numpy and pandas array-like inputs are returned unmodified whereas others are converted to list. """ - if isinstance( - values, (list, np.ndarray, ABCIndexClass, ABCSeries, ABCExtensionArray) - ): + if isinstance(values, (list, np.ndarray, ABCIndex, ABCSeries, ABCExtensionArray)): # np.ndarray resolving as Any gives a false positive return values # type: ignore[return-value] elif isinstance(values, abc.Iterable) and not isinstance(values, str): diff --git a/pandas/core/construction.py b/pandas/core/construction.py index 66ebdc2763617a..a8ca457cdf2a78 100644 --- a/pandas/core/construction.py +++ b/pandas/core/construction.py @@ -41,7 +41,7 @@ ) from pandas.core.dtypes.generic import ( ABCExtensionArray, - ABCIndexClass, + ABCIndex, ABCPandasArray, ABCSeries, ) @@ -281,9 +281,7 @@ def array( msg = f"Cannot pass scalar '{data}' to 'pandas.array'." raise ValueError(msg) - if dtype is None and isinstance( - data, (ABCSeries, ABCIndexClass, ABCExtensionArray) - ): + if dtype is None and isinstance(data, (ABCSeries, ABCIndex, ABCExtensionArray)): dtype = data.dtype data = extract_array(data, extract_numpy=True) @@ -392,7 +390,7 @@ def extract_array(obj: object, extract_numpy: bool = False) -> Union[Any, ArrayL >>> extract_array(pd.Series([1, 2, 3]), extract_numpy=True) array([1, 2, 3]) """ - if isinstance(obj, (ABCIndexClass, ABCSeries)): + if isinstance(obj, (ABCIndex, ABCSeries)): obj = obj.array if extract_numpy and isinstance(obj, ABCPandasArray): diff --git a/pandas/core/dtypes/base.py b/pandas/core/dtypes/base.py index c2be81cd46b3bc..6adb4984d156ef 100644 --- a/pandas/core/dtypes/base.py +++ b/pandas/core/dtypes/base.py @@ -9,7 +9,7 @@ from pandas._typing import DtypeObj from pandas.errors import AbstractMethodError -from pandas.core.dtypes.generic import ABCDataFrame, ABCIndexClass, ABCSeries +from pandas.core.dtypes.generic import ABCDataFrame, ABCIndex, ABCSeries if TYPE_CHECKING: from pandas.core.arrays import ExtensionArray @@ -277,7 +277,7 @@ def is_dtype(cls, dtype: object) -> bool: """ dtype = getattr(dtype, "dtype", dtype) - if isinstance(dtype, (ABCSeries, ABCIndexClass, ABCDataFrame, np.dtype)): + if isinstance(dtype, (ABCSeries, ABCIndex, ABCDataFrame, np.dtype)): # https://github.com/pandas-dev/pandas/issues/22960 # avoid passing data to `construct_from_string`. This could # cause a FutureWarning from numpy about failing elementwise diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index b4f6d587c66427..e9aa7cc7f94445 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -19,7 +19,7 @@ IntervalDtype, PeriodDtype, ) -from pandas.core.dtypes.generic import ABCCategorical, ABCIndexClass +from pandas.core.dtypes.generic import ABCCategorical, ABCIndex from pandas.core.dtypes.inference import ( # noqa:F401 is_array_like, is_bool, @@ -1389,7 +1389,7 @@ def is_bool_dtype(arr_or_dtype) -> bool: arr_or_dtype = arr_or_dtype.categories # now we use the special definition for Index - if isinstance(arr_or_dtype, ABCIndexClass): + if isinstance(arr_or_dtype, ABCIndex): # TODO(jreback) # we don't have a boolean Index class diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 3c5421ae433b6e..429cbda208391e 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -25,7 +25,7 @@ from pandas._typing import DtypeObj, Ordered from pandas.core.dtypes.base import ExtensionDtype, register_extension_dtype -from pandas.core.dtypes.generic import ABCCategoricalIndex, ABCIndexClass +from pandas.core.dtypes.generic import ABCCategoricalIndex, ABCIndex from pandas.core.dtypes.inference import is_bool, is_list_like if TYPE_CHECKING: @@ -499,7 +499,7 @@ def validate_categories(categories, fastpath: bool = False): raise TypeError( f"Parameter 'categories' must be list-like, was {repr(categories)}" ) - elif not isinstance(categories, ABCIndexClass): + elif not isinstance(categories, ABCIndex): categories = Index(categories, tupleize_cols=False) if not fastpath: diff --git a/pandas/core/dtypes/generic.py b/pandas/core/dtypes/generic.py index dfbbaa9c1784ae..be78ee7e08421b 100644 --- a/pandas/core/dtypes/generic.py +++ b/pandas/core/dtypes/generic.py @@ -9,6 +9,7 @@ DataFrame, DatetimeIndex, Float64Index, + Index, Int64Index, IntervalIndex, MultiIndex, @@ -76,24 +77,28 @@ def _check(cls, inst) -> bool: "Type[IntervalIndex]", create_pandas_abc_type("ABCIntervalIndex", "_typ", ("intervalindex",)), ) -ABCIndexClass = create_pandas_abc_type( - "ABCIndexClass", - "_typ", - { - "index", - "int64index", - "rangeindex", - "float64index", - "uint64index", - "multiindex", - "datetimeindex", - "timedeltaindex", - "periodindex", - "categoricalindex", - "intervalindex", - }, +ABCIndex = cast( + "Type[Index]", + create_pandas_abc_type( + "ABCIndex", + "_typ", + { + "index", + "int64index", + "rangeindex", + "float64index", + "uint64index", + "multiindex", + "datetimeindex", + "timedeltaindex", + "periodindex", + "categoricalindex", + "intervalindex", + }, + ), ) + ABCNDFrame = cast( "Type[NDFrame]", create_pandas_abc_type("ABCNDFrame", "_typ", ("series", "dataframe")), diff --git a/pandas/core/dtypes/missing.py b/pandas/core/dtypes/missing.py index 0b4aab0ac9d883..e80e6f370f46e0 100644 --- a/pandas/core/dtypes/missing.py +++ b/pandas/core/dtypes/missing.py @@ -34,7 +34,7 @@ from pandas.core.dtypes.generic import ( ABCDataFrame, ABCExtensionArray, - ABCIndexClass, + ABCIndex, ABCMultiIndex, ABCSeries, ) @@ -156,7 +156,7 @@ def _isna(obj, inf_as_na: bool = False): raise NotImplementedError("isna is not defined for MultiIndex") elif isinstance(obj, type): return False - elif isinstance(obj, (ABCSeries, np.ndarray, ABCIndexClass, ABCExtensionArray)): + elif isinstance(obj, (ABCSeries, np.ndarray, ABCIndex, ABCExtensionArray)): return _isna_ndarraylike(obj, inf_as_na=inf_as_na) elif isinstance(obj, ABCDataFrame): return obj.isna() diff --git a/pandas/core/indexers.py b/pandas/core/indexers.py index da4654bbf2c10d..a221f77f261709 100644 --- a/pandas/core/indexers.py +++ b/pandas/core/indexers.py @@ -15,7 +15,7 @@ is_integer_dtype, is_list_like, ) -from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries +from pandas.core.dtypes.generic import ABCIndex, ABCSeries # ----------------------------------------------------------- # Indexer Identification @@ -297,7 +297,7 @@ def length_of_indexer(indexer, target=None) -> int: start, stop = stop + 1, start + 1 step = -step return (stop - start + step - 1) // step - elif isinstance(indexer, (ABCSeries, ABCIndexClass, np.ndarray, list)): + elif isinstance(indexer, (ABCSeries, ABCIndex, np.ndarray, list)): if isinstance(indexer, list): indexer = np.array(indexer) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index fe07823a807836..ac0564e1f4f790 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -52,12 +52,7 @@ pandas_dtype, ) from pandas.core.dtypes.dtypes import ExtensionDtype -from pandas.core.dtypes.generic import ( - ABCDataFrame, - ABCIndexClass, - ABCPandasArray, - ABCSeries, -) +from pandas.core.dtypes.generic import ABCDataFrame, ABCIndex, ABCPandasArray, ABCSeries from pandas.core.dtypes.missing import is_valid_nat_for_dtype, isna, isna_compat import pandas.core.algorithms as algos @@ -1082,7 +1077,7 @@ def putmask( List[Block] """ mask = _extract_bool_array(mask) - assert not isinstance(new, (ABCIndexClass, ABCSeries, ABCDataFrame)) + assert not isinstance(new, (ABCIndex, ABCSeries, ABCDataFrame)) new_values = self.values # delay copy if possible. # if we are passed a scalar None, convert it here @@ -1435,7 +1430,7 @@ def where( import pandas.core.computation.expressions as expressions cond = _extract_bool_array(cond) - assert not isinstance(other, (ABCIndexClass, ABCSeries, ABCDataFrame)) + assert not isinstance(other, (ABCIndex, ABCSeries, ABCDataFrame)) assert errors in ["raise", "ignore"] transpose = self.ndim == 2 @@ -1967,7 +1962,7 @@ def where( ) -> List["Block"]: cond = _extract_bool_array(cond) - assert not isinstance(other, (ABCIndexClass, ABCSeries, ABCDataFrame)) + assert not isinstance(other, (ABCIndex, ABCSeries, ABCDataFrame)) if isinstance(other, np.ndarray) and other.ndim == 2: # TODO(EA2D): unnecessary with 2D EAs diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index bc8e75ceef87b5..cb0f1d962e984a 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -32,7 +32,7 @@ from pandas.core.dtypes.generic import ( ABCDataFrame, ABCDatetimeIndex, - ABCIndexClass, + ABCIndex, ABCSeries, ABCTimedeltaIndex, ) @@ -279,9 +279,7 @@ def init_dict(data: Dict, index, columns, dtype: Optional[DtypeObj] = None): arrays = [com.maybe_iterable_to_list(data[k]) for k in keys] # GH#24096 need copy to be deep for datetime64tz case # TODO: See if we can avoid these copies - arrays = [ - arr if not isinstance(arr, ABCIndexClass) else arr._data for arr in arrays - ] + arrays = [arr if not isinstance(arr, ABCIndex) else arr._data for arr in arrays] arrays = [ arr if not is_datetime64tz_dtype(arr) else arr.copy() for arr in arrays ] diff --git a/pandas/core/ops/array_ops.py b/pandas/core/ops/array_ops.py index 41d539564d91e6..22f674cc6a894a 100644 --- a/pandas/core/ops/array_ops.py +++ b/pandas/core/ops/array_ops.py @@ -27,7 +27,7 @@ is_object_dtype, is_scalar, ) -from pandas.core.dtypes.generic import ABCExtensionArray, ABCIndexClass, ABCSeries +from pandas.core.dtypes.generic import ABCExtensionArray, ABCIndex, ABCSeries from pandas.core.dtypes.missing import isna, notna from pandas.core.construction import ensure_wrapped_if_datetimelike @@ -41,11 +41,11 @@ def comp_method_OBJECT_ARRAY(op, x, y): if isinstance(y, list): y = construct_1d_object_array_from_listlike(y) - if isinstance(y, (np.ndarray, ABCSeries, ABCIndexClass)): + if isinstance(y, (np.ndarray, ABCSeries, ABCIndex)): if not is_object_dtype(y.dtype): y = y.astype(np.object_) - if isinstance(y, (ABCSeries, ABCIndexClass)): + if isinstance(y, (ABCSeries, ABCIndex)): y = y._values if x.shape != y.shape: diff --git a/pandas/core/ops/common.py b/pandas/core/ops/common.py index 58ad3237c8288a..25a38b3a373ae8 100644 --- a/pandas/core/ops/common.py +++ b/pandas/core/ops/common.py @@ -7,7 +7,7 @@ from pandas._libs.lib import item_from_zerodim from pandas._typing import F -from pandas.core.dtypes.generic import ABCDataFrame, ABCIndexClass, ABCSeries +from pandas.core.dtypes.generic import ABCDataFrame, ABCIndex, ABCSeries def unpack_zerodim_and_defer(name: str) -> Callable[[F], F]: @@ -50,11 +50,11 @@ def _unpack_zerodim_and_defer(method, name: str): @wraps(method) def new_method(self, other): - if is_cmp and isinstance(self, ABCIndexClass) and isinstance(other, ABCSeries): + if is_cmp and isinstance(self, ABCIndex) and isinstance(other, ABCSeries): # For comparison ops, Index does *not* defer to Series pass else: - for cls in [ABCDataFrame, ABCSeries, ABCIndexClass]: + for cls in [ABCDataFrame, ABCSeries, ABCIndex]: if isinstance(self, cls): break if isinstance(other, cls): @@ -82,7 +82,7 @@ def get_op_result_name(left, right): name : object Usually a string """ - if isinstance(right, (ABCSeries, ABCIndexClass)): + if isinstance(right, (ABCSeries, ABCIndex)): name = _maybe_match_name(left, right) else: name = left.name diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index 2713b76189157b..339ad2653fcfb0 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -16,12 +16,7 @@ is_integer, is_list_like, ) -from pandas.core.dtypes.generic import ( - ABCDataFrame, - ABCIndexClass, - ABCMultiIndex, - ABCSeries, -) +from pandas.core.dtypes.generic import ABCDataFrame, ABCIndex, ABCMultiIndex, ABCSeries from pandas.core.dtypes.missing import isna from pandas.core.base import NoNewAttributesMixin @@ -260,7 +255,7 @@ def _wrap_result( # infer from ndim if expand is not specified expand = result.ndim != 1 - elif expand is True and not isinstance(self._orig, ABCIndexClass): + elif expand is True and not isinstance(self._orig, ABCIndex): # required when expand=True is explicitly specified # not needed when inferred @@ -293,7 +288,7 @@ def cons_row(x): # Wait until we are sure result is a Series or Index before # checking attributes (GH 12180) - if isinstance(self._orig, ABCIndexClass): + if isinstance(self._orig, ABCIndex): # if result is a boolean np.array, return the np.array # instead of wrapping it into a boolean Index (GH 8875) if is_bool_dtype(result): @@ -351,14 +346,14 @@ def _get_series_list(self, others): from pandas import DataFrame, Series # self._orig is either Series or Index - idx = self._orig if isinstance(self._orig, ABCIndexClass) else self._orig.index + idx = self._orig if isinstance(self._orig, ABCIndex) else self._orig.index # Generally speaking, all objects without an index inherit the index # `idx` of the calling Series/Index - i.e. must have matching length. # Objects with an index (i.e. Series/Index/DataFrame) keep their own. if isinstance(others, ABCSeries): return [others] - elif isinstance(others, ABCIndexClass): + elif isinstance(others, ABCIndex): return [Series(others._values, index=idx)] elif isinstance(others, ABCDataFrame): return [others[x] for x in others] @@ -371,7 +366,7 @@ def _get_series_list(self, others): # in case of list-like `others`, all elements must be # either Series/Index/np.ndarray (1-dim)... if all( - isinstance(x, (ABCSeries, ABCIndexClass)) + isinstance(x, (ABCSeries, ABCIndex)) or (isinstance(x, np.ndarray) and x.ndim == 1) for x in others ): @@ -532,7 +527,7 @@ def cat(self, others=None, sep=None, na_rep=None, join="left"): if sep is None: sep = "" - if isinstance(self._orig, ABCIndexClass): + if isinstance(self._orig, ABCIndex): data = Series(self._orig, index=self._orig) else: # Series data = self._orig @@ -593,7 +588,7 @@ def cat(self, others=None, sep=None, na_rep=None, join="left"): # no NaNs - can just concatenate result = cat_safe(all_cols, sep) - if isinstance(self._orig, ABCIndexClass): + if isinstance(self._orig, ABCIndex): # add dtype for case that result is all-NA result = Index(result, dtype=object, name=self._orig.name) else: # Series @@ -3012,7 +3007,7 @@ def _str_extract_noexpand(arr, pat, flags=0): # not dispatching, so we have to reconstruct here. result = array(result, dtype=result_dtype) else: - if isinstance(arr, ABCIndexClass): + if isinstance(arr, ABCIndex): raise ValueError("only one regex group is supported with Index") name = None names = dict(zip(regex.groupindex.values(), regex.groupindex.keys())) @@ -3076,7 +3071,7 @@ def str_extractall(arr, pat, flags=0): if regex.groups == 0: raise ValueError("pattern contains no capture groups") - if isinstance(arr, ABCIndexClass): + if isinstance(arr, ABCIndex): arr = arr.to_series().reset_index(drop=True) names = dict(zip(regex.groupindex.values(), regex.groupindex.keys())) diff --git a/pandas/core/tools/numeric.py b/pandas/core/tools/numeric.py index dd7373927ed9b6..08cdfde7df58d1 100644 --- a/pandas/core/tools/numeric.py +++ b/pandas/core/tools/numeric.py @@ -12,7 +12,7 @@ is_scalar, needs_i8_conversion, ) -from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries +from pandas.core.dtypes.generic import ABCIndex, ABCSeries import pandas as pd @@ -122,7 +122,7 @@ def to_numeric(arg, errors="raise", downcast=None): if isinstance(arg, ABCSeries): is_series = True values = arg.values - elif isinstance(arg, ABCIndexClass): + elif isinstance(arg, ABCIndex): is_index = True if needs_i8_conversion(arg.dtype): values = arg.asi8 diff --git a/pandas/core/tools/timedeltas.py b/pandas/core/tools/timedeltas.py index 6a9fd7a542a442..5a69f5e4b012fc 100644 --- a/pandas/core/tools/timedeltas.py +++ b/pandas/core/tools/timedeltas.py @@ -8,7 +8,7 @@ from pandas._libs.tslibs.timedeltas import Timedelta, parse_timedelta_unit from pandas.core.dtypes.common import is_list_like -from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries +from pandas.core.dtypes.generic import ABCIndex, ABCSeries from pandas.core.arrays.timedeltas import sequence_to_td64ns @@ -113,7 +113,7 @@ def to_timedelta(arg, unit=None, errors="raise"): elif isinstance(arg, ABCSeries): values = _convert_listlike(arg._values, unit=unit, errors=errors) return arg._constructor(values, index=arg.index, name=arg.name) - elif isinstance(arg, ABCIndexClass): + elif isinstance(arg, ABCIndex): return _convert_listlike(arg, unit=unit, errors=errors, name=arg.name) elif isinstance(arg, np.ndarray) and arg.ndim == 0: # extract array scalar and process below diff --git a/pandas/core/tools/times.py b/pandas/core/tools/times.py index 643c1165180b4c..9b86a7325fa6de 100644 --- a/pandas/core/tools/times.py +++ b/pandas/core/tools/times.py @@ -5,7 +5,7 @@ from pandas._libs.lib import is_list_like -from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries +from pandas.core.dtypes.generic import ABCIndex, ABCSeries from pandas.core.dtypes.missing import notna @@ -103,7 +103,7 @@ def _convert_listlike(arg, format): elif isinstance(arg, ABCSeries): values = _convert_listlike(arg._values, format) return arg._constructor(values, index=arg.index, name=arg.name) - elif isinstance(arg, ABCIndexClass): + elif isinstance(arg, ABCIndex): return _convert_listlike(arg, format) elif is_list_like(arg): return _convert_listlike(arg, format) diff --git a/pandas/core/util/hashing.py b/pandas/core/util/hashing.py index df082c7285ae84..5af3f8f4e0a7ff 100644 --- a/pandas/core/util/hashing.py +++ b/pandas/core/util/hashing.py @@ -13,12 +13,7 @@ is_extension_array_dtype, is_list_like, ) -from pandas.core.dtypes.generic import ( - ABCDataFrame, - ABCIndexClass, - ABCMultiIndex, - ABCSeries, -) +from pandas.core.dtypes.generic import ABCDataFrame, ABCIndex, ABCMultiIndex, ABCSeries # 16 byte long hashing key _default_hash_key = "0123456789123456" @@ -86,7 +81,7 @@ def hash_pandas_object( if isinstance(obj, ABCMultiIndex): return Series(hash_tuples(obj, encoding, hash_key), dtype="uint64", copy=False) - elif isinstance(obj, ABCIndexClass): + elif isinstance(obj, ABCIndex): h = hash_array(obj._values, encoding, hash_key, categorize).astype( "uint64", copy=False ) diff --git a/pandas/io/formats/csvs.py b/pandas/io/formats/csvs.py index 6d14d6172aa6c9..5ad06bdcd83838 100644 --- a/pandas/io/formats/csvs.py +++ b/pandas/io/formats/csvs.py @@ -20,7 +20,7 @@ from pandas.core.dtypes.generic import ( ABCDatetimeIndex, - ABCIndexClass, + ABCIndex, ABCMultiIndex, ABCPeriodIndex, ) @@ -101,7 +101,7 @@ def _initialize_index_label(self, index_label: Optional[IndexLabel]) -> IndexLab if index_label is not False: if index_label is None: return self._get_index_label_from_obj() - elif not isinstance(index_label, (list, tuple, np.ndarray, ABCIndexClass)): + elif not isinstance(index_label, (list, tuple, np.ndarray, ABCIndex)): # given a string for a DF with Index return [index_label] return index_label @@ -137,7 +137,7 @@ def _initialize_columns(self, cols: Optional[Sequence[Label]]) -> Sequence[Label raise TypeError(msg) if cols is not None: - if isinstance(cols, ABCIndexClass): + if isinstance(cols, ABCIndex): cols = cols._format_native_types(**self._number_format) else: cols = list(cols) @@ -146,7 +146,7 @@ def _initialize_columns(self, cols: Optional[Sequence[Label]]) -> Sequence[Label # update columns to include possible multiplicity of dupes # and make sure cols is just a list of labels new_cols = self.obj.columns - if isinstance(new_cols, ABCIndexClass): + if isinstance(new_cols, ABCIndex): return new_cols._format_native_types(**self._number_format) else: return list(new_cols) @@ -188,7 +188,7 @@ def nlevels(self) -> int: @property def _has_aliases(self) -> bool: - return isinstance(self.header, (tuple, list, np.ndarray, ABCIndexClass)) + return isinstance(self.header, (tuple, list, np.ndarray, ABCIndex)) @property def _need_to_save_header(self) -> bool: diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 1a22e5629ebe82..3cf72edcc505ef 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -22,7 +22,7 @@ ) from pandas.core.dtypes.generic import ( ABCDataFrame, - ABCIndexClass, + ABCIndex, ABCMultiIndex, ABCPeriodIndex, ABCSeries, @@ -192,7 +192,7 @@ def __init__( for kw, err in zip(["xerr", "yerr"], [xerr, yerr]) } - if not isinstance(secondary_y, (bool, tuple, list, np.ndarray, ABCIndexClass)): + if not isinstance(secondary_y, (bool, tuple, list, np.ndarray, ABCIndex)): secondary_y = [secondary_y] self.secondary_y = secondary_y @@ -678,7 +678,7 @@ def _plot(cls, ax: "Axes", x, y, style=None, is_errorbar: bool = False, **kwds): y = np.ma.array(y) y = np.ma.masked_where(mask, y) - if isinstance(x, ABCIndexClass): + if isinstance(x, ABCIndex): x = x._mpl_repr() if is_errorbar: @@ -748,7 +748,7 @@ def on_right(self, i): if isinstance(self.secondary_y, bool): return self.secondary_y - if isinstance(self.secondary_y, (tuple, list, np.ndarray, ABCIndexClass)): + if isinstance(self.secondary_y, (tuple, list, np.ndarray, ABCIndex)): return self.data.columns[i] in self.secondary_y def _apply_style_colors(self, colors, kwds, col_num, label): diff --git a/pandas/plotting/_matplotlib/hist.py b/pandas/plotting/_matplotlib/hist.py index 6d22d2ffe4a519..bff434d3c2d9d4 100644 --- a/pandas/plotting/_matplotlib/hist.py +++ b/pandas/plotting/_matplotlib/hist.py @@ -3,7 +3,7 @@ import numpy as np from pandas.core.dtypes.common import is_integer, is_list_like -from pandas.core.dtypes.generic import ABCDataFrame, ABCIndexClass +from pandas.core.dtypes.generic import ABCDataFrame, ABCIndex from pandas.core.dtypes.missing import isna, remove_na_arraylike from pandas.io.formats.printing import pprint_thing @@ -414,7 +414,7 @@ def hist_frame( return axes if column is not None: - if not isinstance(column, (list, np.ndarray, ABCIndexClass)): + if not isinstance(column, (list, np.ndarray, ABCIndex)): column = [column] data = data[column] # GH32590 diff --git a/pandas/plotting/_matplotlib/tools.py b/pandas/plotting/_matplotlib/tools.py index 955a057000c41e..da9d45602d75c6 100644 --- a/pandas/plotting/_matplotlib/tools.py +++ b/pandas/plotting/_matplotlib/tools.py @@ -10,7 +10,7 @@ from pandas._typing import FrameOrSeriesUnion from pandas.core.dtypes.common import is_list_like -from pandas.core.dtypes.generic import ABCDataFrame, ABCIndexClass, ABCSeries +from pandas.core.dtypes.generic import ABCDataFrame, ABCIndex, ABCSeries from pandas.plotting._matplotlib import compat @@ -406,7 +406,7 @@ def handle_shared_axes( def flatten_axes(axes: Union["Axes", Sequence["Axes"]]) -> np.ndarray: if not is_list_like(axes): return np.array([axes]) - elif isinstance(axes, (np.ndarray, ABCIndexClass)): + elif isinstance(axes, (np.ndarray, ABCIndex)): return np.asarray(axes).ravel() return np.array(axes) diff --git a/pandas/tests/arrays/integer/test_dtypes.py b/pandas/tests/arrays/integer/test_dtypes.py index 4d00a22e13c3a3..457117c167749c 100644 --- a/pandas/tests/arrays/integer/test_dtypes.py +++ b/pandas/tests/arrays/integer/test_dtypes.py @@ -1,7 +1,7 @@ import numpy as np import pytest -from pandas.core.dtypes.generic import ABCIndexClass +from pandas.core.dtypes.generic import ABCIndex import pandas as pd import pandas._testing as tm @@ -86,7 +86,7 @@ def test_astype_index(all_data, dropna): dtype = all_data.dtype idx = pd.Index(np.array(other)) - assert isinstance(idx, ABCIndexClass) + assert isinstance(idx, ABCIndex) result = idx.astype(dtype) expected = idx.astype(object).astype(dtype) diff --git a/pandas/tests/dtypes/test_generic.py b/pandas/tests/dtypes/test_generic.py index 847daa1e6b2630..6c38c8ff19c157 100644 --- a/pandas/tests/dtypes/test_generic.py +++ b/pandas/tests/dtypes/test_generic.py @@ -30,8 +30,8 @@ def test_abc_types(self): assert isinstance(self.timedelta_index, gt.ABCTimedeltaIndex) assert isinstance(self.period_index, gt.ABCPeriodIndex) assert isinstance(self.categorical_df.index, gt.ABCCategoricalIndex) - assert isinstance(pd.Index(["a", "b", "c"]), gt.ABCIndexClass) - assert isinstance(pd.Int64Index([1, 2, 3]), gt.ABCIndexClass) + assert isinstance(pd.Index(["a", "b", "c"]), gt.ABCIndex) + assert isinstance(pd.Int64Index([1, 2, 3]), gt.ABCIndex) assert isinstance(pd.Series([1, 2, 3]), gt.ABCSeries) assert isinstance(self.df, gt.ABCDataFrame) assert isinstance(self.sparse_array, gt.ABCExtensionArray)