Skip to content

Commit 05d12b5

Browse files
topper-123Terji Petersen
and
Terji Petersen
authored
DEPR: remove Int/Uint/Float64Index from pandas/tests/indexing & pandas/tests/series (#50781)
* remove Int/Uint/Float64Index from pandas/tests/indexing & pandas/tests/series * fix failures * fix failures II * fix failures III * make positive integers explicit Co-authored-by: Terji Petersen <[email protected]>
1 parent 0569760 commit 05d12b5

25 files changed

+157
-166
lines changed

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
from pandas.core.indexes.accessors import CombinedDatetimelikeProperties
134134
from pandas.core.indexes.api import (
135135
DatetimeIndex,
136-
Float64Index,
137136
Index,
138137
MultiIndex,
139138
PeriodIndex,
@@ -2591,7 +2590,8 @@ def quantile(
25912590

25922591
if is_list_like(q):
25932592
result.name = self.name
2594-
return self._constructor(result, index=Float64Index(q), name=self.name)
2593+
idx = Index(q, dtype=np.float64)
2594+
return self._constructor(result, index=idx, name=self.name)
25952595
else:
25962596
# scalar
25972597
return result.iloc[0]

pandas/io/pytables.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
is_datetime64_dtype,
7171
is_datetime64tz_dtype,
7272
is_extension_array_dtype,
73+
is_integer_dtype,
7374
is_list_like,
7475
is_string_dtype,
7576
is_timedelta64_dtype,
@@ -88,7 +89,7 @@
8889
concat,
8990
isna,
9091
)
91-
from pandas.core.api import Int64Index
92+
from pandas.core.api import NumericIndex
9293
from pandas.core.arrays import (
9394
Categorical,
9495
DatetimeArray,
@@ -2242,13 +2243,13 @@ class GenericIndexCol(IndexCol):
22422243
def is_indexed(self) -> bool:
22432244
return False
22442245

2245-
# error: Return type "Tuple[Int64Index, Int64Index]" of "convert"
2246+
# error: Return type "Tuple[NumericIndex, NumericIndex]" of "convert"
22462247
# incompatible with return type "Union[Tuple[ndarray[Any, Any],
22472248
# ndarray[Any, Any]], Tuple[DatetimeIndex, DatetimeIndex]]" in
22482249
# supertype "IndexCol"
22492250
def convert( # type: ignore[override]
22502251
self, values: np.ndarray, nan_rep, encoding: str, errors: str
2251-
) -> tuple[Int64Index, Int64Index]:
2252+
) -> tuple[NumericIndex, NumericIndex]:
22522253
"""
22532254
Convert the data from this selection to the appropriate pandas type.
22542255
@@ -2261,7 +2262,7 @@ def convert( # type: ignore[override]
22612262
"""
22622263
assert isinstance(values, np.ndarray), type(values)
22632264

2264-
index = Int64Index(np.arange(len(values)))
2265+
index = NumericIndex(np.arange(len(values)), dtype=np.int64)
22652266
return index, index
22662267

22672268
def set_attr(self) -> None:
@@ -4864,11 +4865,11 @@ def _convert_index(name: str, index: Index, encoding: str, errors: str) -> Index
48644865
atom = DataIndexableCol._get_atom(converted)
48654866

48664867
if (
4867-
isinstance(index, Int64Index)
4868+
(isinstance(index, NumericIndex) and is_integer_dtype(index))
48684869
or needs_i8_conversion(index.dtype)
48694870
or is_bool_dtype(index.dtype)
48704871
):
4871-
# Includes Int64Index, RangeIndex, DatetimeIndex, TimedeltaIndex, PeriodIndex,
4872+
# Includes NumericIndex, RangeIndex, DatetimeIndex, TimedeltaIndex, PeriodIndex,
48724873
# in which case "kind" is "integer", "integer", "datetime64",
48734874
# "timedelta64", and "integer", respectively.
48744875
return IndexCol(

pandas/tests/indexes/common.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@
2828
isna,
2929
)
3030
import pandas._testing as tm
31-
from pandas.core.api import ( # noqa:F401
32-
Float64Index,
33-
Int64Index,
34-
NumericIndex,
35-
UInt64Index,
36-
)
31+
from pandas.core.api import NumericIndex
3732
from pandas.core.arrays import BaseMaskedArray
3833

3934

@@ -322,7 +317,9 @@ def test_numpy_argsort(self, index):
322317
def test_repeat(self, simple_index):
323318
rep = 2
324319
idx = simple_index.copy()
325-
new_index_cls = Int64Index if isinstance(idx, RangeIndex) else idx._constructor
320+
new_index_cls = (
321+
NumericIndex if isinstance(idx, RangeIndex) else idx._constructor
322+
)
326323
expected = new_index_cls(idx.values.repeat(rep), name=idx.name)
327324
tm.assert_index_equal(idx.repeat(rep), expected)
328325

@@ -505,7 +502,6 @@ def test_equals_op(self, simple_index):
505502
# assuming the 2nd to last item is unique in the data
506503
item = index_a[-2]
507504
tm.assert_numpy_array_equal(index_a == item, expected3)
508-
# For RangeIndex we can convert to Int64Index
509505
tm.assert_series_equal(series_a == item, Series(expected3))
510506

511507
def test_format(self, simple_index):
@@ -596,7 +592,7 @@ def test_map(self, simple_index):
596592
idx = simple_index
597593

598594
result = idx.map(lambda x: x)
599-
# For RangeIndex we convert to Int64Index
595+
# RangeIndex are equivalent to the similar NumericIndex with int64 dtype
600596
tm.assert_index_equal(result, idx, exact="equiv")
601597

602598
@pytest.mark.parametrize(
@@ -619,7 +615,7 @@ def test_map_dictlike(self, mapper, simple_index):
619615
identity = mapper(idx.values, idx)
620616

621617
result = idx.map(identity)
622-
# For RangeIndex we convert to Int64Index
618+
# RangeIndex are equivalent to the similar NumericIndex with int64 dtype
623619
tm.assert_index_equal(result, idx, exact="equiv")
624620

625621
# empty mappable
@@ -910,19 +906,19 @@ def test_arithmetic_explicit_conversions(self):
910906

911907
# float conversions
912908
arr = np.arange(5, dtype="int64") * 3.2
913-
expected = Float64Index(arr)
909+
expected = NumericIndex(arr, dtype=np.float64)
914910
fidx = idx * 3.2
915911
tm.assert_index_equal(fidx, expected)
916912
fidx = 3.2 * idx
917913
tm.assert_index_equal(fidx, expected)
918914

919915
# interops with numpy arrays
920-
expected = Float64Index(arr)
916+
expected = NumericIndex(arr, dtype=np.float64)
921917
a = np.zeros(5, dtype="float64")
922918
result = fidx - a
923919
tm.assert_index_equal(result, expected)
924920

925-
expected = Float64Index(-arr)
921+
expected = NumericIndex(-arr, dtype=np.float64)
926922
a = np.zeros(5, dtype="float64")
927923
result = a - fidx
928924
tm.assert_index_equal(result, expected)

pandas/tests/indexes/conftest.py

+20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Series,
66
array,
77
)
8+
import pandas._testing as tm
89

910

1011
@pytest.fixture(params=[None, False])
@@ -39,3 +40,22 @@ def listlike_box(request):
3940
Types that may be passed as the indexer to searchsorted.
4041
"""
4142
return request.param
43+
44+
45+
@pytest.fixture(
46+
params=[
47+
*tm.ALL_REAL_NUMPY_DTYPES,
48+
"object",
49+
"category",
50+
"datetime64[ns]",
51+
"timedelta64[ns]",
52+
]
53+
)
54+
def any_numpy_dtype_for_small_pos_integer_indexes(request):
55+
"""
56+
Dtypes that can be given to an Index with small positive integers.
57+
58+
This means that for any dtype `x` in the params list, `Index([1, 2, 3], dtype=x)` is
59+
valid and gives the correct Index (sub-)class.
60+
"""
61+
return request.param

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
date_range,
1616
)
1717
import pandas._testing as tm
18-
from pandas.core.api import Int64Index
1918

2019

2120
class TestDatetimeIndex:
@@ -30,7 +29,7 @@ def test_astype(self):
3029
tm.assert_index_equal(result, expected)
3130

3231
result = idx.astype(np.int64)
33-
expected = Int64Index(
32+
expected = Index(
3433
[1463356800000000000] + [-9223372036854775808] * 3,
3534
dtype=np.int64,
3635
name="idx",

pandas/tests/indexes/datetimes/test_scalar_compat.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
date_range,
2020
)
2121
import pandas._testing as tm
22-
from pandas.core.api import Float64Index
2322

2423

2524
class TestDatetimeIndexOps:
@@ -316,33 +315,33 @@ def test_1700(self):
316315
dr = date_range(start=Timestamp("1710-10-01"), periods=5, freq="D")
317316
r1 = pd.Index([x.to_julian_date() for x in dr])
318317
r2 = dr.to_julian_date()
319-
assert isinstance(r2, Float64Index)
318+
assert isinstance(r2, pd.Index) and r2.dtype == np.float64
320319
tm.assert_index_equal(r1, r2)
321320

322321
def test_2000(self):
323322
dr = date_range(start=Timestamp("2000-02-27"), periods=5, freq="D")
324323
r1 = pd.Index([x.to_julian_date() for x in dr])
325324
r2 = dr.to_julian_date()
326-
assert isinstance(r2, Float64Index)
325+
assert isinstance(r2, pd.Index) and r2.dtype == np.float64
327326
tm.assert_index_equal(r1, r2)
328327

329328
def test_hour(self):
330329
dr = date_range(start=Timestamp("2000-02-27"), periods=5, freq="H")
331330
r1 = pd.Index([x.to_julian_date() for x in dr])
332331
r2 = dr.to_julian_date()
333-
assert isinstance(r2, Float64Index)
332+
assert isinstance(r2, pd.Index) and r2.dtype == np.float64
334333
tm.assert_index_equal(r1, r2)
335334

336335
def test_minute(self):
337336
dr = date_range(start=Timestamp("2000-02-27"), periods=5, freq="T")
338337
r1 = pd.Index([x.to_julian_date() for x in dr])
339338
r2 = dr.to_julian_date()
340-
assert isinstance(r2, Float64Index)
339+
assert isinstance(r2, pd.Index) and r2.dtype == np.float64
341340
tm.assert_index_equal(r1, r2)
342341

343342
def test_second(self):
344343
dr = date_range(start=Timestamp("2000-02-27"), periods=5, freq="S")
345344
r1 = pd.Index([x.to_julian_date() for x in dr])
346345
r2 = dr.to_julian_date()
347-
assert isinstance(r2, Float64Index)
346+
assert isinstance(r2, pd.Index) and r2.dtype == np.float64
348347
tm.assert_index_equal(r1, r2)

pandas/tests/indexes/datetimes/test_setops.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
date_range,
1717
)
1818
import pandas._testing as tm
19-
from pandas.core.api import Int64Index
2019

2120
from pandas.tseries.offsets import (
2221
BMonthEnd,
@@ -184,7 +183,7 @@ def test_union_dataframe_index(self):
184183
tm.assert_index_equal(df.index, exp)
185184

186185
def test_union_with_DatetimeIndex(self, sort):
187-
i1 = Int64Index(np.arange(0, 20, 2))
186+
i1 = Index(np.arange(0, 20, 2, dtype=np.int64))
188187
i2 = date_range(start="2012-01-03 00:00:00", periods=10, freq="D")
189188
# Works
190189
i1.union(i2, sort=sort)

pandas/tests/indexes/interval/test_formats.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
from pandas import (
55
DataFrame,
6+
Index,
67
Interval,
78
IntervalIndex,
89
Series,
910
Timedelta,
1011
Timestamp,
1112
)
1213
import pandas._testing as tm
13-
from pandas.core.api import Float64Index
1414

1515

1616
class TestIntervalIndexRendering:
@@ -54,8 +54,8 @@ def test_repr_floats(self):
5454
[
5555
Interval(left, right)
5656
for left, right in zip(
57-
Float64Index([329.973, 345.137], dtype="float64"),
58-
Float64Index([345.137, 360.191], dtype="float64"),
57+
Index([329.973, 345.137], dtype="float64"),
58+
Index([345.137, 360.191], dtype="float64"),
5959
)
6060
]
6161
),

pandas/tests/indexes/interval/test_interval.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
timedelta_range,
1919
)
2020
import pandas._testing as tm
21-
from pandas.core.api import Float64Index
2221
import pandas.core.common as com
2322

2423

@@ -406,7 +405,7 @@ def test_maybe_convert_i8_nat(self, breaks):
406405
index = IntervalIndex.from_breaks(breaks)
407406

408407
to_convert = breaks._constructor([pd.NaT] * 3)
409-
expected = Float64Index([np.nan] * 3)
408+
expected = Index([np.nan] * 3, dtype=np.float64)
410409
result = index._maybe_convert_i8(to_convert)
411410
tm.assert_index_equal(result, expected)
412411

pandas/tests/indexes/multi/test_analytics.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
period_range,
1010
)
1111
import pandas._testing as tm
12-
from pandas.core.api import UInt64Index
1312

1413

1514
def test_infer_objects(idx):
@@ -196,8 +195,8 @@ def test_map_dictlike(idx, mapper):
196195

197196
identity = mapper(idx.values, idx)
198197

199-
# we don't infer to UInt64 for a dict
200-
if isinstance(idx, UInt64Index) and isinstance(identity, dict):
198+
# we don't infer to uint64 dtype for a dict
199+
if idx.dtype == np.uint64 and isinstance(identity, dict):
201200
expected = idx.astype("int64")
202201
else:
203202
expected = idx

pandas/tests/indexes/multi/test_integrity.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
import pandas as pd
99
from pandas import (
10+
Index,
1011
IntervalIndex,
1112
MultiIndex,
1213
RangeIndex,
1314
)
1415
import pandas._testing as tm
15-
from pandas.core.api import Int64Index
1616

1717

1818
def test_labels_dtypes():
@@ -84,17 +84,17 @@ def test_values_multiindex_periodindex():
8484
idx = MultiIndex.from_arrays([ints, pidx])
8585
result = idx.values
8686

87-
outer = Int64Index([x[0] for x in result])
88-
tm.assert_index_equal(outer, Int64Index(ints))
87+
outer = Index([x[0] for x in result])
88+
tm.assert_index_equal(outer, Index(ints, dtype=np.int64))
8989

9090
inner = pd.PeriodIndex([x[1] for x in result])
9191
tm.assert_index_equal(inner, pidx)
9292

9393
# n_lev > n_lab
9494
result = idx[:2].values
9595

96-
outer = Int64Index([x[0] for x in result])
97-
tm.assert_index_equal(outer, Int64Index(ints[:2]))
96+
outer = Index([x[0] for x in result])
97+
tm.assert_index_equal(outer, Index(ints[:2], dtype=np.int64))
9898

9999
inner = pd.PeriodIndex([x[1] for x in result])
100100
tm.assert_index_equal(inner, pidx[:2])
@@ -246,11 +246,11 @@ def test_rangeindex_fallback_coercion_bug():
246246
tm.assert_frame_equal(df, expected, check_like=True)
247247

248248
result = df.index.get_level_values("fizz")
249-
expected = Int64Index(np.arange(10), name="fizz").repeat(10)
249+
expected = Index(np.arange(10, dtype=np.int64), name="fizz").repeat(10)
250250
tm.assert_index_equal(result, expected)
251251

252252
result = df.index.get_level_values("buzz")
253-
expected = Int64Index(np.tile(np.arange(10), 10), name="buzz")
253+
expected = Index(np.tile(np.arange(10, dtype=np.int64), 10), name="buzz")
254254
tm.assert_index_equal(result, expected)
255255

256256

pandas/tests/indexes/period/test_indexing.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
period_range,
2121
)
2222
import pandas._testing as tm
23-
from pandas.core.api import (
24-
Float64Index,
25-
Int64Index,
26-
)
2723

2824
dti4 = date_range("2016-01-01", periods=4)
2925
dti = dti4[:-1]
@@ -806,10 +802,10 @@ def test_asof_locs_mismatched_type(self):
806802

807803
msg = "must be DatetimeIndex or PeriodIndex"
808804
with pytest.raises(TypeError, match=msg):
809-
pi.asof_locs(Int64Index(pi.asi8), mask)
805+
pi.asof_locs(pd.Index(pi.asi8, dtype=np.int64), mask)
810806

811807
with pytest.raises(TypeError, match=msg):
812-
pi.asof_locs(Float64Index(pi.asi8), mask)
808+
pi.asof_locs(pd.Index(pi.asi8, dtype=np.float64), mask)
813809

814810
with pytest.raises(TypeError, match=msg):
815811
# TimedeltaIndex

0 commit comments

Comments
 (0)