diff --git a/pandas/compat/pickle_compat.py b/pandas/compat/pickle_compat.py index 051aa5c337782..b3eb5b1bfdcde 100644 --- a/pandas/compat/pickle_compat.py +++ b/pandas/compat/pickle_compat.py @@ -120,7 +120,20 @@ def load_reduce(self): ), ("pandas.indexes.numeric", "Float64Index"): ( "pandas.core.indexes.numeric", - "Float64Index", + "Index", # updated in 50775 + ), + # 50775, remove Int64Index, UInt64Index & Float64Index from codabase + ("pandas.core.indexes.numeric", "Int64Index"): ( + "pandas.core.indexes.base", + "Index", + ), + ("pandas.core.indexes.numeric", "UInt64Index"): ( + "pandas.core.indexes.base", + "Index", + ), + ("pandas.core.indexes.numeric", "Float64Index"): ( + "pandas.core.indexes.base", + "Index", ), } diff --git a/pandas/core/dtypes/generic.py b/pandas/core/dtypes/generic.py index 9b30ff60570ce..190bd9d940ca3 100644 --- a/pandas/core/dtypes/generic.py +++ b/pandas/core/dtypes/generic.py @@ -29,11 +29,6 @@ TimedeltaArray, ) from pandas.core.generic import NDFrame - from pandas.core.indexes.api import ( - Float64Index, - Int64Index, - UInt64Index, - ) # define abstract base classes to enable isinstance type checking on our @@ -62,22 +57,10 @@ def _subclasscheck(cls, inst) -> bool: return meta(name, (), dct) -ABCInt64Index = cast( - "Type[Int64Index]", - create_pandas_abc_type("ABCInt64Index", "_typ", ("int64index",)), -) -ABCUInt64Index = cast( - "Type[UInt64Index]", - create_pandas_abc_type("ABCUInt64Index", "_typ", ("uint64index",)), -) ABCRangeIndex = cast( "Type[RangeIndex]", create_pandas_abc_type("ABCRangeIndex", "_typ", ("rangeindex",)), ) -ABCFloat64Index = cast( - "Type[Float64Index]", - create_pandas_abc_type("ABCFloat64Index", "_typ", ("float64index",)), -) ABCMultiIndex = cast( "Type[MultiIndex]", create_pandas_abc_type("ABCMultiIndex", "_typ", ("multiindex",)), @@ -109,10 +92,7 @@ def _subclasscheck(cls, inst) -> bool: "_typ", { "index", - "int64index", "rangeindex", - "float64index", - "uint64index", "numericindex", "multiindex", "datetimeindex", diff --git a/pandas/tests/arithmetic/conftest.py b/pandas/tests/arithmetic/conftest.py index b734344d25174..83b95a1b46075 100644 --- a/pandas/tests/arithmetic/conftest.py +++ b/pandas/tests/arithmetic/conftest.py @@ -4,11 +4,7 @@ import pandas as pd from pandas import RangeIndex import pandas._testing as tm -from pandas.core.api import ( - Float64Index, - Int64Index, - UInt64Index, -) +from pandas.core.api import NumericIndex from pandas.core.computation import expressions as expr @@ -90,9 +86,10 @@ def zero(request): @pytest.fixture( params=[ - Float64Index(np.arange(5, dtype="float64")), - Int64Index(np.arange(5, dtype="int64")), - UInt64Index(np.arange(5, dtype="uint64")), + # TODO: add more dtypes here + NumericIndex(np.arange(5, dtype="float64")), + NumericIndex(np.arange(5, dtype="int64")), + NumericIndex(np.arange(5, dtype="uint64")), RangeIndex(5), ], ids=lambda x: type(x).__name__, diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index fea216c35129b..a38fdb2c2cde8 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -377,7 +377,7 @@ def test_divmod_zero(self, zero, numeric_idx): @pytest.mark.parametrize("op", [operator.truediv, operator.floordiv]) def test_div_negative_zero(self, zero, numeric_idx, op): # Check that -1 / -0.0 returns np.inf, not -np.inf - if isinstance(numeric_idx, UInt64Index): + if numeric_idx.dtype == np.uint64: return idx = numeric_idx - 3 @@ -669,7 +669,7 @@ def test_mul_int_array(self, numeric_idx): result = idx * np.array(5, dtype="int64") tm.assert_index_equal(result, idx * 5) - arr_dtype = "uint64" if isinstance(idx, UInt64Index) else "int64" + arr_dtype = "uint64" if idx.dtype == np.uint64 else "int64" result = idx * np.arange(5, dtype=arr_dtype) tm.assert_index_equal(result, didx) @@ -677,7 +677,7 @@ def test_mul_int_series(self, numeric_idx): idx = numeric_idx didx = idx * idx - arr_dtype = "uint64" if isinstance(idx, UInt64Index) else "int64" + arr_dtype = "uint64" if idx.dtype == np.uint64 else "int64" result = idx * Series(np.arange(5, dtype=arr_dtype)) tm.assert_series_equal(result, Series(didx)) @@ -714,7 +714,7 @@ def test_pow_float(self, op, numeric_idx, box_with_array): # test power calculations both ways, GH#14973 box = box_with_array idx = numeric_idx - expected = Float64Index(op(idx.values, 2.0)) + expected = Index(op(idx.values, 2.0)) idx = tm.box_expected(idx, box) expected = tm.box_expected(expected, box) @@ -1216,7 +1216,7 @@ def test_binops_index(self, op, idx1, idx2): idx1 = idx1._rename("foo") idx2 = idx2._rename("bar") result = op(idx1, idx2) - expected = op(Int64Index(idx1), Int64Index(idx2)) + expected = op(Index(idx1.to_numpy()), Index(idx2.to_numpy())) tm.assert_index_equal(result, expected, exact="equiv") @pytest.mark.parametrize( @@ -1252,7 +1252,7 @@ def test_binops_index_pow(self, idx1, idx2): idx1 = idx1._rename("foo") idx2 = idx2._rename("bar") result = pow(idx1, idx2) - expected = pow(Int64Index(idx1), Int64Index(idx2)) + expected = pow(Index(idx1.to_numpy()), Index(idx2.to_numpy())) tm.assert_index_equal(result, expected, exact="equiv") @pytest.mark.parametrize("idx", [RangeIndex(0, 10, 1), RangeIndex(0, 20, 2)]) @@ -1330,7 +1330,7 @@ def test_numeric_compat2(self): # __pow__ idx = RangeIndex(0, 1000, 2) result = idx**2 - expected = Int64Index(idx._values) ** 2 + expected = Index(idx._values) ** 2 tm.assert_index_equal(Index(result.values), expected, exact=True) @pytest.mark.parametrize( diff --git a/pandas/tests/dtypes/test_generic.py b/pandas/tests/dtypes/test_generic.py index 4f73754d2708f..6459942c99190 100644 --- a/pandas/tests/dtypes/test_generic.py +++ b/pandas/tests/dtypes/test_generic.py @@ -8,11 +8,6 @@ import pandas as pd import pandas._testing as tm -from pandas.core.api import ( - Float64Index, - Int64Index, - UInt64Index, -) class TestABCClasses: @@ -29,9 +24,6 @@ class TestABCClasses: timedelta_array = pd.core.arrays.TimedeltaArray(timedelta_index) abc_pairs = [ - ("ABCInt64Index", Int64Index([1, 2, 3])), - ("ABCUInt64Index", UInt64Index([1, 2, 3])), - ("ABCFloat64Index", Float64Index([1, 2, 3])), ("ABCMultiIndex", multi_index), ("ABCDatetimeIndex", datetime_index), ("ABCRangeIndex", pd.RangeIndex(3)),