Skip to content

Commit 1bc27e6

Browse files
GH677 Allow pd.RangeIndex to be initialized with range (#1005)
* GH677 Allow pd.RangeIndex to be initialized with range * GH677 Remove pd.RangeIndex.__init__ to align with pandas code
1 parent ba99000 commit 1bc27e6

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

pandas-stubs/core/indexes/range.pyi

+1-10
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,13 @@ from pandas._typing import (
1515
class RangeIndex(Index[int]):
1616
def __new__(
1717
cls,
18-
start: int | RangeIndex = ...,
18+
start: int | RangeIndex | range = ...,
1919
stop: int = ...,
2020
step: int = ...,
2121
dtype=...,
2222
copy: bool = ...,
2323
name=...,
2424
): ...
25-
def __init__(
26-
self,
27-
start: int | RangeIndex = ...,
28-
stop: int = ...,
29-
step: int = ...,
30-
dtype=...,
31-
copy: bool = ...,
32-
name=...,
33-
) -> None: ...
3425
@classmethod
3526
def from_range(cls, data, name=..., dtype=...): ...
3627
def __reduce__(self): ...

tests/test_indexes.py

+6
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,12 @@ def test_getitem() -> None:
912912
check(assert_type(i0[[0, 2]], "pd.Index[str]"), pd.Index, str)
913913

914914

915+
def test_range_index_range() -> None:
916+
"""Test that pd.RangeIndex can be initialized from range."""
917+
iri = pd.RangeIndex(range(5))
918+
check(assert_type(iri, pd.RangeIndex), pd.RangeIndex, int)
919+
920+
915921
def test_multiindex_dtypes():
916922
# GH-597
917923
mi = pd.MultiIndex.from_tuples([(1, 2.0), (2, 3.0)], names=["foo", "bar"])

0 commit comments

Comments
 (0)