Skip to content
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 numpy 2 stuff #57668

Merged
merged 7 commits into from
Mar 2, 2024
Merged

CLN: More numpy 2 stuff #57668

merged 7 commits into from
Mar 2, 2024

Conversation

lithomas1
Copy link
Member

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

@lithomas1 lithomas1 requested a review from WillAyd as a code owner February 28, 2024 23:30
@lithomas1 lithomas1 added this to the 2.2.2 milestone Feb 28, 2024
@lithomas1 lithomas1 added Compat pandas objects compatability with Numpy or Python functions Clean labels Feb 28, 2024
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work

@@ -492,7 +490,7 @@ static int NpyArr_iterNextItem(JSOBJ obj, JSONTypeContext *tc) {
((PyObjectEncoder *)tc->encoder)->npyValue = npyarr->dataptr;
((PyObjectEncoder *)tc->encoder)->npyCtxtPassthru = npyarr;
} else {
GET_TC(tc)->itemValue = npyarr->getitem(npyarr->dataptr, npyarr->array);
GET_TC(tc)->itemValue = PyArray_GETITEM(npyarr->array, npyarr->dataptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failing build doesn't like the implicit conversion from a PyArrayObject* to a PyObject* . Should be able to type-check / cast to make the compiler happy

@@ -492,7 +490,8 @@ static int NpyArr_iterNextItem(JSOBJ obj, JSONTypeContext *tc) {
((PyObjectEncoder *)tc->encoder)->npyValue = npyarr->dataptr;
((PyObjectEncoder *)tc->encoder)->npyCtxtPassthru = npyarr;
} else {
GET_TC(tc)->itemValue = npyarr->getitem(npyarr->dataptr, npyarr->array);
GET_TC(tc)->itemValue =
PyArray_GETITEM((PyArrayObject *)npyarr->array, npyarr->dataptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would still prefer a type check before the cast - prevents strange bugs in case this ever gets refactored.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it already happens a couple lines above.

if (!PyArray_Check(npyarr->array)) {
PyErr_SetString(PyExc_TypeError,
"NpyArr_iterNextItem received a non-array object");
return 0;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case we should assign const PyArrayObject *arrayobj = (const PyArrayObject *)npyarr->array right after the type check and reference that here.

Generally want to minimize casting and keep it very localized to where the type check happens (historically we have not done a good job of this) Otherwise things are very liable to break when refactoring

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. didn't look through all failures but assume they are leap day issues. maybe worth waiting until tomorrow

@WillAyd
Copy link
Member

WillAyd commented Mar 2, 2024

I merged main thinking the CI failures would be gone by now but looks like they are still around. Happy to merge as is given I am fairly confident the failures are unrelated, but will leave it up to you

@lithomas1
Copy link
Member Author

Merging then, since numpy is blocked on this.

Thanks for the review!

@lithomas1 lithomas1 merged commit 1bf86a3 into pandas-dev:main Mar 2, 2024
44 of 47 checks passed
@lithomas1 lithomas1 deleted the np2 branch March 2, 2024 19:52
meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Mar 2, 2024
lithomas1 added a commit that referenced this pull request Mar 3, 2024
Backport PR #57668: CLN: More numpy 2 stuff

Co-authored-by: Thomas Li <47963215+lithomas1@users.noreply.github.com>
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
* CLN: More numpy 2 stuff

* More

* fix warning

* clean

---------

Co-authored-by: William Ayd <will_ayd@innobi.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Compat pandas objects compatability with Numpy or Python functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants