Skip to content

Commit a3a2129

Browse files
committed
remove Int/Uint/Float64Index from pandas/tests/indexes/ranges
1 parent 3f0af5e commit a3a2129

File tree

4 files changed

+70
-75
lines changed

4 files changed

+70
-75
lines changed

pandas/core/indexes/range.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import pandas.core.indexes.base as ibase
4949
from pandas.core.indexes.base import maybe_extract_name
5050
from pandas.core.indexes.numeric import (
51-
Float64Index,
5251
Int64Index,
5352
NumericIndex,
5453
)
@@ -386,7 +385,7 @@ def _shallow_copy(self, values, name: Hashable = no_default):
386385
name = self.name if name is no_default else name
387386

388387
if values.dtype.kind == "f":
389-
return Float64Index(values, name=name)
388+
return NumericIndex(values, name=name, dtype=np.float64)
390389
# GH 46675 & 43885: If values is equally spaced, return a
391390
# more memory-compact RangeIndex instead of Int64Index
392391
unique_diffs = unique_deltas(values)
@@ -395,7 +394,7 @@ def _shallow_copy(self, values, name: Hashable = no_default):
395394
new_range = range(values[0], values[-1] + diff, diff)
396395
return type(self)._simple_new(new_range, name=name)
397396
else:
398-
return Int64Index._simple_new(values, name=name)
397+
return NumericIndex._simple_new(values, name=name)
399398

400399
def _view(self: RangeIndex) -> RangeIndex:
401400
result = type(self)._simple_new(self._range, name=self._name)
@@ -848,7 +847,7 @@ def _concat(self, indexes: list[Index], name: Hashable) -> Index:
848847
# First non-empty index had only one element
849848
if rng.start == start:
850849
values = np.concatenate([x._values for x in rng_indexes])
851-
result = Int64Index(values)
850+
result = self._constructor(values)
852851
return result.rename(name)
853852

854853
step = rng.start - start
@@ -857,7 +856,9 @@ def _concat(self, indexes: list[Index], name: Hashable) -> Index:
857856
next_ is not None and rng.start != next_
858857
)
859858
if non_consecutive:
860-
result = Int64Index(np.concatenate([x._values for x in rng_indexes]))
859+
result = self._constructor(
860+
np.concatenate([x._values for x in rng_indexes])
861+
)
861862
return result.rename(name)
862863

863864
if step is not None:
@@ -905,7 +906,6 @@ def __getitem__(self, key):
905906
"and integer or boolean "
906907
"arrays are valid indices"
907908
)
908-
# fall back to Int64Index
909909
return super().__getitem__(key)
910910

911911
def _getitem_slice(self: RangeIndex, slobj: slice) -> RangeIndex:
@@ -1010,15 +1010,14 @@ def _arith_method(self, other, op):
10101010
res_name = ops.get_op_result_name(self, other)
10111011
result = type(self)(rstart, rstop, rstep, name=res_name)
10121012

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

10191019
return result
10201020

10211021
except (ValueError, TypeError, ZeroDivisionError):
1022-
# Defer to Int64Index implementation
10231022
# test_arithmetic_explicit_conversions
10241023
return super()._arith_method(other, op)

pandas/tests/indexes/ranges/test_join.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55
RangeIndex,
66
)
77
import pandas._testing as tm
8-
from pandas.core.indexes.api import Int64Index
98

109

1110
class TestJoin:
1211
def test_join_outer(self):
13-
# join with Int64Index
12+
# join with Index[int64]
1413
index = RangeIndex(start=0, stop=20, step=2)
15-
other = Int64Index(np.arange(25, 14, -1))
14+
other = Index(np.arange(25, 14, -1, dtype=np.int64))
1615

1716
res, lidx, ridx = index.join(other, how="outer", return_indexers=True)
1817
noidx_res = index.join(other, how="outer")
1918
tm.assert_index_equal(res, noidx_res)
2019

21-
eres = Int64Index(
20+
eres = Index(
2221
[0, 2, 4, 6, 8, 10, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
2322
)
2423
elidx = np.array(
@@ -30,9 +29,9 @@ def test_join_outer(self):
3029
dtype=np.intp,
3130
)
3231

33-
assert isinstance(res, Int64Index)
32+
assert isinstance(res, Index) and res.dtype == np.int64
3433
assert not isinstance(res, RangeIndex)
35-
tm.assert_index_equal(res, eres)
34+
tm.assert_index_equal(res, eres, exact=True)
3635
tm.assert_numpy_array_equal(lidx, elidx)
3736
tm.assert_numpy_array_equal(ridx, eridx)
3837

@@ -43,7 +42,7 @@ def test_join_outer(self):
4342
noidx_res = index.join(other, how="outer")
4443
tm.assert_index_equal(res, noidx_res)
4544

46-
assert isinstance(res, Int64Index)
45+
assert isinstance(res, Index) and res.dtype == np.int64
4746
assert not isinstance(res, RangeIndex)
4847
tm.assert_index_equal(res, eres)
4948
tm.assert_numpy_array_equal(lidx, elidx)
@@ -52,7 +51,7 @@ def test_join_outer(self):
5251
def test_join_inner(self):
5352
# Join with non-RangeIndex
5453
index = RangeIndex(start=0, stop=20, step=2)
55-
other = Int64Index(np.arange(25, 14, -1))
54+
other = Index(np.arange(25, 14, -1, dtype=np.int64))
5655

5756
res, lidx, ridx = index.join(other, how="inner", return_indexers=True)
5857

@@ -62,7 +61,7 @@ def test_join_inner(self):
6261
lidx = lidx.take(ind)
6362
ridx = ridx.take(ind)
6463

65-
eres = Int64Index([16, 18])
64+
eres = Index([16, 18])
6665
elidx = np.array([8, 9], dtype=np.intp)
6766
eridx = np.array([9, 7], dtype=np.intp)
6867

@@ -82,9 +81,9 @@ def test_join_inner(self):
8281
tm.assert_numpy_array_equal(ridx, eridx)
8382

8483
def test_join_left(self):
85-
# Join with Int64Index
84+
# Join with Index[int64]
8685
index = RangeIndex(start=0, stop=20, step=2)
87-
other = Int64Index(np.arange(25, 14, -1))
86+
other = Index(np.arange(25, 14, -1, dtype=np.int64))
8887

8988
res, lidx, ridx = index.join(other, how="left", return_indexers=True)
9089
eres = index
@@ -96,7 +95,7 @@ def test_join_left(self):
9695
tm.assert_numpy_array_equal(ridx, eridx)
9796

9897
# Join withRangeIndex
99-
other = Int64Index(np.arange(25, 14, -1))
98+
other = Index(np.arange(25, 14, -1, dtype=np.int64))
10099

101100
res, lidx, ridx = index.join(other, how="left", return_indexers=True)
102101

@@ -106,15 +105,15 @@ def test_join_left(self):
106105
tm.assert_numpy_array_equal(ridx, eridx)
107106

108107
def test_join_right(self):
109-
# Join with Int64Index
108+
# Join with Index[int64]
110109
index = RangeIndex(start=0, stop=20, step=2)
111-
other = Int64Index(np.arange(25, 14, -1))
110+
other = Index(np.arange(25, 14, -1, dtype=np.int64))
112111

113112
res, lidx, ridx = index.join(other, how="right", return_indexers=True)
114113
eres = other
115114
elidx = np.array([-1, -1, -1, -1, -1, -1, -1, 9, -1, 8, -1], dtype=np.intp)
116115

117-
assert isinstance(other, Int64Index)
116+
assert isinstance(other, Index) and other.dtype == np.int64
118117
tm.assert_index_equal(res, eres)
119118
tm.assert_numpy_array_equal(lidx, elidx)
120119
assert ridx is None
@@ -164,7 +163,7 @@ def test_join_non_unique(self):
164163

165164
res, lidx, ridx = index.join(other, return_indexers=True)
166165

167-
eres = Int64Index([0, 2, 4, 4, 6, 8, 10, 12, 14, 16, 18])
166+
eres = Index([0, 2, 4, 4, 6, 8, 10, 12, 14, 16, 18])
168167
elidx = np.array([0, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9], dtype=np.intp)
169168
eridx = np.array([-1, -1, 0, 1, -1, -1, -1, -1, -1, -1, -1], dtype=np.intp)
170169

pandas/tests/indexes/ranges/test_range.py

Lines changed: 11 additions & 16 deletions
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)