Skip to content

Commit 71498fe

Browse files
topper-123pooja-subramaniam
authored andcommitted
DEPR: remove Int/Uint/Float64Index from tests/arithmetic + various (pandas-dev#50889)
DEPR: remove Int/Uint/Float64Index from tests/arithmetic + various places
1 parent 1258e4a commit 71498fe

File tree

7 files changed

+38
-37
lines changed

7 files changed

+38
-37
lines changed

pandas/tests/arithmetic/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def zero(request):
7575
--------
7676
arr = RangeIndex(5)
7777
arr / zeros
78-
Float64Index([nan, inf, inf, inf, inf], dtype='float64')
78+
NumericIndex([nan, inf, inf, inf, inf], dtype='float64')
7979
"""
8080
return request.param
8181

pandas/tests/arithmetic/test_numeric.py

+32-30
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@
2222
)
2323
import pandas._testing as tm
2424
from pandas.core import ops
25-
from pandas.core.api import (
26-
Float64Index,
27-
Int64Index,
28-
UInt64Index,
29-
)
25+
from pandas.core.api import NumericIndex
3026
from pandas.core.computation import expressions as expr
3127
from pandas.tests.arithmetic.common import (
3228
assert_invalid_addsub_type,
@@ -1058,72 +1054,77 @@ def test_series_divmod_zero(self):
10581054

10591055

10601056
class TestUFuncCompat:
1061-
@pytest.mark.parametrize(
1062-
"holder",
1063-
[Int64Index, UInt64Index, Float64Index, RangeIndex, Series],
1064-
)
1065-
def test_ufunc_compat(self, holder):
1057+
# TODO: add more dtypes
1058+
@pytest.mark.parametrize("holder", [NumericIndex, RangeIndex, Series])
1059+
@pytest.mark.parametrize("dtype", [np.int64, np.uint64, np.float64])
1060+
def test_ufunc_compat(self, holder, dtype):
10661061
box = Series if holder is Series else Index
10671062

10681063
if holder is RangeIndex:
1064+
if dtype != np.int64:
1065+
pytest.skip(f"dtype {dtype} not relevant for RangeIndex")
10691066
idx = RangeIndex(0, 5, name="foo")
10701067
else:
1071-
idx = holder(np.arange(5, dtype="int64"), name="foo")
1068+
idx = holder(np.arange(5, dtype=dtype), name="foo")
10721069
result = np.sin(idx)
1073-
expected = box(np.sin(np.arange(5, dtype="int64")), name="foo")
1070+
expected = box(np.sin(np.arange(5, dtype=dtype)), name="foo")
10741071
tm.assert_equal(result, expected)
10751072

1076-
@pytest.mark.parametrize("holder", [Int64Index, UInt64Index, Float64Index, Series])
1077-
def test_ufunc_coercions(self, holder):
1078-
idx = holder([1, 2, 3, 4, 5], name="x")
1073+
# TODO: add more dtypes
1074+
@pytest.mark.parametrize("holder", [NumericIndex, Series])
1075+
@pytest.mark.parametrize("dtype", [np.int64, np.uint64, np.float64])
1076+
def test_ufunc_coercions(self, holder, dtype):
1077+
idx = holder([1, 2, 3, 4, 5], dtype=dtype, name="x")
10791078
box = Series if holder is Series else Index
10801079

10811080
result = np.sqrt(idx)
10821081
assert result.dtype == "f8" and isinstance(result, box)
1083-
exp = Float64Index(np.sqrt(np.array([1, 2, 3, 4, 5])), name="x")
1082+
exp = Index(np.sqrt(np.array([1, 2, 3, 4, 5], dtype=np.float64)), name="x")
10841083
exp = tm.box_expected(exp, box)
10851084
tm.assert_equal(result, exp)
10861085

10871086
result = np.divide(idx, 2.0)
10881087
assert result.dtype == "f8" and isinstance(result, box)
1089-
exp = Float64Index([0.5, 1.0, 1.5, 2.0, 2.5], name="x")
1088+
exp = Index([0.5, 1.0, 1.5, 2.0, 2.5], dtype=np.float64, name="x")
10901089
exp = tm.box_expected(exp, box)
10911090
tm.assert_equal(result, exp)
10921091

10931092
# _evaluate_numeric_binop
10941093
result = idx + 2.0
10951094
assert result.dtype == "f8" and isinstance(result, box)
1096-
exp = Float64Index([3.0, 4.0, 5.0, 6.0, 7.0], name="x")
1095+
exp = Index([3.0, 4.0, 5.0, 6.0, 7.0], dtype=np.float64, name="x")
10971096
exp = tm.box_expected(exp, box)
10981097
tm.assert_equal(result, exp)
10991098

11001099
result = idx - 2.0
11011100
assert result.dtype == "f8" and isinstance(result, box)
1102-
exp = Float64Index([-1.0, 0.0, 1.0, 2.0, 3.0], name="x")
1101+
exp = Index([-1.0, 0.0, 1.0, 2.0, 3.0], dtype=np.float64, name="x")
11031102
exp = tm.box_expected(exp, box)
11041103
tm.assert_equal(result, exp)
11051104

11061105
result = idx * 1.0
11071106
assert result.dtype == "f8" and isinstance(result, box)
1108-
exp = Float64Index([1.0, 2.0, 3.0, 4.0, 5.0], name="x")
1107+
exp = Index([1.0, 2.0, 3.0, 4.0, 5.0], dtype=np.float64, name="x")
11091108
exp = tm.box_expected(exp, box)
11101109
tm.assert_equal(result, exp)
11111110

11121111
result = idx / 2.0
11131112
assert result.dtype == "f8" and isinstance(result, box)
1114-
exp = Float64Index([0.5, 1.0, 1.5, 2.0, 2.5], name="x")
1113+
exp = Index([0.5, 1.0, 1.5, 2.0, 2.5], dtype=np.float64, name="x")
11151114
exp = tm.box_expected(exp, box)
11161115
tm.assert_equal(result, exp)
11171116

1118-
@pytest.mark.parametrize("holder", [Int64Index, UInt64Index, Float64Index, Series])
1119-
def test_ufunc_multiple_return_values(self, holder):
1120-
obj = holder([1, 2, 3], name="x")
1117+
# TODO: add more dtypes
1118+
@pytest.mark.parametrize("holder", [NumericIndex, Series])
1119+
@pytest.mark.parametrize("dtype", [np.int64, np.uint64, np.float64])
1120+
def test_ufunc_multiple_return_values(self, holder, dtype):
1121+
obj = holder([1, 2, 3], dtype=dtype, name="x")
11211122
box = Series if holder is Series else Index
11221123

11231124
result = np.modf(obj)
11241125
assert isinstance(result, tuple)
1125-
exp1 = Float64Index([0.0, 0.0, 0.0], name="x")
1126-
exp2 = Float64Index([1.0, 2.0, 3.0], name="x")
1126+
exp1 = Index([0.0, 0.0, 0.0], dtype=np.float64, name="x")
1127+
exp2 = Index([1.0, 2.0, 3.0], dtype=np.float64, name="x")
11271128
tm.assert_equal(result[0], tm.box_expected(exp1, box))
11281129
tm.assert_equal(result[1], tm.box_expected(exp2, box))
11291130

@@ -1241,7 +1242,7 @@ def test_binops_index(self, op, idx1, idx2):
12411242
@pytest.mark.parametrize("scalar", [-1, 1, 2])
12421243
def test_binops_index_scalar(self, op, idx, scalar):
12431244
result = op(idx, scalar)
1244-
expected = op(Int64Index(idx), scalar)
1245+
expected = op(Index(idx.to_numpy()), scalar)
12451246
tm.assert_index_equal(result, expected, exact="equiv")
12461247

12471248
@pytest.mark.parametrize("idx1", [RangeIndex(0, 10, 1), RangeIndex(0, 20, 2)])
@@ -1261,7 +1262,7 @@ def test_binops_index_scalar_pow(self, idx, scalar):
12611262
# numpy does not allow powers of negative integers so test separately
12621263
# https://github.com/numpy/numpy/pull/8127
12631264
result = pow(idx, scalar)
1264-
expected = pow(Int64Index(idx), scalar)
1265+
expected = pow(Index(idx.to_numpy()), scalar)
12651266
tm.assert_index_equal(result, expected, exact="equiv")
12661267

12671268
# TODO: divmod?
@@ -1336,17 +1337,18 @@ def test_numeric_compat2(self):
13361337
@pytest.mark.parametrize(
13371338
"idx, div, expected",
13381339
[
1340+
# TODO: add more dtypes
13391341
(RangeIndex(0, 1000, 2), 2, RangeIndex(0, 500, 1)),
13401342
(RangeIndex(-99, -201, -3), -3, RangeIndex(33, 67, 1)),
13411343
(
13421344
RangeIndex(0, 1000, 1),
13431345
2,
1344-
Int64Index(RangeIndex(0, 1000, 1)._values) // 2,
1346+
Index(RangeIndex(0, 1000, 1)._values) // 2,
13451347
),
13461348
(
13471349
RangeIndex(0, 100, 1),
13481350
2.0,
1349-
Int64Index(RangeIndex(0, 100, 1)._values) // 2.0,
1351+
Index(RangeIndex(0, 100, 1)._values) // 2.0,
13501352
),
13511353
(RangeIndex(0), 50, RangeIndex(0)),
13521354
(RangeIndex(2, 4, 2), 3, RangeIndex(0, 1, 1)),

pandas/tests/groupby/aggregate/test_aggregate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def test_agg_apply_corner(ts, tsframe):
137137
grouped = ts.groupby(ts * np.nan, group_keys=False)
138138
assert ts.dtype == np.float64
139139

140-
# groupby float64 values results in Float64Index
140+
# groupby float64 values results in a float64 Index
141141
exp = Series([], dtype=np.float64, index=Index([], dtype=np.float64))
142142
tm.assert_series_equal(grouped.sum(), exp)
143143
tm.assert_series_equal(grouped.agg(np.sum), exp)

pandas/tests/indexes/numeric/test_astype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class TestAstype:
1313
def test_astype_float64_to_uint64(self):
14-
# GH#45309 used to incorrectly return Int64Index
14+
# GH#45309 used to incorrectly return Index with int64 dtype
1515
idx = Index([0.0, 5.0, 10.0, 15.0, 20.0], dtype=np.float64)
1616
result = idx.astype("u8")
1717
expected = Index([0, 5, 10, 15, 20], dtype=np.uint64)

pandas/tests/indexes/period/methods/test_astype.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
period_range,
1212
)
1313
import pandas._testing as tm
14-
from pandas.core.indexes.api import Int64Index
1514

1615

1716
class TestPeriodIndexAsType:
@@ -36,7 +35,7 @@ def test_astype_conversion(self):
3635
tm.assert_index_equal(result, expected)
3736

3837
result = idx.astype(np.int64)
39-
expected = Int64Index(
38+
expected = Index(
4039
[16937] + [-9223372036854775808] * 3, dtype=np.int64, name="idx"
4140
)
4241
tm.assert_index_equal(result, expected)

pandas/tests/indexes/period/test_constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def test_constructor_simple_new(self):
329329

330330
msg = "Should be numpy array of type i8"
331331
with pytest.raises(AssertionError, match=msg):
332-
# Need ndarray, not Int64Index
332+
# Need ndarray, not int64 Index
333333
type(idx._data)._simple_new(Index(idx.asi8), freq=idx.freq)
334334

335335
arr = type(idx._data)._simple_new(idx.asi8, freq=idx.freq)

pandas/tests/reductions/test_reductions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ def test_idxmax(self):
874874
result = s.idxmax()
875875
assert result == 4
876876

877-
# Float64Index
877+
# Index with float64 dtype
878878
# GH#5914
879879
s = Series([1, 2, 3], [1.1, 2.1, 3.1])
880880
result = s.idxmax()

0 commit comments

Comments
 (0)