Skip to content

Commit bc7911e

Browse files
committed
remove Int/Uint/Float64Index from pandas/tests/indexes/ranges
1 parent e7e6be1 commit bc7911e

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

pandas/core/indexes/range.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ def _concat(self, indexes: list[Index], name: Hashable) -> Index:
848848
# First non-empty index had only one element
849849
if rng.start == start:
850850
values = np.concatenate([x._values for x in rng_indexes])
851-
result = Int64Index(values)
851+
result = self._constructor(values)
852852
return result.rename(name)
853853

854854
step = rng.start - start
@@ -857,7 +857,9 @@ def _concat(self, indexes: list[Index], name: Hashable) -> Index:
857857
next_ is not None and rng.start != next_
858858
)
859859
if non_consecutive:
860-
result = Int64Index(np.concatenate([x._values for x in rng_indexes]))
860+
result = self._constructor(
861+
np.concatenate([x._values for x in rng_indexes])
862+
)
861863
return result.rename(name)
862864

863865
if step is not None:
@@ -905,7 +907,6 @@ def __getitem__(self, key):
905907
"and integer or boolean "
906908
"arrays are valid indices"
907909
)
908-
# fall back to Int64Index
909910
return super().__getitem__(key)
910911

911912
def _getitem_slice(self: RangeIndex, slobj: slice) -> RangeIndex:
@@ -1010,15 +1011,14 @@ def _arith_method(self, other, op):
10101011
res_name = ops.get_op_result_name(self, other)
10111012
result = type(self)(rstart, rstop, rstep, name=res_name)
10121013

1013-
# for compat with numpy / Int64Index
1014+
# for compat with numpy / Index with int64 dtype
10141015
# even if we can represent as a RangeIndex, return
1015-
# as a Float64Index if we have float-like descriptors
1016+
# as a float64 Index if we have float-like descriptors
10161017
if not all(is_integer(x) for x in [rstart, rstop, rstep]):
10171018
result = result.astype("float64")
10181019

10191020
return result
10201021

10211022
except (ValueError, TypeError, ZeroDivisionError):
1022-
# Defer to Int64Index implementation
10231023
# test_arithmetic_explicit_conversions
10241024
return super()._arith_method(other, op)

pandas/tests/indexes/ranges/test_range.py

+11-16
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@
44
from pandas.core.dtypes.common import ensure_platform_int
55

66
import pandas as pd
7-
import pandas._testing as tm
8-
from pandas.core.indexes.api import (
9-
Float64Index,
7+
from pandas import (
108
Index,
11-
Int64Index,
129
RangeIndex,
1310
)
11+
import pandas._testing as tm
1412
from pandas.tests.indexes.common import NumericBase
1513

1614
# aliases to make some tests easier to read
1715
RI = RangeIndex
18-
I64 = Int64Index
19-
F64 = Float64Index
20-
OI = Index
2116

2217

2318
class TestRangeIndex(NumericBase):
@@ -111,7 +106,7 @@ def test_insert(self):
111106
tm.assert_index_equal(idx[0:4], result.insert(0, idx[0]), exact="equiv")
112107

113108
# GH 18295 (test missing)
114-
expected = Float64Index([0, np.nan, 1, 2, 3, 4])
109+
expected = Index([0, np.nan, 1, 2, 3, 4], dtype=np.float64)
115110
for na in [np.nan, None, pd.NA]:
116111
result = RangeIndex(5).insert(1, na)
117112
tm.assert_index_equal(result, expected)
@@ -379,7 +374,7 @@ def test_nbytes(self):
379374

380375
# memory savings vs int index
381376
idx = RangeIndex(0, 1000)
382-
assert idx.nbytes < Int64Index(idx._values).nbytes / 10
377+
assert idx.nbytes < Index(idx._values).nbytes / 10
383378

384379
# constant memory usage
385380
i2 = RangeIndex(0, 10)
@@ -530,16 +525,16 @@ def test_len_specialised(self, step):
530525
([RI(-4, -8), RI(-8, -12)], RI(0, 0)),
531526
([RI(-4, -8), RI(3, -4)], RI(0, 0)),
532527
([RI(-4, -8), RI(3, 5)], RI(3, 5)),
533-
([RI(-4, -2), RI(3, 5)], I64([-4, -3, 3, 4])),
528+
([RI(-4, -2), RI(3, 5)], Index([-4, -3, 3, 4])),
534529
([RI(-2), RI(3, 5)], RI(3, 5)),
535-
([RI(2), RI(2)], I64([0, 1, 0, 1])),
530+
([RI(2), RI(2)], Index([0, 1, 0, 1])),
536531
([RI(2), RI(2, 5), RI(5, 8, 4)], RI(0, 6)),
537-
([RI(2), RI(3, 5), RI(5, 8, 4)], I64([0, 1, 3, 4, 5])),
532+
([RI(2), RI(3, 5), RI(5, 8, 4)], Index([0, 1, 3, 4, 5])),
538533
([RI(-2, 2), RI(2, 5), RI(5, 8, 4)], RI(-2, 6)),
539-
([RI(3), OI([-1, 3, 15])], OI([0, 1, 2, -1, 3, 15])),
540-
([RI(3), OI([-1, 3.1, 15.0])], OI([0, 1, 2, -1, 3.1, 15.0])),
541-
([RI(3), OI(["a", None, 14])], OI([0, 1, 2, "a", None, 14])),
542-
([RI(3, 1), OI(["a", None, 14])], OI(["a", None, 14])),
534+
([RI(3), Index([-1, 3, 15])], Index([0, 1, 2, -1, 3, 15])),
535+
([RI(3), Index([-1, 3.1, 15.0])], Index([0, 1, 2, -1, 3.1, 15.0])),
536+
([RI(3), Index(["a", None, 14])], Index([0, 1, 2, "a", None, 14])),
537+
([RI(3, 1), Index(["a", None, 14])], Index(["a", None, 14])),
543538
]
544539
)
545540
def appends(self, request):

0 commit comments

Comments
 (0)