Skip to content

Commit bed018c

Browse files
authored
fix loc on MultiIndex with slice (#291)
* fix loc on mi with slice * remove tuple and slice as first part of tuple for loc.getitem
1 parent 60913c4 commit bed018c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,7 @@ class _LocIndexerFrame(_LocIndexer):
136136
| MaskType
137137
| list[HashableT]
138138
| tuple[
139-
IndexType
140-
| MaskType
141-
| slice
142-
| list[HashableT]
143-
| tuple[str | int | slice, ...],
139+
IndexType | MaskType | list[HashableT] | Hashable,
144140
list[HashableT] | slice | Series[bool] | Callable,
145141
],
146142
) -> DataFrame: ...

tests/test_frame.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,3 +1741,12 @@ def test_xs_key() -> None:
17411741
check(
17421742
assert_type(df.xs(0, level="foo"), Union[pd.DataFrame, pd.Series]), pd.DataFrame
17431743
)
1744+
1745+
1746+
def test_loc_slice() -> None:
1747+
# GH 277
1748+
df1 = pd.DataFrame(
1749+
{"x": [1, 2, 3, 4]},
1750+
index=pd.MultiIndex.from_product([[1, 2], ["a", "b"]], names=["num", "let"]),
1751+
)
1752+
check(assert_type(df1.loc[1, :], pd.DataFrame), pd.DataFrame)

0 commit comments

Comments
 (0)