diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index da4a73ce1c80f..de28342c0d526 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -75,8 +75,8 @@ def assert_almost_equal( right : object check_dtype : bool or {'equiv'}, default 'equiv' Check dtype if both a and b are the same type. If 'equiv' is passed in, - then `RangeIndex` and `Int64Index` are also considered equivalent - when doing type checking. + then `RangeIndex` and `NumericIndex` with int64 dtype are also considered + equivalent when doing type checking. rtol : float, default 1e-5 Relative tolerance. @@ -197,7 +197,7 @@ def assert_index_equal( exact : bool or {'equiv'}, default 'equiv' Whether to check the Index class, dtype and inferred_type are identical. If 'equiv', then RangeIndex can be substituted for - Int64Index as well. + NumericIndex with an int64 dtype as well. check_names : bool, default True Whether to check the names attribute. check_exact : bool, default True @@ -511,7 +511,7 @@ def assert_interval_array_equal( exact : bool or {'equiv'}, default 'equiv' Whether to check the Index class, dtype and inferred_type are identical. If 'equiv', then RangeIndex can be substituted for - Int64Index as well. + NumericIndex with an int64 dtype as well. obj : str, default 'IntervalArray' Specify object name being compared, internally used to show appropriate assertion message diff --git a/pandas/compat/pickle_compat.py b/pandas/compat/pickle_compat.py index b3eb5b1bfdcde..2fbd3a6cdb046 100644 --- a/pandas/compat/pickle_compat.py +++ b/pandas/compat/pickle_compat.py @@ -94,8 +94,8 @@ def load_reduce(self): ("pandas.indexes.base", "_new_Index"): ("pandas.core.indexes.base", "_new_Index"), ("pandas.indexes.base", "Index"): ("pandas.core.indexes.base", "Index"), ("pandas.indexes.numeric", "Int64Index"): ( - "pandas.core.indexes.numeric", - "Int64Index", + "pandas.core.indexes.base", + "Index", # updated in 50775 ), ("pandas.indexes.range", "RangeIndex"): ("pandas.core.indexes.range", "RangeIndex"), ("pandas.indexes.multi", "MultiIndex"): ("pandas.core.indexes.multi", "MultiIndex"), @@ -119,7 +119,7 @@ def load_reduce(self): "TimedeltaIndex", ), ("pandas.indexes.numeric", "Float64Index"): ( - "pandas.core.indexes.numeric", + "pandas.core.indexes.base", "Index", # updated in 50775 ), # 50775, remove Int64Index, UInt64Index & Float64Index from codabase diff --git a/pandas/conftest.py b/pandas/conftest.py index 1a410f87c8552..2e9638036eec5 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -520,7 +520,7 @@ def multiindex_year_month_day_dataframe_random_data(): """ tdf = tm.makeTimeDataFrame(100) ymd = tdf.groupby([lambda x: x.year, lambda x: x.month, lambda x: x.day]).sum() - # use Int64Index, to make sure things work + # use int64 Index, to make sure things work ymd.index = ymd.index.set_levels([lev.astype("i8") for lev in ymd.index.levels]) ymd.index.set_names(["year", "month", "day"], inplace=True) return ymd diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index aa9d1c8152019..a7fa77d1ff0ee 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1305,7 +1305,7 @@ def __init__(self, obj: DataFrame, n: int, keep: str, columns: IndexLabel) -> No def compute(self, method: str) -> DataFrame: - from pandas.core.api import Int64Index + from pandas.core.api import NumericIndex n = self.n frame = self.obj @@ -1333,7 +1333,7 @@ def get_indexer(current_indexer, other_indexer): original_index = frame.index cur_frame = frame = frame.reset_index(drop=True) cur_n = n - indexer = Int64Index([]) + indexer = NumericIndex([], dtype=np.int64) for i, column in enumerate(columns): # For each column we apply method to cur_frame[column]. diff --git a/pandas/core/api.py b/pandas/core/api.py index 3d2547fcea230..0dffa681acfc1 100644 --- a/pandas/core/api.py +++ b/pandas/core/api.py @@ -51,16 +51,13 @@ from pandas.core.indexes.api import ( CategoricalIndex, DatetimeIndex, - Float64Index, Index, - Int64Index, IntervalIndex, MultiIndex, NumericIndex, PeriodIndex, RangeIndex, TimedeltaIndex, - UInt64Index, ) from pandas.core.indexes.datetimes import ( bdate_range, @@ -101,14 +98,12 @@ "Flags", "Float32Dtype", "Float64Dtype", - "Float64Index", "Grouper", "Index", "IndexSlice", "Int16Dtype", "Int32Dtype", "Int64Dtype", - "Int64Index", "Int8Dtype", "Interval", "IntervalDtype", @@ -141,7 +136,6 @@ "UInt16Dtype", "UInt32Dtype", "UInt64Dtype", - "UInt64Index", "UInt8Dtype", "unique", "value_counts", diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index 1a2b9728f80a1..50203003a037a 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -726,10 +726,10 @@ def total_seconds(self) -> npt.NDArray[np.float64]: Returns ------- - ndarray, Float64Index or Series + ndarray, Index or Series When the calling object is a TimedeltaArray, the return type is ndarray. When the calling object is a TimedeltaIndex, - the return type is a Float64Index. When the calling object + the return type is an Index with a float64 dtype. When the calling object is a Series, the return type is Series of type `float64` whose index is the same as the original. diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 3b122eaa814e5..9efc07628cccd 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10870,11 +10870,7 @@ def quantile( f"Invalid method: {method}. Method must be in {valid_method}." ) if method == "single": - # error: Argument "qs" to "quantile" of "BlockManager" has incompatible type - # "Index"; expected "Float64Index" - res = data._mgr.quantile( - qs=q, axis=1, interpolation=interpolation # type: ignore[arg-type] - ) + res = data._mgr.quantile(qs=q, axis=1, interpolation=interpolation) elif method == "table": valid_interpolation = {"nearest", "lower", "higher"} if interpolation not in valid_interpolation: diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index e0e5c15f6adfc..ffc886711932b 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -880,7 +880,7 @@ def is_in_axis(key) -> bool: try: items.get_loc(key) except (KeyError, TypeError, InvalidIndexError): - # TypeError shows up here if we pass e.g. Int64Index + # TypeError shows up here if we pass e.g. an Index return False return True diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index c562eaffd241d..08191363bfc93 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -26,12 +26,7 @@ from pandas.core.indexes.datetimes import DatetimeIndex from pandas.core.indexes.interval import IntervalIndex from pandas.core.indexes.multi import MultiIndex -from pandas.core.indexes.numeric import ( - Float64Index, - Int64Index, - NumericIndex, - UInt64Index, -) +from pandas.core.indexes.numeric import NumericIndex from pandas.core.indexes.period import PeriodIndex from pandas.core.indexes.range import RangeIndex from pandas.core.indexes.timedeltas import TimedeltaIndex @@ -52,12 +47,9 @@ "Index", "MultiIndex", "NumericIndex", - "Float64Index", - "Int64Index", "CategoricalIndex", "IntervalIndex", "RangeIndex", - "UInt64Index", "InvalidIndexError", "TimedeltaIndex", "PeriodIndex", diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 4d2e4758817be..fc2c51166a737 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -296,9 +296,6 @@ class Index(IndexOpsMixin, PandasObject): TimedeltaIndex : Index of timedelta64 data. PeriodIndex : Index of Period data. NumericIndex : Index of numpy int/uint/float data. - Int64Index : Index of purely int64 labels (deprecated). - UInt64Index : Index of purely uint64 labels (deprecated). - Float64Index : Index of purely float64 labels (deprecated). Notes ----- @@ -498,7 +495,7 @@ def __new__( klass = cls._dtype_to_subclass(arr.dtype) - # _ensure_array _may_ be unnecessary once Int64Index etc are gone + # _ensure_array _may_ be unnecessary once NumericIndex etc are gone arr = klass._ensure_array(arr, arr.dtype, copy=False) return klass._simple_new(arr, name) @@ -1026,7 +1023,7 @@ def take( taken = values.take( indices, allow_fill=allow_fill, fill_value=self._na_value ) - # _constructor so RangeIndex->Int64Index + # _constructor so RangeIndex-> Index with an int64 dtype return self._constructor._simple_new(taken, name=self.name) @final @@ -1097,7 +1094,7 @@ def repeat(self, repeats, axis=None): nv.validate_repeat((), {"axis": axis}) res_values = self._values.repeat(repeats) - # _constructor so RangeIndex->Int64Index + # _constructor so RangeIndex-> Index with an int64 dtype return self._constructor._simple_new(res_values, name=self.name) # -------------------------------------------------------------------- @@ -6228,7 +6225,7 @@ def _maybe_cast_slice_bound(self, label, side: str_t): """ # We are a plain index here (sub-class override this method if they - # wish to have special treatment for floats/ints, e.g. Float64Index and + # wish to have special treatment for floats/ints, e.g. NumericIndex and # datetimelike Indexes # Special case numeric EA Indexes, since they are not handled by NumericIndex @@ -6442,7 +6439,7 @@ def delete(self: _IndexT, loc) -> _IndexT: else: res_values = values.delete(loc) - # _constructor so RangeIndex->Int64Index + # _constructor so RangeIndex-> Index with an int64 dtype return self._constructor._simple_new(res_values, name=self.name) def insert(self, loc: int, item) -> Index: diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index bdaaeb20b3508..fc40ae4a99be0 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -63,7 +63,7 @@ if TYPE_CHECKING: from pandas.core.api import ( DataFrame, - Float64Index, + NumericIndex, PeriodIndex, ) @@ -284,11 +284,11 @@ def to_period(self, freq=None) -> PeriodIndex: return PeriodIndex._simple_new(arr, name=self.name) @doc(DatetimeArray.to_julian_date) - def to_julian_date(self) -> Float64Index: - from pandas.core.indexes.api import Float64Index + def to_julian_date(self) -> NumericIndex: + from pandas.core.indexes.api import NumericIndex arr = self._data.to_julian_date() - return Float64Index._simple_new(arr, name=self.name) + return NumericIndex._simple_new(arr, name=self.name) @doc(DatetimeArray.isocalendar) def isocalendar(self) -> DataFrame: diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index c6bd7b8aae980..3b0b5d1d55a88 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -520,7 +520,7 @@ def _maybe_convert_i8(self, key): ------- scalar or list-like The original key if no conversion occurred, int if converted scalar, - Int64Index if converted list-like. + Index with an int64 dtype if converted list-like. """ if is_list_like(key): key = ensure_index(key) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index d7fba354ceead..14240f1d19472 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1642,7 +1642,7 @@ def get_level_values(self, level): level_1 int64 dtype: object >>> pd.MultiIndex.from_arrays([[1, None, 2], [3, 4, 5]]).get_level_values(0) - Float64Index([1.0, nan, 2.0], dtype='float64') + NumericIndex([1.0, nan, 2.0], dtype='float64') """ level = self._get_level_number(level) values = self._get_level_values(level) diff --git a/pandas/core/indexes/numeric.py b/pandas/core/indexes/numeric.py index 3ea7b30f7e9f1..fab741ec1ba18 100644 --- a/pandas/core/indexes/numeric.py +++ b/pandas/core/indexes/numeric.py @@ -1,16 +1,10 @@ from __future__ import annotations -from typing import ( - Callable, - Hashable, -) +from typing import Callable import numpy as np -from pandas._libs import ( - index as libindex, - lib, -) +from pandas._libs import index as libindex from pandas._typing import ( Dtype, npt, @@ -26,8 +20,6 @@ is_integer_dtype, is_numeric_dtype, is_scalar, - is_signed_integer_dtype, - is_unsigned_integer_dtype, pandas_dtype, ) from pandas.core.dtypes.generic import ABCSeries @@ -68,9 +60,6 @@ class NumericIndex(Index): See Also -------- Index : The base pandas Index type. - Int64Index : Index of purely int64 labels (deprecated). - UInt64Index : Index of purely uint64 labels (deprecated). - Float64Index : Index of purely float64 labels (deprecated). Notes ----- @@ -146,18 +135,12 @@ def _ensure_array(cls, data, dtype, copy: bool): if not isinstance(data, (ABCSeries, list, tuple)): data = list(data) - orig = data if isinstance(data, (list, tuple)): if len(data): data = sanitize_array(data, index=None) else: data = np.array([], dtype=np.int64) - if dtype is None and data.dtype.kind == "f": - if cls is UInt64Index and (data >= 0).all(): - # https://github.com/numpy/numpy/issues/19146 - data = np.asarray(orig, dtype=np.uint64) - dtype = cls._ensure_dtype(dtype) if copy or not is_dtype_equal(data.dtype, dtype): @@ -199,8 +182,6 @@ def _validate_dtype(cls, dtype: Dtype | None) -> None: @classmethod def _ensure_dtype(cls, dtype: Dtype | None) -> np.dtype | None: """ - Ensure int64 dtype for Int64Index etc. but allow int32 etc. for NumericIndex. - Assumes dtype has already been validated. """ if dtype is None: @@ -243,14 +224,6 @@ def _maybe_cast_slice_bound(self, label, side: str): # ---------------------------------------------------------------- - @doc(Index._shallow_copy) - def _shallow_copy(self, values, name: Hashable = lib.no_default): - if not self._can_hold_na and values.dtype.kind == "f": - name = self._name if name is lib.no_default else name - # Ensure we are not returning an Int64Index with float data: - return Float64Index._simple_new(values, name=name) - return super()._shallow_copy(values=values, name=name) - def _convert_tolerance(self, tolerance, target): tolerance = super()._convert_tolerance(tolerance, target) @@ -308,108 +281,3 @@ def _format_native_types( quoting=quoting, **kwargs, ) - - -_num_index_shared_docs = {} - - -_num_index_shared_docs[ - "class_descr" -] = """ - Immutable sequence used for indexing and alignment. - - .. deprecated:: 1.4.0 - In pandas v2.0 %(klass)s will be removed and :class:`NumericIndex` used instead. - %(klass)s will remain fully functional for the duration of pandas 1.x. - - The basic object storing axis labels for all pandas objects. - %(klass)s is a special case of `Index` with purely %(ltype)s labels. %(extra)s. - - Parameters - ---------- - data : array-like (1-dimensional) - dtype : NumPy dtype (default: %(dtype)s) - copy : bool - Make a copy of input ndarray. - name : object - Name to be stored in the index. - - Attributes - ---------- - None - - Methods - ------- - None - - See Also - -------- - Index : The base pandas Index type. - NumericIndex : Index of numpy int/uint/float data. - - Notes - ----- - An Index instance can **only** contain hashable objects. -""" - - -class IntegerIndex(NumericIndex): - """ - This is an abstract class for Int64Index, UInt64Index. - """ - - _is_backward_compat_public_numeric_index: bool = False - - -class Int64Index(IntegerIndex): - _index_descr_args = { - "klass": "Int64Index", - "ltype": "integer", - "dtype": "int64", - "extra": "", - } - __doc__ = _num_index_shared_docs["class_descr"] % _index_descr_args - - _typ = "int64index" - _default_dtype = np.dtype(np.int64) - _dtype_validation_metadata = (is_signed_integer_dtype, "signed integer") - - @property - def _engine_type(self) -> type[libindex.Int64Engine]: - return libindex.Int64Engine - - -class UInt64Index(IntegerIndex): - _index_descr_args = { - "klass": "UInt64Index", - "ltype": "unsigned integer", - "dtype": "uint64", - "extra": "", - } - __doc__ = _num_index_shared_docs["class_descr"] % _index_descr_args - - _typ = "uint64index" - _default_dtype = np.dtype(np.uint64) - _dtype_validation_metadata = (is_unsigned_integer_dtype, "unsigned integer") - - @property - def _engine_type(self) -> type[libindex.UInt64Engine]: - return libindex.UInt64Engine - - -class Float64Index(NumericIndex): - _index_descr_args = { - "klass": "Float64Index", - "dtype": "float64", - "ltype": "float", - "extra": "", - } - __doc__ = _num_index_shared_docs["class_descr"] % _index_descr_args - - _typ = "float64index" - _default_dtype = np.dtype(np.float64) - _dtype_validation_metadata = (is_float_dtype, "float") - - @property - def _engine_type(self) -> type[libindex.Float64Engine]: - return libindex.Float64Engine diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 877bb2844e8c9..b32f0954a7c30 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -45,7 +45,6 @@ Index, ) from pandas.core.indexes.extension import inherit_names -from pandas.core.indexes.numeric import Int64Index _index_doc_kwargs = dict(ibase._index_doc_kwargs) _index_doc_kwargs.update({"target_klass": "PeriodIndex or list of Periods"}) @@ -183,18 +182,18 @@ def to_timestamp(self, freq=None, how: str = "start") -> DatetimeIndex: @property @doc(PeriodArray.hour.fget) - def hour(self) -> Int64Index: - return Int64Index(self._data.hour, name=self.name) + def hour(self) -> Index: + return Index(self._data.hour, name=self.name) @property @doc(PeriodArray.minute.fget) - def minute(self) -> Int64Index: - return Int64Index(self._data.minute, name=self.name) + def minute(self) -> Index: + return Index(self._data.minute, name=self.name) @property @doc(PeriodArray.second.fget) - def second(self) -> Int64Index: - return Int64Index(self._data.second, name=self.name) + def second(self) -> Index: + return Index(self._data.second, name=self.name) # ------------------------------------------------------------------------ # Index Constructors diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 636e376197ef1..a7b19e3180fff 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -2081,7 +2081,7 @@ def _setitem_with_indexer_missing(self, indexer, value): new_index = index.insert(len(index), indexer) # we have a coerced indexer, e.g. a float - # that matches in an Int64Index, so + # that matches in an int64 Index, so # we will not create a duplicate index, rather # index to that element # e.g. 0.0 -> 0 diff --git a/pandas/core/internals/array_manager.py b/pandas/core/internals/array_manager.py index b8ef925362e7b..82316806d3d47 100644 --- a/pandas/core/internals/array_manager.py +++ b/pandas/core/internals/array_manager.py @@ -4,7 +4,6 @@ from __future__ import annotations from typing import ( - TYPE_CHECKING, Any, Callable, Hashable, @@ -94,10 +93,6 @@ to_native_types, ) -if TYPE_CHECKING: - from pandas.core.api import Float64Index - - T = TypeVar("T", bound="BaseArrayManager") @@ -1013,7 +1008,7 @@ def operate_blockwise(self, other: ArrayManager, array_op) -> ArrayManager: def quantile( self, *, - qs: Float64Index, + qs: Index, # with dtype float64 axis: AxisInt = 0, transposed: bool = False, interpolation: QuantileInterpolation = "linear", diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 4bb4882574228..00ab9d02cee00 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1288,8 +1288,8 @@ def quantile( Parameters ---------- - qs : Float64Index - List of the quantiles to be computed. + qs : Index + The quantiles to be computed in float64. interpolation : str, default 'linear' Type of interpolation. axis : int, default 0