Skip to content

Commit

Permalink
GH677 Allow pd.RangeIndex to be initialized with range (pandas-dev#1005)
Browse files Browse the repository at this point in the history
* GH677 Allow pd.RangeIndex to be initialized with range

* GH677 Remove pd.RangeIndex.__init__ to align with pandas code
  • Loading branch information
loicdiridollou authored Sep 22, 2024
1 parent ba99000 commit 1bc27e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 1 addition & 10 deletions pandas-stubs/core/indexes/range.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,13 @@ from pandas._typing import (
class RangeIndex(Index[int]):
def __new__(
cls,
start: int | RangeIndex = ...,
start: int | RangeIndex | range = ...,
stop: int = ...,
step: int = ...,
dtype=...,
copy: bool = ...,
name=...,
): ...
def __init__(
self,
start: int | RangeIndex = ...,
stop: int = ...,
step: int = ...,
dtype=...,
copy: bool = ...,
name=...,
) -> None: ...
@classmethod
def from_range(cls, data, name=..., dtype=...): ...
def __reduce__(self): ...
Expand Down
6 changes: 6 additions & 0 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,12 @@ def test_getitem() -> None:
check(assert_type(i0[[0, 2]], "pd.Index[str]"), pd.Index, str)


def test_range_index_range() -> None:
"""Test that pd.RangeIndex can be initialized from range."""
iri = pd.RangeIndex(range(5))
check(assert_type(iri, pd.RangeIndex), pd.RangeIndex, int)


def test_multiindex_dtypes():
# GH-597
mi = pd.MultiIndex.from_tuples([(1, 2.0), (2, 3.0)], names=["foo", "bar"])
Expand Down

0 comments on commit 1bc27e6

Please sign in to comment.