-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Use take_1d in take_nd #40405
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
Use take_1d in take_nd #40405
Conversation
can remove comment in take_1d about being only for ArrayManager Update: ill just do this in one of my cleanup branches |
test failure is unrelated (and the flaky test is fixed on master). LGTM |
cool, does this allow refactor of other code? |
can this be moved out of Draft mode? |
@jorisvandenbossche gentle ping |
@jorisvandenbossche gentle ping to see if we can move this out of draft mode |
@jorisvandenbossche gentle ping |
Updated the PR. In [1]: from pandas.core.array_algos.take import take_1d, take_nd
In [2]: dtype = 'int'
...: m = 100
...: n = 1000
In [3]: values = np.arange(m * n)
In [4]: index = np.arange(m)
# this is not affected, just including as reference
In [5]: %timeit take_1d(values, index)
5.67 µs ± 27 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) <-- master
5.59 µs ± 50.6 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) <-- PR
In [6]: %timeit take_nd(values, index)
10.5 µs ± 104 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) <-- master
8.86 µs ± 68.3 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) <-- PR So it does give a small improvement, but when increasing the size of the array, the improvement almost completely disappears. |
3 lines for a 15% improvement for a fairly common case seems like a good deal to me |
@@ -89,6 +89,10 @@ def take_nd( | |||
if fill_value is lib.no_default: | |||
fill_value = na_value_for_dtype(arr.dtype, compat=False) | |||
|
|||
if arr.ndim == 1 and axis == 0 and indexer is not None: | |||
indexer = ensure_platform_int(indexer) |
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.
comment to the effect of "fastpath"
agree this can't hurt (and you know me about not liking special cases) |
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this. |
Thanks @jorisvandenbossche for the PR. closing as stale. re-open when ready. |
xref #40300 (comment)