-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
[CLN] More Misc Cleanups in _libs #22287
Conversation
pandas/_libs/lib.pyx
Outdated
@@ -647,7 +646,7 @@ def row_bool_subset(ndarray[float64_t, ndim=2] values, | |||
out[pos, j] = values[i, j] | |||
pos += 1 | |||
|
|||
return out | |||
return out.base # `.base` to access underlying np.ndarray |
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.
I know elsewhere we do np.asarray(<memoryview>)
- are those equivalent?
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.
Very close to equivalent. It's a bit roundabout.
Above out
is typed as a float64_t[:, :]
memoryview, but then instantiated with
out = np.empty((mask.sum(), k), dtype=np.float64)
In executing that line, cython creates the numpy array, then casts it as a memoryview out
, and attaches the original ndarray as out.base
. So out.base
is an attribute lookup to return an existing np.ndarray.
The performance penalty to np.asarray
must be tiny; it might be worth it to do it that way to avoid confusion.
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.
ahh yes, can we change these
Codecov Report
@@ Coverage Diff @@
## master #22287 +/- ##
=======================================
Coverage 92.05% 92.05%
=======================================
Files 169 169
Lines 50709 50709
=======================================
Hits 46679 46679
Misses 4030 4030
Continue to review full report at Codecov.
|
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.
looks fine. are you linting these? (obviously how you made some of the changes), is this thru an IDE? I know I have asked this a bunch of times.
No, just periodically reading through them. My vague plan for achieving linting is to get the code (at least some pyx modules) "close enough" to valid python to trick the linter. |
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.
if you'd fix the .base things, otherwise lgtm.
pandas/_libs/lib.pyx
Outdated
@@ -329,10 +329,10 @@ def fast_zip(list ndarrays): | |||
Py_INCREF(val) | |||
PyArray_ITER_NEXT(it) | |||
|
|||
return result | |||
return result.base # `.base` to access underlying np.ndarray |
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 change these in this PR
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.
Sure
Had to revert some edits to fix persistent ResourceWarning in one Travis environment. Will try to narrow down the culprit in the next pass. |
Ping (got “LGTM” a few days ago) |
thanks |
cpdef --> cdef in a few cases
modernize string formatting
modernize for loop syntax
Should be orthogonal to other outstanding PR(s)