Skip to content

Commit 640cea1

Browse files
Terji Petersentopper-123
Terji Petersen
authored andcommitted
remove Int/Uint/Float64Index from pandas/tests/indexing & pandas/tests/series
1 parent 0b3bc92 commit 640cea1

26 files changed

+165
-167
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,
@@ -124,7 +123,6 @@
124123
ABCDatetimeIndex,
125124
ABCMultiIndex,
126125
ABCPeriodIndex,
127-
ABCRangeIndex,
128126
ABCSeries,
129127
ABCTimedeltaIndex,
130128
)

pandas/core/series.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@
132132
from pandas.core.indexes.accessors import CombinedDatetimelikeProperties
133133
from pandas.core.indexes.api import (
134134
DatetimeIndex,
135-
Float64Index,
136135
Index,
137136
MultiIndex,
138137
PeriodIndex,
@@ -2569,7 +2568,8 @@ def quantile(
25692568

25702569
if is_list_like(q):
25712570
result.name = self.name
2572-
return self._constructor(result, index=Float64Index(q), name=self.name)
2571+
idx = Index(q, dtype=np.float64)
2572+
return self._constructor(result, index=idx, name=self.name)
25732573
else:
25742574
# scalar
25752575
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(
@@ -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
@@ -901,19 +897,19 @@ def test_arithmetic_explicit_conversions(self):
901897

902898
# float conversions
903899
arr = np.arange(5, dtype="int64") * 3.2
904-
expected = Float64Index(arr)
900+
expected = NumericIndex(arr, dtype=np.float64)
905901
fidx = idx * 3.2
906902
tm.assert_index_equal(fidx, expected)
907903
fidx = 3.2 * idx
908904
tm.assert_index_equal(fidx, expected)
909905

910906
# interops with numpy arrays
911-
expected = Float64Index(arr)
907+
expected = NumericIndex(arr, dtype=np.float64)
912908
a = np.zeros(5, dtype="float64")
913909
result = fidx - a
914910
tm.assert_index_equal(result, expected)
915911

916-
expected = Float64Index(-arr)
912+
expected = NumericIndex(-arr, dtype=np.float64)
917913
a = np.zeros(5, dtype="float64")
918914
result = a - fidx
919915
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: 6 additions & 2 deletions
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",
@@ -44,6 +43,11 @@ def test_astype(self):
4443

4544
def test_astype_uint(self):
4645
arr = date_range("2000", periods=2, name="idx")
46+
expected = Index(
47+
np.array([946684800000000000, 946771200000000000], dtype="uint64"),
48+
name="idx",
49+
)
50+
tm.assert_index_equal(arr.astype("uint64"), expected)
4751

4852
with pytest.raises(TypeError, match=r"Do obj.astype\('int64'\)"):
4953
arr.astype("uint64")

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

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)