Skip to content

Commit 961314d

Browse files
authored
DEPR: Remove NumericIndex from tests/arithmetic/ (#51100)
1 parent 936da9e commit 961314d

File tree

4 files changed

+41
-47
lines changed

4 files changed

+41
-47
lines changed

pandas/tests/arithmetic/conftest.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
import pytest
33

44
import pandas as pd
5-
from pandas import RangeIndex
5+
from pandas import (
6+
Index,
7+
RangeIndex,
8+
)
69
import pandas._testing as tm
7-
from pandas.core.api import NumericIndex
810
from pandas.core.computation import expressions as expr
911

1012

@@ -46,12 +48,10 @@ def one(request):
4648

4749
zeros = [
4850
box_cls([0] * 5, dtype=dtype)
49-
for box_cls in [pd.Index, np.array, pd.array]
51+
for box_cls in [Index, np.array, pd.array]
5052
for dtype in [np.int64, np.uint64, np.float64]
5153
]
52-
zeros.extend(
53-
[box_cls([-0.0] * 5, dtype=np.float64) for box_cls in [pd.Index, np.array]]
54-
)
54+
zeros.extend([box_cls([-0.0] * 5, dtype=np.float64) for box_cls in [Index, np.array]])
5555
zeros.extend([np.array(0, dtype=dtype) for dtype in [np.int64, np.uint64, np.float64]])
5656
zeros.extend([np.array(-0.0, dtype=np.float64)])
5757
zeros.extend([0, 0.0, -0.0])
@@ -75,7 +75,7 @@ def zero(request):
7575
--------
7676
arr = RangeIndex(5)
7777
arr / zeros
78-
NumericIndex([nan, inf, inf, inf, inf], dtype='float64')
78+
Index([nan, inf, inf, inf, inf], dtype='float64')
7979
"""
8080
return request.param
8181

@@ -87,9 +87,9 @@ def zero(request):
8787
@pytest.fixture(
8888
params=[
8989
# TODO: add more dtypes here
90-
NumericIndex(np.arange(5, dtype="float64")),
91-
NumericIndex(np.arange(5, dtype="int64")),
92-
NumericIndex(np.arange(5, dtype="uint64")),
90+
Index(np.arange(5, dtype="float64")),
91+
Index(np.arange(5, dtype="int64")),
92+
Index(np.arange(5, dtype="uint64")),
9393
RangeIndex(5),
9494
],
9595
ids=lambda x: type(x).__name__,
@@ -217,7 +217,7 @@ def mismatched_freq(request):
217217

218218

219219
@pytest.fixture(
220-
params=[pd.Index, pd.Series, tm.to_array, np.array, list], ids=lambda x: x.__name__
220+
params=[Index, pd.Series, tm.to_array, np.array, list], ids=lambda x: x.__name__
221221
)
222222
def box_1d_array(request):
223223
"""

pandas/tests/arithmetic/test_datetime64.py

-1
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,6 @@ def test_dt64arr_addsub_intlike(
11221122
assert_invalid_addsub_type(obj, pd.array(other), msg)
11231123
assert_invalid_addsub_type(obj, pd.Categorical(other), msg)
11241124
assert_invalid_addsub_type(obj, pd.Index(other), msg)
1125-
assert_invalid_addsub_type(obj, pd.core.indexes.api.NumericIndex(other), msg)
11261125
assert_invalid_addsub_type(obj, Series(other), msg)
11271126

11281127
@pytest.mark.parametrize(

pandas/tests/arithmetic/test_numeric.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
)
2323
import pandas._testing as tm
2424
from pandas.core import ops
25-
from pandas.core.api import NumericIndex
2625
from pandas.core.computation import expressions as expr
2726
from pandas.tests.arithmetic.common import (
2827
assert_invalid_addsub_type,
@@ -1055,7 +1054,7 @@ def test_series_divmod_zero(self):
10551054

10561055
class TestUFuncCompat:
10571056
# TODO: add more dtypes
1058-
@pytest.mark.parametrize("holder", [NumericIndex, RangeIndex, Series])
1057+
@pytest.mark.parametrize("holder", [Index, RangeIndex, Series])
10591058
@pytest.mark.parametrize("dtype", [np.int64, np.uint64, np.float64])
10601059
def test_ufunc_compat(self, holder, dtype):
10611060
box = Series if holder is Series else Index
@@ -1071,7 +1070,7 @@ def test_ufunc_compat(self, holder, dtype):
10711070
tm.assert_equal(result, expected)
10721071

10731072
# TODO: add more dtypes
1074-
@pytest.mark.parametrize("holder", [NumericIndex, Series])
1073+
@pytest.mark.parametrize("holder", [Index, Series])
10751074
@pytest.mark.parametrize("dtype", [np.int64, np.uint64, np.float64])
10761075
def test_ufunc_coercions(self, holder, dtype):
10771076
idx = holder([1, 2, 3, 4, 5], dtype=dtype, name="x")
@@ -1115,7 +1114,7 @@ def test_ufunc_coercions(self, holder, dtype):
11151114
tm.assert_equal(result, exp)
11161115

11171116
# TODO: add more dtypes
1118-
@pytest.mark.parametrize("holder", [NumericIndex, Series])
1117+
@pytest.mark.parametrize("holder", [Index, Series])
11191118
@pytest.mark.parametrize("dtype", [np.int64, np.uint64, np.float64])
11201119
def test_ufunc_multiple_return_values(self, holder, dtype):
11211120
obj = holder([1, 2, 3], dtype=dtype, name="x")

pandas/tests/arithmetic/test_timedelta64.py

+27-31
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pandas import (
1818
DataFrame,
1919
DatetimeIndex,
20+
Index,
2021
NaT,
2122
Series,
2223
Timedelta,
@@ -26,7 +27,6 @@
2627
timedelta_range,
2728
)
2829
import pandas._testing as tm
29-
from pandas.core.api import NumericIndex
3030
from pandas.core.arrays import PandasArray
3131
from pandas.tests.arithmetic.common import (
3232
assert_invalid_addsub_type,
@@ -68,9 +68,7 @@ class TestTimedelta64ArrayLikeComparisons:
6868
def test_compare_timedelta64_zerodim(self, box_with_array):
6969
# GH#26689 should unbox when comparing with zerodim array
7070
box = box_with_array
71-
xbox = (
72-
box_with_array if box_with_array not in [pd.Index, pd.array] else np.ndarray
73-
)
71+
xbox = box_with_array if box_with_array not in [Index, pd.array] else np.ndarray
7472

7573
tdi = timedelta_range("2H", periods=4)
7674
other = np.array(tdi.to_numpy()[0])
@@ -93,7 +91,7 @@ def test_compare_timedelta64_zerodim(self, box_with_array):
9391
def test_compare_timedeltalike_scalar(self, box_with_array, td_scalar):
9492
# regression test for GH#5963
9593
box = box_with_array
96-
xbox = box if box not in [pd.Index, pd.array] else np.ndarray
94+
xbox = box if box not in [Index, pd.array] else np.ndarray
9795

9896
ser = Series([timedelta(days=1), timedelta(days=2)])
9997
ser = tm.box_expected(ser, box)
@@ -489,7 +487,7 @@ def test_addition_ops(self):
489487
# random indexes
490488
msg = "Addition/subtraction of integers and integer-arrays"
491489
with pytest.raises(TypeError, match=msg):
492-
tdi + NumericIndex([1, 2, 3], dtype=np.int64)
490+
tdi + Index([1, 2, 3], dtype=np.int64)
493491

494492
# this is a union!
495493
# pytest.raises(TypeError, lambda : Index([1,2,3]) + tdi)
@@ -600,7 +598,7 @@ def test_tdi_iadd_timedeltalike(self, two_hours, box_with_array):
600598
orig_rng = rng
601599
rng += two_hours
602600
tm.assert_equal(rng, expected)
603-
if box_with_array is not pd.Index:
601+
if box_with_array is not Index:
604602
# Check that operation is actually inplace
605603
tm.assert_equal(orig_rng, expected)
606604

@@ -615,7 +613,7 @@ def test_tdi_isub_timedeltalike(self, two_hours, box_with_array):
615613
orig_rng = rng
616614
rng -= two_hours
617615
tm.assert_equal(rng, expected)
618-
if box_with_array is not pd.Index:
616+
if box_with_array is not Index:
619617
# Check that operation is actually inplace
620618
tm.assert_equal(orig_rng, expected)
621619

@@ -1119,7 +1117,7 @@ def test_td64arr_addsub_numeric_scalar_invalid(self, box_with_array, other):
11191117
"vec",
11201118
[
11211119
np.array([1, 2, 3]),
1122-
pd.Index([1, 2, 3]),
1120+
Index([1, 2, 3]),
11231121
Series([1, 2, 3]),
11241122
DataFrame([[1, 2, 3]]),
11251123
],
@@ -1292,7 +1290,7 @@ def test_td64arr_add_sub_offset_index(self, names, box_with_array):
12921290
exname = get_expected_name(box, names)
12931291

12941292
tdi = TimedeltaIndex(["1 days 00:00:00", "3 days 04:00:00"], name=names[0])
1295-
other = pd.Index([offsets.Hour(n=1), offsets.Minute(n=-2)], name=names[1])
1293+
other = Index([offsets.Hour(n=1), offsets.Minute(n=-2)], name=names[1])
12961294
other = np.array(other) if box in [tm.to_array, pd.array] else other
12971295

12981296
expected = TimedeltaIndex(
@@ -1350,7 +1348,7 @@ def test_td64arr_add_sub_offset_array(self, box_with_array):
13501348
def test_td64arr_with_offset_series(self, names, box_with_array):
13511349
# GH#18849
13521350
box = box_with_array
1353-
box2 = Series if box in [pd.Index, tm.to_array, pd.array] else box
1351+
box2 = Series if box in [Index, tm.to_array, pd.array] else box
13541352
exname = get_expected_name(box, names)
13551353

13561354
tdi = TimedeltaIndex(["1 days 00:00:00", "3 days 04:00:00"], name=names[0])
@@ -1379,7 +1377,7 @@ def test_td64arr_with_offset_series(self, names, box_with_array):
13791377
res3 = obj - other
13801378
tm.assert_equal(res3, expected_sub)
13811379

1382-
@pytest.mark.parametrize("obox", [np.array, pd.Index, Series])
1380+
@pytest.mark.parametrize("obox", [np.array, Index, Series])
13831381
def test_td64arr_addsub_anchored_offset_arraylike(self, obox, box_with_array):
13841382
# GH#18824
13851383
tdi = TimedeltaIndex(["1 days 00:00:00", "3 days 04:00:00"])
@@ -1418,7 +1416,7 @@ def test_td64arr_add_sub_object_array(self, box_with_array):
14181416
with tm.assert_produces_warning(PerformanceWarning):
14191417
result = tdarr + other
14201418

1421-
expected = pd.Index(
1419+
expected = Index(
14221420
[Timedelta(days=2), Timedelta(days=4), Timestamp("2000-01-07")]
14231421
)
14241422
expected = tm.box_expected(expected, xbox).astype(object)
@@ -1432,7 +1430,7 @@ def test_td64arr_add_sub_object_array(self, box_with_array):
14321430
with tm.assert_produces_warning(PerformanceWarning):
14331431
result = other - tdarr
14341432

1435-
expected = pd.Index([Timedelta(0), Timedelta(0), Timestamp("2000-01-01")])
1433+
expected = Index([Timedelta(0), Timedelta(0), Timestamp("2000-01-01")])
14361434
expected = tm.box_expected(expected, xbox).astype(object)
14371435
tm.assert_equal(result, expected)
14381436

@@ -1486,7 +1484,7 @@ def test_tdi_mul_int_array(self, box_with_array):
14861484

14871485
def test_tdi_mul_int_series(self, box_with_array):
14881486
box = box_with_array
1489-
xbox = Series if box in [pd.Index, tm.to_array, pd.array] else box
1487+
xbox = Series if box in [Index, tm.to_array, pd.array] else box
14901488

14911489
idx = TimedeltaIndex(np.arange(5, dtype="int64"))
14921490
expected = TimedeltaIndex(np.arange(5, dtype="int64") ** 2)
@@ -1499,7 +1497,7 @@ def test_tdi_mul_int_series(self, box_with_array):
14991497

15001498
def test_tdi_mul_float_series(self, box_with_array):
15011499
box = box_with_array
1502-
xbox = Series if box in [pd.Index, tm.to_array, pd.array] else box
1500+
xbox = Series if box in [Index, tm.to_array, pd.array] else box
15031501

15041502
idx = TimedeltaIndex(np.arange(5, dtype="int64"))
15051503
idx = tm.box_expected(idx, box)
@@ -1516,9 +1514,9 @@ def test_tdi_mul_float_series(self, box_with_array):
15161514
"other",
15171515
[
15181516
np.arange(1, 11),
1519-
NumericIndex(np.arange(1, 11), np.int64),
1520-
NumericIndex(range(1, 11), np.uint64),
1521-
NumericIndex(range(1, 11), np.float64),
1517+
Index(np.arange(1, 11), np.int64),
1518+
Index(range(1, 11), np.uint64),
1519+
Index(range(1, 11), np.float64),
15221520
pd.RangeIndex(1, 11),
15231521
],
15241522
ids=lambda x: type(x).__name__,
@@ -1602,7 +1600,7 @@ def test_td64arr_div_tdlike_scalar(self, two_hours, box_with_array):
16021600
xbox = np.ndarray if box is pd.array else box
16031601

16041602
rng = timedelta_range("1 days", "10 days", name="foo")
1605-
expected = NumericIndex((np.arange(10) + 1) * 12, dtype=np.float64, name="foo")
1603+
expected = Index((np.arange(10) + 1) * 12, dtype=np.float64, name="foo")
16061604

16071605
rng = tm.box_expected(rng, box)
16081606
expected = tm.box_expected(expected, xbox)
@@ -1642,7 +1640,7 @@ def test_td64arr_div_tdlike_scalar_with_nat(self, two_hours, box_with_array):
16421640
xbox = np.ndarray if box is pd.array else box
16431641

16441642
rng = TimedeltaIndex(["1 days", NaT, "2 days"], name="foo")
1645-
expected = NumericIndex([12, np.nan, 24], dtype=np.float64, name="foo")
1643+
expected = Index([12, np.nan, 24], dtype=np.float64, name="foo")
16461644

16471645
rng = tm.box_expected(rng, box)
16481646
expected = tm.box_expected(expected, xbox)
@@ -1660,7 +1658,7 @@ def test_td64arr_div_td64_ndarray(self, box_with_array):
16601658
xbox = np.ndarray if box is pd.array else box
16611659

16621660
rng = TimedeltaIndex(["1 days", NaT, "2 days"])
1663-
expected = NumericIndex([12, np.nan, 24], dtype=np.float64)
1661+
expected = Index([12, np.nan, 24], dtype=np.float64)
16641662

16651663
rng = tm.box_expected(rng, box)
16661664
expected = tm.box_expected(expected, xbox)
@@ -1700,7 +1698,7 @@ def test_tdarr_div_length_mismatch(self, box_with_array):
17001698
msg = "Cannot divide vectors|Unable to coerce to Series"
17011699
for obj in [mismatched, mismatched[:2]]:
17021700
# one shorter, one longer
1703-
for other in [obj, np.array(obj), pd.Index(obj)]:
1701+
for other in [obj, np.array(obj), Index(obj)]:
17041702
with pytest.raises(ValueError, match=msg):
17051703
rng / other
17061704
with pytest.raises(ValueError, match=msg):
@@ -1717,9 +1715,7 @@ def test_td64_div_object_mixed_result(self, box_with_array):
17171715

17181716
res = tdi / other
17191717

1720-
expected = pd.Index(
1721-
[1.0, np.timedelta64("NaT", "ns"), orig[0], 1.5], dtype=object
1722-
)
1718+
expected = Index([1.0, np.timedelta64("NaT", "ns"), orig[0], 1.5], dtype=object)
17231719
expected = tm.box_expected(expected, box_with_array, transpose=False)
17241720
if isinstance(expected, PandasArray):
17251721
expected = expected.to_numpy()
@@ -1730,7 +1726,7 @@ def test_td64_div_object_mixed_result(self, box_with_array):
17301726

17311727
res = tdi // other
17321728

1733-
expected = pd.Index([1, np.timedelta64("NaT", "ns"), orig[0], 1], dtype=object)
1729+
expected = Index([1, np.timedelta64("NaT", "ns"), orig[0], 1], dtype=object)
17341730
expected = tm.box_expected(expected, box_with_array, transpose=False)
17351731
if isinstance(expected, PandasArray):
17361732
expected = expected.to_numpy()
@@ -1974,7 +1970,7 @@ def test_td64arr_floordiv_numeric_scalar(self, box_with_array, two):
19741970

19751971
@pytest.mark.parametrize(
19761972
"vector",
1977-
[np.array([20, 30, 40]), pd.Index([20, 30, 40]), Series([20, 30, 40])],
1973+
[np.array([20, 30, 40]), Index([20, 30, 40]), Series([20, 30, 40])],
19781974
ids=lambda x: type(x).__name__,
19791975
)
19801976
def test_td64arr_rmul_numeric_array(
@@ -2004,7 +2000,7 @@ def test_td64arr_rmul_numeric_array(
20042000

20052001
@pytest.mark.parametrize(
20062002
"vector",
2007-
[np.array([20, 30, 40]), pd.Index([20, 30, 40]), Series([20, 30, 40])],
2003+
[np.array([20, 30, 40]), Index([20, 30, 40]), Series([20, 30, 40])],
20082004
ids=lambda x: type(x).__name__,
20092005
)
20102006
def test_td64arr_div_numeric_array(
@@ -2118,8 +2114,8 @@ def test_td64arr_all_nat_div_object_dtype_numeric(self, box_with_array):
21182114
left = tm.box_expected(tdi, box_with_array)
21192115
right = np.array([2, 2.0], dtype=object)
21202116

2121-
expected = pd.Index([np.timedelta64("NaT", "ns")] * 2, dtype=object)
2122-
if box_with_array is not pd.Index:
2117+
expected = Index([np.timedelta64("NaT", "ns")] * 2, dtype=object)
2118+
if box_with_array is not Index:
21232119
expected = tm.box_expected(expected, box_with_array).astype(object)
21242120

21252121
result = left / right

0 commit comments

Comments
 (0)