Skip to content

GH1285 Allow range in pd.MultiIndex.from_product #1296

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 1 commit into from
Jul 28, 2025
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
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/multi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MultiIndex(Index):
@classmethod
def from_product(
cls,
iterables: Sequence[SequenceNotStr[Hashable] | pd.Series | pd.Index],
iterables: Sequence[SequenceNotStr[Hashable] | pd.Series | pd.Index | range],
sortorder: int | None = ...,
names: SequenceNotStr[Hashable] = ...,
) -> Self: ...
Expand Down
13 changes: 13 additions & 0 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1384,3 +1384,16 @@ def test_index_infer_objects() -> None:
df = pd.DataFrame({"A": ["a", 1, 2, 3]})
idx = df.set_index("A").index[1:]
check(assert_type(idx.infer_objects(), pd.Index), pd.Index)


def test_multiindex_range() -> None:
"""Test using range in `MultiIndex.from_product` GH1285."""
midx = pd.MultiIndex.from_product(
[range(3), range(5)],
)
check(assert_type(midx, pd.MultiIndex), pd.MultiIndex)

midx_mixed_types = pd.MultiIndex.from_product(
[range(3), pd.Series([2, 3, 5])],
)
check(assert_type(midx_mixed_types, pd.MultiIndex), pd.MultiIndex)
Loading