-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Changes from 1 commit
03450d9
f0b1f98
6d6d1fb
988ff30
1fb9751
98d70f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
import pandas as pd | ||
from pandas import DataFrame, Index, MultiIndex, Series | ||
import pandas._testing as tm | ||
from pandas.core.indexing import IndexingError | ||
|
@@ -279,3 +280,32 @@ def test_loc_empty_multiindex(): | |
result = df | ||
expected = DataFrame([1, 2, 3, 4], index=index, columns=["value"]) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize("nan", [np.nan, pd.NA, None]) | ||
def test_loc_nan_multiindex(nan): | ||
# GH#29751 | ||
# tests to check loc on a multiindex containing nan values | ||
arr = [ | ||
[11, nan, 13], | ||
[21, nan, 23], | ||
[31, nan, 33], | ||
[41, nan, 43], | ||
[51, nan, 53], | ||
] | ||
cols = ["a", "b", "c"] | ||
df = DataFrame(arr, columns=cols, dtype="int").set_index(["a", "b"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use dtype='int64' to avoid the 32-bit failures There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed dtype to int64 in the recent commit |
||
idx = df.index[1] | ||
result = df.loc[:idx, :] | ||
expected = DataFrame(arr[:2], columns=cols, dtype="int").set_index(["a", "b"]) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
result = df.loc[idx:, :] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you try to parametrize with slices? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have parametrized the slices in the recent commit |
||
expected = DataFrame(arr[1:], columns=cols).set_index(["a", "b"]) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
idx1 = df.index[1] | ||
idx2 = df.index[3] | ||
result = df.loc[idx1:idx2, :] | ||
expected = DataFrame(arr[1:4], columns=cols).set_index(["a", "b"]) | ||
tm.assert_frame_equal(result, expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a fixture for all NaNs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nulls_fixture
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the test case to use nulls_fixture in the most recent commit