Skip to content

Commit 83bfe46

Browse files
code sample for pandas-dev#47596
1 parent 2770b38 commit 83bfe46

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

bisect/47596.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# BUG: Inconsistent handling of dropping levels in MultiIndex when using IndexSlice #47596
2+
3+
import pandas as pd
4+
5+
print(pd.__version__)
6+
7+
idx = pd.IndexSlice
8+
df = pd.DataFrame(
9+
index=pd.MultiIndex.from_product([["A", "B"], range(2), ["a", "b"]]),
10+
columns=pd.MultiIndex.from_product([["a", "b"], range(2)]),
11+
)
12+
result = df.loc[idx["A", :, :]]
13+
print(result)
14+
15+
expected = pd.DataFrame(
16+
index=pd.MultiIndex.from_product([["A"], range(2), ["a", "b"]]),
17+
columns=pd.MultiIndex.from_product([["a", "b"], range(2)]),
18+
)
19+
pd.testing.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)