-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
TYP: get_reverse_indexer, get_group_index_sorter #40476
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
TYP: get_reverse_indexer, get_group_index_sorter #40476
Conversation
|
any perf changes? |
might be some small gain on 32 bit, nothing on 64. |
pandas/core/indexes/base.py
Outdated
| new_codes = [lab[mask] for lab in new_codes] | ||
| left_indexer = left_indexer[mask] | ||
| # error: Value of type "Optional[ndarray]" is not indexable | ||
| left_indexer = left_indexer[mask] # type: ignore[index] |
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.
np.arange resolves to Any. https://github.com/numpy/numpy/blob/main/numpy/__init__.pyi
as a result left_indexer is not narrowed with left_indexer = np.arange(len(left), dtype=np.intp) (L4215 after merge master)
so I think in this case better to cast than add an ignore. (We have warn_redundant_casts = True in setup.cfg) so should be aware when the cast is no longer required)
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.
updated + green
| # missing values are placed first; drop them! | ||
| left_indexer = left_indexer[counts[0] :] | ||
| # error: Value of type "Optional[ndarray]" is not indexable | ||
| left_indexer = left_indexer[counts[0] :] # type: ignore[index] |
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.
you could maybe leave this one as a "fix later" ignore instead of a cast as we can fix ourselves by typing libalgos.groupsort_indexer (i.e. adding algos.pyi)
simonjayhawkins
left a comment
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.
Thanks @jbrockmendel for the updates
|
yeah will look a bit later |
nailing down all the "np.intp"s bit by little bit.
AFAICT we're not going to be able to annotate ndarrays with ndim/dtype any time soon. Might be worth looking into https://pypi.org/project/nptyping/