Skip to content

DEPR: Remove ABC(Int|Uint|Float)64Index #50775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion pandas/compat/pickle_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
}

Expand Down
20 changes: 0 additions & 20 deletions pandas/core/dtypes/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",)),
Expand Down Expand Up @@ -109,10 +92,7 @@ def _subclasscheck(cls, inst) -> bool:
"_typ",
{
"index",
"int64index",
"rangeindex",
"float64index",
"uint64index",
"numericindex",
"multiindex",
"datetimeindex",
Expand Down
13 changes: 5 additions & 8 deletions pandas/tests/arithmetic/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got some problems with arithmetics with non-64-bit indexes. I'd like to take them in a follow-up.

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__,
Expand Down
14 changes: 7 additions & 7 deletions pandas/tests/arithmetic/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -669,15 +669,15 @@ 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use is_unsigned_integer_dtype here? Ok as follow up

result = idx * np.arange(5, dtype=arr_dtype)
tm.assert_index_equal(result, didx)

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))

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)])
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 0 additions & 8 deletions pandas/tests/dtypes/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@

import pandas as pd
import pandas._testing as tm
from pandas.core.api import (
Float64Index,
Int64Index,
UInt64Index,
)


class TestABCClasses:
Expand All @@ -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)),
Expand Down