Skip to content

Commit 6b9321f

Browse files
Terji Petersentopper-123
Terji Petersen
authored andcommitted
remove Int/Uint/Float64Index from pandas/tests/indexing & pandas/tests/series
1 parent 45683ae commit 6b9321f

26 files changed

+160
-181
lines changed

pandas/core/indexes/base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
ensure_platform_int,
9191
is_bool_dtype,
9292
is_categorical_dtype,
93-
is_complex_dtype,
9493
is_dtype_equal,
9594
is_ea_or_datetimelike_dtype,
9695
is_extension_array_dtype,
@@ -123,7 +122,6 @@
123122
ABCDatetimeIndex,
124123
ABCMultiIndex,
125124
ABCPeriodIndex,
126-
ABCRangeIndex,
127125
ABCSeries,
128126
ABCTimedeltaIndex,
129127
)

pandas/core/series.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
from pandas.core.indexes.accessors import CombinedDatetimelikeProperties
127127
from pandas.core.indexes.api import (
128128
DatetimeIndex,
129-
Float64Index,
130129
Index,
131130
MultiIndex,
132131
PeriodIndex,
@@ -2554,7 +2553,8 @@ def quantile(
25542553

25552554
if is_list_like(q):
25562555
result.name = self.name
2557-
return self._constructor(result, index=Float64Index(q), name=self.name)
2556+
idx = Index(q, dtype=np.float64)
2557+
return self._constructor(result, index=idx, name=self.name)
25582558
else:
25592559
# scalar
25602560
return result.iloc[0]

pandas/io/pytables.py

Lines changed: 7 additions & 6 deletions
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,
@@ -2240,13 +2241,13 @@ class GenericIndexCol(IndexCol):
22402241
def is_indexed(self) -> bool:
22412242
return False
22422243

2243-
# error: Return type "Tuple[Int64Index, Int64Index]" of "convert"
2244+
# error: Return type "Tuple[NumericIndex, NumericIndex]" of "convert"
22442245
# incompatible with return type "Union[Tuple[ndarray[Any, Any],
22452246
# ndarray[Any, Any]], Tuple[DatetimeIndex, DatetimeIndex]]" in
22462247
# supertype "IndexCol"
22472248
def convert( # type: ignore[override]
22482249
self, values: np.ndarray, nan_rep, encoding: str, errors: str
2249-
) -> tuple[Int64Index, Int64Index]:
2250+
) -> tuple[NumericIndex, NumericIndex]:
22502251
"""
22512252
Convert the data from this selection to the appropriate pandas type.
22522253
@@ -2259,7 +2260,7 @@ def convert( # type: ignore[override]
22592260
"""
22602261
assert isinstance(values, np.ndarray), type(values)
22612262

2262-
index = Int64Index(np.arange(len(values)))
2263+
index = NumericIndex(np.arange(len(values)), dtype=np.int64)
22632264
return index, index
22642265

22652266
def set_attr(self) -> None:
@@ -4862,11 +4863,11 @@ def _convert_index(name: str, index: Index, encoding: str, errors: str) -> Index
48624863
atom = DataIndexableCol._get_atom(converted)
48634864

48644865
if (
4865-
isinstance(index, Int64Index)
4866+
(isinstance(index, NumericIndex) and is_integer_dtype(index))
48664867
or needs_i8_conversion(index.dtype)
48674868
or is_bool_dtype(index.dtype)
48684869
):
4869-
# Includes Int64Index, RangeIndex, DatetimeIndex, TimedeltaIndex, PeriodIndex,
4870+
# Includes NumericIndex, RangeIndex, DatetimeIndex, TimedeltaIndex, PeriodIndex,
48704871
# in which case "kind" is "integer", "integer", "datetime64",
48714872
# "timedelta64", and "integer", respectively.
48724873
return IndexCol(

pandas/tests/indexes/common.py

Lines changed: 9 additions & 13 deletions
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(
@@ -617,7 +613,7 @@ def test_map_dictlike(self, mapper, simple_index):
617613
identity = mapper(idx.values, idx)
618614

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

623619
# empty mappable
@@ -874,19 +870,19 @@ def test_arithmetic_explicit_conversions(self):
874870

875871
# float conversions
876872
arr = np.arange(5, dtype="int64") * 3.2
877-
expected = Float64Index(arr)
873+
expected = NumericIndex(arr, dtype=np.float64)
878874
fidx = idx * 3.2
879875
tm.assert_index_equal(fidx, expected)
880876
fidx = 3.2 * idx
881877
tm.assert_index_equal(fidx, expected)
882878

883879
# interops with numpy arrays
884-
expected = Float64Index(arr)
880+
expected = NumericIndex(arr, dtype=np.float64)
885881
a = np.zeros(5, dtype="float64")
886882
result = fidx - a
887883
tm.assert_index_equal(result, expected)
888884

889-
expected = Float64Index(-arr)
885+
expected = NumericIndex(-arr, dtype=np.float64)
890886
a = np.zeros(5, dtype="float64")
891887
result = a - fidx
892888
tm.assert_index_equal(result, expected)

pandas/tests/indexes/conftest.py

Lines changed: 20 additions & 0 deletions
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+
"datetime64[ns]",
49+
"category",
50+
"object",
51+
"timedelta64[ns]",
52+
]
53+
)
54+
def any_numpy_dtype_for_small_integer_indexes(request):
55+
"""
56+
Dtypes that can be given to an Index with small 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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
date_range,
1616
)
1717
import pandas._testing as tm
18-
from pandas.core.api import (
19-
Int64Index,
20-
UInt64Index,
21-
)
2218

2319

2420
class TestDatetimeIndex:
@@ -33,7 +29,7 @@ def test_astype(self):
3329
tm.assert_index_equal(result, expected)
3430

3531
result = idx.astype(np.int64)
36-
expected = Int64Index(
32+
expected = Index(
3733
[1463356800000000000] + [-9223372036854775808] * 3,
3834
dtype=np.int64,
3935
name="idx",
@@ -47,7 +43,7 @@ def test_astype(self):
4743

4844
def test_astype_uint(self):
4945
arr = date_range("2000", periods=2, name="idx")
50-
expected = UInt64Index(
46+
expected = Index(
5147
np.array([946684800000000000, 946771200000000000], dtype="uint64"),
5248
name="idx",
5349
)

pandas/tests/indexes/datetimes/test_scalar_compat.py

Lines changed: 5 additions & 6 deletions
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:
@@ -313,33 +312,33 @@ def test_1700(self):
313312
dr = date_range(start=Timestamp("1710-10-01"), periods=5, freq="D")
314313
r1 = pd.Index([x.to_julian_date() for x in dr])
315314
r2 = dr.to_julian_date()
316-
assert isinstance(r2, Float64Index)
315+
assert isinstance(r2, pd.Index) and r2.dtype == np.float64
317316
tm.assert_index_equal(r1, r2)
318317

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

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

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

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

pandas/tests/indexes/datetimes/test_setops.py

Lines changed: 1 addition & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818
timedelta_range,
1919
)
2020
import pandas._testing as tm
21-
from pandas.core.api import (
22-
Float64Index,
23-
NumericIndex,
24-
)
21+
from pandas.core.api import NumericIndex
2522
import pandas.core.common as com
2623

2724

@@ -409,7 +406,7 @@ def test_maybe_convert_i8_nat(self, breaks):
409406
index = IntervalIndex.from_breaks(breaks)
410407

411408
to_convert = breaks._constructor([pd.NaT] * 3)
412-
expected = Float64Index([np.nan] * 3)
409+
expected = Index([np.nan] * 3, dtype=np.float64)
413410
result = index._maybe_convert_i8(to_convert)
414411
tm.assert_index_equal(result, expected)
415412

pandas/tests/indexes/multi/test_analytics.py

Lines changed: 2 additions & 3 deletions
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

0 commit comments

Comments
 (0)