-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
ENH: groupby missing data in index #28097
Changes from all commits
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 |
---|---|---|
|
@@ -628,6 +628,24 @@ def test_groupby_empty(self): | |
# check name | ||
assert s.groupby(s).grouper.names == ["name"] | ||
|
||
def test_groupby_level_index_value_all_na(self): | ||
# issue 20519 | ||
df = DataFrame( | ||
[["x", np.nan, 10], [None, np.nan, 20]], columns=["A", "B", "C"] | ||
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. If I cast side-note, I'd find this easier to follow in smaller steps:
Especially relevant as it is the 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. @jbrockmendel 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.
Yes, I meant to write
Huh, not sure how I got to a different error. My bad. |
||
).set_index(["A", "B"]) | ||
result = df.groupby(level=["A", "B"]).sum() | ||
expected = DataFrame( | ||
WillAyd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data=[], | ||
index=MultiIndex( | ||
levels=[Index(["x"], dtype="object"), Index([], dtype="float64")], | ||
codes=[[], []], | ||
names=["A", "B"], | ||
), | ||
columns=["C"], | ||
dtype="int64", | ||
) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
# get_group | ||
# -------------------------------- | ||
|
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.
hmm, can you eliminate the branch, and just always pass
fill_value=True
?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.
If remove the branch, for example,
raise exception.
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.
actually i think this is incorrect
@WillAyd wasn’t done here
this branch can be simplified i think
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.
Sorry misread the approval above
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.
@proost do you mind simplifying this in a follow up PR?