Skip to content

Conversation

@koskampt
Copy link

@koskampt koskampt commented Nov 23, 2025

…62501)

@koskampt koskampt requested a review from rhshadrach as a code owner November 23, 2025 15:13
Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Please always add tests. Does this also handle the tuple case on L667?

for name in names
)

elif any(isna(k) for k in self.indices.keys()):
Copy link
Member

Choose a reason for hiding this comment

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

This check is expensive - this function is only ever called currently with names a list of length 1, and the rest of the method is O(1) in terms of self.indices. It's called from the inner loop of DataFramGroupBy.fitler as we're iterating over each group. This seems avoidable.

I believe we could change this function to just accept a single name (rather than a list) and then have a special case:

if isna(name):
    return self.indices.get(np.nan, [])

names = (converter(name) for name in names)

return [self.indices.get(name, []) for name in names]
indices = {np.nan if isna(k) else k: v for k, v in self.indices.items()}
Copy link
Member

Choose a reason for hiding this comment

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

It seems better to do this on indices cached property directly, and only in the case where there is a NaN value with if not self.dropna and self.result_index.hasnans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Inconsistent behavior of Groupby with None values with filter

2 participants