Skip to content

GH677 Allow pd.RangeIndex to be initialized with range #1005

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 2 commits into from
Sep 22, 2024
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
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
Loading