Skip to content

Commit 21dfb77

Browse files
GH1285 Allow range in pd.MultiIndex.from_product (#1296)
1 parent 4f0c41d commit 21dfb77

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pandas-stubs/core/indexes/multi.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class MultiIndex(Index):
5757
@classmethod
5858
def from_product(
5959
cls,
60-
iterables: Sequence[SequenceNotStr[Hashable] | pd.Series | pd.Index],
60+
iterables: Sequence[SequenceNotStr[Hashable] | pd.Series | pd.Index | range],
6161
sortorder: int | None = ...,
6262
names: SequenceNotStr[Hashable] = ...,
6363
) -> Self: ...

tests/test_indexes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,3 +1384,16 @@ def test_index_infer_objects() -> None:
13841384
df = pd.DataFrame({"A": ["a", 1, 2, 3]})
13851385
idx = df.set_index("A").index[1:]
13861386
check(assert_type(idx.infer_objects(), pd.Index), pd.Index)
1387+
1388+
1389+
def test_multiindex_range() -> None:
1390+
"""Test using range in `MultiIndex.from_product` GH1285."""
1391+
midx = pd.MultiIndex.from_product(
1392+
[range(3), range(5)],
1393+
)
1394+
check(assert_type(midx, pd.MultiIndex), pd.MultiIndex)
1395+
1396+
midx_mixed_types = pd.MultiIndex.from_product(
1397+
[range(3), pd.Series([2, 3, 5])],
1398+
)
1399+
check(assert_type(midx_mixed_types, pd.MultiIndex), pd.MultiIndex)

0 commit comments

Comments
 (0)