Skip to content

REF: RangeIndex dont subclass Int64Index #40717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from pandas.core.indexes.numeric import (
Float64Index,
Int64Index,
NumericIndex,
)
from pandas.core.ops.common import unpack_zerodim_and_defer

Expand All @@ -55,7 +56,7 @@
_empty_range = range(0)


class RangeIndex(Int64Index):
class RangeIndex(NumericIndex):
"""
Immutable Index implementing a monotonic integer range.

Expand Down Expand Up @@ -97,6 +98,7 @@ class RangeIndex(Int64Index):

_typ = "rangeindex"
_engine_type = libindex.Int64Engine
_can_hold_na = False
_range: range

# --------------------------------------------------------------------
Expand Down Expand Up @@ -381,6 +383,10 @@ def __contains__(self, key: Any) -> bool:
return False
return key in self._range

@property
def inferred_type(self) -> str:
return "integer"

# --------------------------------------------------------------------
# Indexing Methods

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/feather_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def to_feather(
# validate that we have only a default index
# raise on anything else as we don't serialize the index

if not isinstance(df.index, Int64Index):
if not isinstance(df.index, (Int64Index, RangeIndex)):
typ = type(df.index)
raise ValueError(
f"feather does not support serializing {typ} "
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def test_hasnans_isnans(self, index_flat):
return
elif isinstance(index, DatetimeIndexOpsMixin):
values[1] = iNaT
elif isinstance(index, (Int64Index, UInt64Index)):
elif isinstance(index, (Int64Index, UInt64Index, RangeIndex)):
return
else:
values[1] = np.nan
Expand Down Expand Up @@ -555,7 +555,7 @@ def test_fillna(self, index):

if isinstance(index, DatetimeIndexOpsMixin):
values[1] = iNaT
elif isinstance(index, (Int64Index, UInt64Index)):
elif isinstance(index, (Int64Index, UInt64Index, RangeIndex)):
return
else:
values[1] = np.nan
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/indexes/test_numpy_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Index,
Int64Index,
PeriodIndex,
RangeIndex,
TimedeltaIndex,
UInt64Index,
)
Expand Down Expand Up @@ -55,7 +56,7 @@ def test_numpy_ufuncs_basic(index, func):
with tm.external_error_raised((TypeError, AttributeError)):
with np.errstate(all="ignore"):
func(index)
elif isinstance(index, (Float64Index, Int64Index, UInt64Index)):
elif isinstance(index, (Float64Index, Int64Index, UInt64Index, RangeIndex)):
# coerces to float (e.g. np.sin)
with np.errstate(all="ignore"):
result = func(index)
Expand Down Expand Up @@ -104,7 +105,7 @@ def test_numpy_ufuncs_other(index, func, request):
with tm.external_error_raised(TypeError):
func(index)

elif isinstance(index, (Float64Index, Int64Index, UInt64Index)):
elif isinstance(index, (Float64Index, Int64Index, UInt64Index, RangeIndex)):
# Results in bool array
result = func(index)
assert isinstance(result, np.ndarray)
Expand Down