-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Improve lookup documentation #61471
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
base: main
Are you sure you want to change the base?
Improve lookup documentation #61471
Conversation
Add pd_lookup_het() and pd_lookup_hom()
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 for the PR! No strong opposition to having both functions, but the performance gain of the _het
version does not seem significant to me.
idx, cols = pd.factorize(df['col']) | ||
df.reindex(cols, axis=1).to_numpy()[np.arange(len(df)), idx] | ||
def pd_lookup_hom(df, row_labels, col_labels): | ||
rows = df.index.get_indexer(row_labels) |
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.
Can you add df = df.loc[:, sorted(set(col_labels))]
here.
result = values[flat_index] | ||
return result | ||
|
||
For homogeneous column types, it is fastest to skip column subsetting and go directly to numpy: |
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.
Nit: NumPy
|
||
.. ipython:: python | ||
For heterogeneous column types, we subset columns to avoid unnecessary numpy conversions: |
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.
NumPy again.
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.Follows from #61185
Examples available at https://colab.research.google.com/drive/1MGWX6JVJL5yHyK7BeEBPQAW4tLM3TZL9#scrollTo=DjWfk4i1SiOY