Skip to content

Commit dc207e2

Browse files
authored
REF: RangeIndex dont subclass Int64Index (#40717)
1 parent 105f7fa commit dc207e2

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

pandas/core/indexes/range.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from pandas.core.indexes.numeric import (
4747
Float64Index,
4848
Int64Index,
49+
NumericIndex,
4950
)
5051
from pandas.core.ops.common import unpack_zerodim_and_defer
5152

@@ -55,7 +56,7 @@
5556
_empty_range = range(0)
5657

5758

58-
class RangeIndex(Int64Index):
59+
class RangeIndex(NumericIndex):
5960
"""
6061
Immutable Index implementing a monotonic integer range.
6162
@@ -97,6 +98,7 @@ class RangeIndex(Int64Index):
9798

9899
_typ = "rangeindex"
99100
_engine_type = libindex.Int64Engine
101+
_can_hold_na = False
100102
_range: range
101103

102104
# --------------------------------------------------------------------
@@ -381,6 +383,10 @@ def __contains__(self, key: Any) -> bool:
381383
return False
382384
return key in self._range
383385

386+
@property
387+
def inferred_type(self) -> str:
388+
return "integer"
389+
384390
# --------------------------------------------------------------------
385391
# Indexing Methods
386392

pandas/io/feather_format.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def to_feather(
5656
# validate that we have only a default index
5757
# raise on anything else as we don't serialize the index
5858

59-
if not isinstance(df.index, Int64Index):
59+
if not isinstance(df.index, (Int64Index, RangeIndex)):
6060
typ = type(df.index)
6161
raise ValueError(
6262
f"feather does not support serializing {typ} "

pandas/tests/indexes/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def test_hasnans_isnans(self, index_flat):
516516
return
517517
elif isinstance(index, DatetimeIndexOpsMixin):
518518
values[1] = iNaT
519-
elif isinstance(index, (Int64Index, UInt64Index)):
519+
elif isinstance(index, (Int64Index, UInt64Index, RangeIndex)):
520520
return
521521
else:
522522
values[1] = np.nan
@@ -555,7 +555,7 @@ def test_fillna(self, index):
555555

556556
if isinstance(index, DatetimeIndexOpsMixin):
557557
values[1] = iNaT
558-
elif isinstance(index, (Int64Index, UInt64Index)):
558+
elif isinstance(index, (Int64Index, UInt64Index, RangeIndex)):
559559
return
560560
else:
561561
values[1] = np.nan

pandas/tests/indexes/test_numpy_compat.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Index,
1313
Int64Index,
1414
PeriodIndex,
15+
RangeIndex,
1516
TimedeltaIndex,
1617
UInt64Index,
1718
)
@@ -55,7 +56,7 @@ def test_numpy_ufuncs_basic(index, func):
5556
with tm.external_error_raised((TypeError, AttributeError)):
5657
with np.errstate(all="ignore"):
5758
func(index)
58-
elif isinstance(index, (Float64Index, Int64Index, UInt64Index)):
59+
elif isinstance(index, (Float64Index, Int64Index, UInt64Index, RangeIndex)):
5960
# coerces to float (e.g. np.sin)
6061
with np.errstate(all="ignore"):
6162
result = func(index)
@@ -104,7 +105,7 @@ def test_numpy_ufuncs_other(index, func, request):
104105
with tm.external_error_raised(TypeError):
105106
func(index)
106107

107-
elif isinstance(index, (Float64Index, Int64Index, UInt64Index)):
108+
elif isinstance(index, (Float64Index, Int64Index, UInt64Index, RangeIndex)):
108109
# Results in bool array
109110
result = func(index)
110111
assert isinstance(result, np.ndarray)

0 commit comments

Comments
 (0)