Skip to content

BUG: Added test cases to check loc on multiindex with NaNs #29751 #38772

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 6 commits into from
Jan 7, 2021
32 changes: 32 additions & 0 deletions pandas/tests/indexing/multiindex/test_getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,38 @@ def test_frame_mixed_depth_get():
tm.assert_series_equal(result, expected)


def test_frame_getitem_nan_multiindex(nulls_fixture):
# GH#29751
# loc on a multiindex containing nan values
n = nulls_fixture # for code readability
cols = ["a", "b", "c"]
df = DataFrame(
[[11, n, 13], [21, n, 23], [31, n, 33], [41, n, 43]],
columns=cols,
dtype="int64",
).set_index(["a", "b"])

idx = (21, n)
result = df.loc[:idx]
expected = DataFrame(
[[11, n, 13], [21, n, 23]], columns=cols, dtype="int64"
).set_index(["a", "b"])
tm.assert_frame_equal(result, expected)

result = df.loc[idx:]
expected = DataFrame(
[[21, n, 23], [31, n, 33], [41, n, 43]], columns=cols, dtype="int64"
).set_index(["a", "b"])
tm.assert_frame_equal(result, expected)

idx1, idx2 = (21, n), (31, n)
result = df.loc[idx1:idx2]
expected = DataFrame(
[[21, n, 23], [31, n, 33]], columns=cols, dtype="int64"
).set_index(["a", "b"])
tm.assert_frame_equal(result, expected)


# ----------------------------------------------------------------------------
# test indexing of DataFrame with multi-level Index with duplicates
# ----------------------------------------------------------------------------
Expand Down