-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: Get rid of PyArray_GetCastFunc #56114
Conversation
9511c13
to
27afdde
Compare
27afdde
to
29df456
Compare
cc @seberg |
PyObject *scalarItem = PyArray_ToScalar(dataptr, labels); | ||
PyArray_CastScalarToCtype(scalarItem, &i8date, | ||
PyArray_DescrFromType(NPY_INT64)); | ||
Py_DECREF(scalarItem); |
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.
Here, you can just use:
memcpy(&i8date, dataptr, sizeof(i8data));
I think, since you know this is an int64, as datetimes are int64 (I am unsure about alignment, thus the memcpy).
Same below? (at last I would think so?)
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.
Wow, this is even easier, thanks!
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.
Actually, I just realized the cast function doesn't handle alignment, so even i8data = *(npy_int64 *)dataptr;
should work.
@@ -1532,7 +1521,6 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) { | |||
|
|||
PyArray_Descr *outcode = PyArray_DescrFromType(NPY_INT64); | |||
PyArray_CastScalarToCtype(obj, &longVal, outcode); | |||
Py_DECREF(outcode); |
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.
Just confirming this was also an intentional cleanup?
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.
No, this is an accident and shouldn't be included.
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 catch.
I wonder if we're leaking references to PyArray_Descr elsewhere than.
The numpy docs don't seem too clear about whether we're borrowing references or owning it.
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.
Ah, yeah the deleted code here used to leak them... One point is that array creation functions steal them, though.
Merging then, thanks for the help all. |
@meeseeksdev backport 2.1.x. |
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon! Remember to remove the If these instructions are inaccurate, feel free to suggest an improvement. |
* Backport PR #56114: CLN: Get rid of PyArray_GetCastFunc * fix bad indent? * remove more unintended changes
PyArray_GetCastFunc
#55996 (Replace xxxx with the GitHub issue number)doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.