Skip to content

Commit a9a4ff4

Browse files
committed
TST: Added test case for Multiindex slicing with NaNs issue pandas-dev#25154
1 parent 2aadaa8 commit a9a4ff4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pandas/tests/indexing/multiindex/test_getitem.py

+20
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,26 @@ def test_frame_getitem_nan_multiindex(nulls_fixture):
231231
tm.assert_frame_equal(result, expected)
232232

233233

234+
def test_frame_getitem_nan_cols_multiindex(nulls_fixture):
235+
# Slicing MultiIndex including levels with nan values, for more information
236+
# see GH#25154
237+
data = [[1, 2, 3], [4, 5, 6]]
238+
index = ["First", nulls_fixture]
239+
columns = MultiIndex.from_tuples([("a", "foo"), ("b", "foo"), ("b", nulls_fixture)])
240+
df = DataFrame(data=data, columns=columns, index=index, dtype="int64")
241+
242+
# Slicing out 'b', ['foo', nan]
243+
cols = (["b"], ["foo", nulls_fixture])
244+
result = df.loc[:, cols]
245+
expected_columns = MultiIndex.from_tuples([("b", "foo"), ("b", nulls_fixture)])
246+
expected_index = ["First", nulls_fixture]
247+
expected = DataFrame(
248+
[[2, 3], [5, 6]], columns=expected_columns, index=expected_index, dtype="int64"
249+
)
250+
251+
tm.assert_frame_equal(result, expected)
252+
253+
234254
# ----------------------------------------------------------------------------
235255
# test indexing of DataFrame with multi-level Index with duplicates
236256
# ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)