Skip to content

BUG: additional keys in groupby indices when NAs are present #38861

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 1, 2021

Conversation

rhshadrach
Copy link
Member

lib.indices_fast included logic to skip over null values (-1's), but did not include the case where the first index is null. Currently this function is only used in sorting.get_indexer_dict where the case of all null group_index is handled separately.

@rhshadrach rhshadrach added Bug Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate labels Dec 31, 2020
if labels[j] != -1:
break
else:
raise ValueError("cannot handle all null values")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, just return result no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do any tests hit this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, returning result is much better than raising. Currently no tests can possibly hit this because of short-circuit logic in get_indexer_dict (I changed the comment around it, see the diff), I merely added it to be defensive. Doesn't seem advantageous to remove the short-circuit logic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return of an empty dictionary is hit by several tests however.

@rhshadrach
Copy link
Member Author

@jreback thanks for the review; responses above.

start = 0
cur = labels[0]
for i in range(1, n):
# Start at the first non-null entry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess L891 is redundant now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but its fine

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is, thanks. Removed.

@jreback jreback added this to the 1.3 milestone Jan 1, 2021
@jreback jreback merged commit 160e3f3 into pandas-dev:master Jan 1, 2021
@jreback
Copy link
Contributor

jreback commented Jan 1, 2021

thanks @rhshadrach

@rhshadrach rhshadrach deleted the group_indices branch January 2, 2021 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

additional keys in groupby indices when NAs are present
2 participants