-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
REF/PERF: deduplicate kth_smallest #40559
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
Conversation
pandas/core/algorithms.py
Outdated
@@ -1305,6 +1305,8 @@ def compute(self, method: str) -> Series: | |||
narr = len(arr) | |||
n = min(n, narr) | |||
|
|||
# arr passed into kth_smallest must be contiguous, which |
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.
use ascontiguousarray instead (or specify the ordering flag in copy)
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.
done
pandas/_libs/algos.pxd
Outdated
@@ -12,6 +12,48 @@ cdef inline Py_ssize_t swap(numeric *a, numeric *b) nogil: | |||
return 0 | |||
|
|||
|
|||
cdef inline numeric kth_smallest_c(numeric* arr, Py_ssize_t k, Py_ssize_t n) nogil: |
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.
why is the implementation in the pxd file?
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.
It's cimported from groupby.pyx
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.
that means that it needs to be declared in the pxd file, the actual implementation can be in the pyx file
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.
Oh got it I see what you mean will change
pandas/_libs/algos.pyx
Outdated
|
||
Parameters | ||
---------- | ||
arr: numeric* arr |
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.
trailing "arr" not needed?
space before the colon in Parameters section
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.
Done
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.
LGTM cc @jreback
@@ -64,6 +64,14 @@ cdef: | |||
float64_t NaN = <float64_t>np.NaN | |||
int64_t NPY_NAT = get_nat() | |||
|
|||
cdef enum TiebreakEnumType: |
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.
did you move this?
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.
it was in the pxd but didnt need to be
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.
Yep sorry it was an unrelated change
@mzeitlin11 any top-level user visible perf worth mentioning in the what's new? (e.g. nlargest / nsmallest) |
Based on the benchmark should speed up nlargest/nsmallest about 5-10%. Let me know if that's worth adding a whatsnew |
thanks @mzeitlin11 ok this was more of a refactor then. |
Ensuring a contiguous input seems to give about a 5-10% performance improvement on the existing benchmark
gil.ParallelKth