-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Closes #36541 (BUG: ValueError: cannot convert float NaN to integer when resetting MultiIndex with NaT values) #36563
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 9 commits
d08c57c
92d06ad
c0bcc01
bb62589
cff1e4c
f012f88
47c6a29
316c28a
3c1d755
9d3644a
7127ebc
b00d2a1
9289b39
8e6ca6b
d72df80
07c8bdb
d224768
5e8cf6c
f301191
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
import pandas as pd | ||
from pandas import MultiIndex, Series | ||
import pandas._testing as tm | ||
|
||
|
||
def test_access_none_value_in_multiindex(): | ||
|
@@ -20,3 +21,13 @@ def test_access_none_value_in_multiindex(): | |
s = Series([1] * len(midx), dtype=object, index=midx) | ||
result = s.loc[("Level1", "Level2_a")] | ||
assert result == 1 | ||
|
||
|
||
def test_nat_multi_index(): | ||
# GH36541: that reset_index() does not raise ValueError | ||
ix = pd.MultiIndex.from_tuples([(pd.NaT, 1), (pd.NaT, 2)], names=["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. can you try this with one element a Timestamp (and one a NaT) can parameterize the test. 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. added test cases. please have another look and advise. |
||
result = pd.DataFrame({"x": [11, 12]}, index=ix) | ||
result = result.reset_index() | ||
|
||
expected = pd.DataFrame({"a": [pd.NaT, pd.NaT], "b": [1, 2], "x": [11, 12]}) | ||
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.
should be
dtype.kind in ['M', 'm']
(do the tests fail w/o this?)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.
no, they didn't before with "M" only (except for the ARM tests which I believe have an unrelated problem).
Trying with timedelta "m" now...