Skip to content

Commit 5206bb5

Browse files
topper-123Terji PetersenTerji Petersen
authored
DEPR: remove some more Int/UInt/Float64Index from tests (pandas-dev#50075)
* DEPR: remove some more Int/UInt/Float64Index from tests * fix failed tests * fix failed code check * fix tests * fix tests 2 * fix tests 3 * fix tests Co-authored-by: Terji Petersen <[email protected]> Co-authored-by: Terji Petersen <[email protected]>
1 parent 1fd894d commit 5206bb5

16 files changed

+106
-141
lines changed

pandas/tests/arithmetic/test_timedelta64.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@
2626
timedelta_range,
2727
)
2828
import pandas._testing as tm
29-
from pandas.core.api import (
30-
Float64Index,
31-
Int64Index,
32-
UInt64Index,
33-
)
29+
from pandas.core.api import NumericIndex
3430
from pandas.tests.arithmetic.common import (
3531
assert_invalid_addsub_type,
3632
assert_invalid_comparison,
@@ -492,10 +488,10 @@ def test_addition_ops(self):
492488
# random indexes
493489
msg = "Addition/subtraction of integers and integer-arrays"
494490
with pytest.raises(TypeError, match=msg):
495-
tdi + Int64Index([1, 2, 3])
491+
tdi + NumericIndex([1, 2, 3], dtype=np.int64)
496492

497493
# this is a union!
498-
# pytest.raises(TypeError, lambda : Int64Index([1,2,3]) + tdi)
494+
# pytest.raises(TypeError, lambda : Index([1,2,3]) + tdi)
499495

500496
result = tdi + dti # name will be reset
501497
expected = DatetimeIndex(["20130102", NaT, "20130105"])
@@ -1508,9 +1504,9 @@ def test_tdi_mul_float_series(self, box_with_array):
15081504
"other",
15091505
[
15101506
np.arange(1, 11),
1511-
Int64Index(range(1, 11)),
1512-
UInt64Index(range(1, 11)),
1513-
Float64Index(range(1, 11)),
1507+
NumericIndex(np.arange(1, 11), np.int64),
1508+
NumericIndex(range(1, 11), np.uint64),
1509+
NumericIndex(range(1, 11), np.float64),
15141510
pd.RangeIndex(1, 11),
15151511
],
15161512
ids=lambda x: type(x).__name__,
@@ -1594,7 +1590,7 @@ def test_td64arr_div_tdlike_scalar(self, two_hours, box_with_array):
15941590
xbox = np.ndarray if box is pd.array else box
15951591

15961592
rng = timedelta_range("1 days", "10 days", name="foo")
1597-
expected = Float64Index((np.arange(10) + 1) * 12, name="foo")
1593+
expected = NumericIndex((np.arange(10) + 1) * 12, dtype=np.float64, name="foo")
15981594

15991595
rng = tm.box_expected(rng, box)
16001596
expected = tm.box_expected(expected, xbox)
@@ -1634,7 +1630,7 @@ def test_td64arr_div_tdlike_scalar_with_nat(self, two_hours, box_with_array):
16341630
xbox = np.ndarray if box is pd.array else box
16351631

16361632
rng = TimedeltaIndex(["1 days", NaT, "2 days"], name="foo")
1637-
expected = Float64Index([12, np.nan, 24], name="foo")
1633+
expected = NumericIndex([12, np.nan, 24], dtype=np.float64, name="foo")
16381634

16391635
rng = tm.box_expected(rng, box)
16401636
expected = tm.box_expected(expected, xbox)
@@ -1652,7 +1648,7 @@ def test_td64arr_div_td64_ndarray(self, box_with_array):
16521648
xbox = np.ndarray if box is pd.array else box
16531649

16541650
rng = TimedeltaIndex(["1 days", NaT, "2 days"])
1655-
expected = Float64Index([12, np.nan, 24])
1651+
expected = NumericIndex([12, np.nan, 24], dtype=np.float64)
16561652

16571653
rng = tm.box_expected(rng, box)
16581654
expected = tm.box_expected(expected, xbox)

pandas/tests/dtypes/test_inference.py

-1
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,6 @@ def test_is_timedelta(self):
18291829
assert is_timedelta64_ns_dtype(tdi)
18301830
assert is_timedelta64_ns_dtype(tdi.astype("timedelta64[ns]"))
18311831

1832-
# Conversion to Int64Index:
18331832
assert not is_timedelta64_ns_dtype(Index([], dtype=np.float64))
18341833
assert not is_timedelta64_ns_dtype(Index([], dtype=np.int64))
18351834

pandas/tests/dtypes/test_missing.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@
3333
import pandas as pd
3434
from pandas import (
3535
DatetimeIndex,
36+
Index,
3637
NaT,
3738
Series,
3839
TimedeltaIndex,
3940
date_range,
4041
)
4142
import pandas._testing as tm
42-
from pandas.core.api import Float64Index
43+
from pandas.core.api import NumericIndex
4344

4445
fix_now = pd.Timestamp("2021-01-01")
4546
fix_utcnow = pd.Timestamp("2021-01-01", tz="UTC")
@@ -355,7 +356,7 @@ def test_decimal(self):
355356
tm.assert_series_equal(result, ~expected)
356357

357358
# index
358-
idx = pd.Index(arr)
359+
idx = Index(arr)
359360
expected = np.array([False, True])
360361
result = isna(idx)
361362
tm.assert_numpy_array_equal(result, expected)
@@ -404,10 +405,10 @@ def test_array_equivalent(dtype_equal):
404405
np.array(["a", "b", "c", "d"]), np.array(["e", "e"]), dtype_equal=dtype_equal
405406
)
406407
assert array_equivalent(
407-
Float64Index([0, np.nan]), Float64Index([0, np.nan]), dtype_equal=dtype_equal
408+
NumericIndex([0, np.nan]), NumericIndex([0, np.nan]), dtype_equal=dtype_equal
408409
)
409410
assert not array_equivalent(
410-
Float64Index([0, np.nan]), Float64Index([1, np.nan]), dtype_equal=dtype_equal
411+
NumericIndex([0, np.nan]), NumericIndex([1, np.nan]), dtype_equal=dtype_equal
411412
)
412413
assert array_equivalent(
413414
DatetimeIndex([0, np.nan]), DatetimeIndex([0, np.nan]), dtype_equal=dtype_equal
@@ -559,15 +560,15 @@ def test_array_equivalent_nested():
559560

560561
def test_array_equivalent_index_with_tuples():
561562
# GH#48446
562-
idx1 = pd.Index(np.array([(pd.NA, 4), (1, 1)], dtype="object"))
563-
idx2 = pd.Index(np.array([(1, 1), (pd.NA, 4)], dtype="object"))
563+
idx1 = Index(np.array([(pd.NA, 4), (1, 1)], dtype="object"))
564+
idx2 = Index(np.array([(1, 1), (pd.NA, 4)], dtype="object"))
564565
assert not array_equivalent(idx1, idx2)
565566
assert not idx1.equals(idx2)
566567
assert not array_equivalent(idx2, idx1)
567568
assert not idx2.equals(idx1)
568569

569-
idx1 = pd.Index(np.array([(4, pd.NA), (1, 1)], dtype="object"))
570-
idx2 = pd.Index(np.array([(1, 1), (4, pd.NA)], dtype="object"))
570+
idx1 = Index(np.array([(4, pd.NA), (1, 1)], dtype="object"))
571+
idx2 = Index(np.array([(1, 1), (4, pd.NA)], dtype="object"))
571572
assert not array_equivalent(idx1, idx2)
572573
assert not idx1.equals(idx2)
573574
assert not array_equivalent(idx2, idx1)

pandas/tests/frame/test_constructors.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
SparseArray,
5656
TimedeltaArray,
5757
)
58-
from pandas.core.api import Int64Index
5958

6059
MIXED_FLOAT_DTYPES = ["float16", "float32", "float64"]
6160
MIXED_INT_DTYPES = [
@@ -626,7 +625,7 @@ def test_constructor_2d_index(self):
626625
df = DataFrame([[1]], columns=[[1]], index=[1, 2])
627626
expected = DataFrame(
628627
[1, 1],
629-
index=Int64Index([1, 2], dtype="int64"),
628+
index=Index([1, 2], dtype="int64"),
630629
columns=MultiIndex(levels=[[1]], codes=[[0]]),
631630
)
632631
tm.assert_frame_equal(df, expected)

pandas/tests/groupby/test_apply.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
bdate_range,
1717
)
1818
import pandas._testing as tm
19-
from pandas.core.api import Int64Index
2019
from pandas.tests.groupby import get_groupby_method_args
2120

2221

@@ -799,11 +798,9 @@ def test_apply_with_mixed_types():
799798

800799
def test_func_returns_object():
801800
# GH 28652
802-
df = DataFrame({"a": [1, 2]}, index=Int64Index([1, 2]))
801+
df = DataFrame({"a": [1, 2]}, index=Index([1, 2]))
803802
result = df.groupby("a").apply(lambda g: g.index)
804-
expected = Series(
805-
[Int64Index([1]), Int64Index([2])], index=Int64Index([1, 2], name="a")
806-
)
803+
expected = Series([Index([1]), Index([2])], index=Index([1, 2], name="a"))
807804

808805
tm.assert_series_equal(result, expected)
809806

pandas/tests/groupby/test_grouping.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
date_range,
1515
)
1616
import pandas._testing as tm
17-
from pandas.core.api import (
18-
Float64Index,
19-
Int64Index,
20-
)
2117
from pandas.core.groupby.grouper import Grouping
2218

2319
# selection
@@ -691,11 +687,15 @@ def test_list_grouper_with_nat(self):
691687
),
692688
(
693689
"agg",
694-
Series(name=2, dtype=np.float64, index=Float64Index([], name=1)),
690+
Series(
691+
name=2, dtype=np.float64, index=Index([], dtype=np.float64, name=1)
692+
),
695693
),
696694
(
697695
"apply",
698-
Series(name=2, dtype=np.float64, index=Float64Index([], name=1)),
696+
Series(
697+
name=2, dtype=np.float64, index=Index([], dtype=np.float64, name=1)
698+
),
699699
),
700700
],
701701
)
@@ -759,7 +759,9 @@ def test_groupby_multiindex_level_empty(self):
759759
empty = df[df.value < 0]
760760
result = empty.groupby("id").sum()
761761
expected = DataFrame(
762-
dtype="float64", columns=["value"], index=Int64Index([], name="id")
762+
dtype="float64",
763+
columns=["value"],
764+
index=Index([], dtype=np.int64, name="id"),
763765
)
764766
tm.assert_frame_equal(result, expected)
765767

pandas/tests/groupby/test_min_max.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
Series,
1111
)
1212
import pandas._testing as tm
13-
from pandas.core.api import Int64Index
1413

1514

1615
def test_max_min_non_numeric():
@@ -123,7 +122,7 @@ def test_groupby_aggregate_period_column(func):
123122
df = DataFrame({"a": groups, "b": periods})
124123

125124
result = getattr(df.groupby("a")["b"], func)()
126-
idx = Int64Index([1, 2], name="a")
125+
idx = Index([1, 2], name="a")
127126
expected = Series(periods, index=idx, name="b")
128127

129128
tm.assert_series_equal(result, expected)
@@ -137,7 +136,7 @@ def test_groupby_aggregate_period_frame(func):
137136
df = DataFrame({"a": groups, "b": periods})
138137

139138
result = getattr(df.groupby("a"), func)()
140-
idx = Int64Index([1, 2], name="a")
139+
idx = Index([1, 2], name="a")
141140
expected = DataFrame({"b": periods}, index=idx)
142141

143142
tm.assert_frame_equal(result, expected)

pandas/tests/groupby/test_pipe.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Index,
77
)
88
import pandas._testing as tm
9-
from pandas.core.api import Int64Index
9+
from pandas.core.api import NumericIndex
1010

1111

1212
def test_pipe():
@@ -76,6 +76,6 @@ def h(df, arg3):
7676
ser = pd.Series([1, 1, 2, 2, 3, 3])
7777
result = ser.groupby(ser).pipe(lambda grp: grp.sum() * grp.count())
7878

79-
expected = pd.Series([4, 8, 12], index=Int64Index([1, 2, 3]))
79+
expected = pd.Series([4, 8, 12], index=NumericIndex([1, 2, 3], dtype=np.int64))
8080

8181
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)