-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
MAINT: Adjust the codebase to the new np.array
's copy
keyword meaning
#57172
Conversation
8df14c7
to
467f107
Compare
a80d828
to
f2e8246
Compare
If you have time could you investigate making |
f2e8246
to
3ae782d
Compare
numpy/numpy#25168 got merged today - once a new nightly build is published, all tests should pass now. |
3903437
to
6b28ead
Compare
NumPy nightly build disappeared (numpy/numpy#25907) but once it's back this PR should be ready. |
@mtsokol Please retrigger the CI given numpy/numpy#25907 (comment). |
32dcf9c
to
1a5ec4e
Compare
1a5ec4e
to
9f93fa4
Compare
Hi! I updated the PR with all required changes to be compatible with NumPy dev - now My question: There's a new |
Yes we would probably want to make use of it, but that can be done in a follow up |
Looks like there's some typing validations with the new addition of the keyword. Let me know if you'd like help with them: https://github.com/pandas-dev/pandas/actions/runs/8143484703/job/22255440584 |
These errors look pretty tricky. I guess it's due to the fact that this job installed NumPy 1.x where So for this PR, maybe
|
pandas/core/array_algos/quantile.py
Outdated
copy_false = None if np_version_gt2 else False | ||
result = np.array(result, copy=copy_false) |
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.
copy_false = None if np_version_gt2 else False | |
result = np.array(result, copy=copy_false) | |
result = np.asarray(result) |
Would this be a simpler but equivalent alternative?
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 like it (from a quick glance at the diff).
I just added this to the 2.0 migration guide:
- Code using
np.array(..., copy=False)
can in most cases be changed to
np.asarray(...)
. Older code tended to usenp.array
like this because
it had less overhead than the defaultnp.asarray
copy-if-needed
behavior. This is no longer true, andnp.asarray
is the preferred function.
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. |
Thanks @mtsokol. Will create a follow up issue about utilizing the new |
…s keyword meaning
…meaning (#57740) Co-authored-by: Mateusz Sokół <8431159+mtsokol@users.noreply.github.com>
…ning (pandas-dev#57172) * MAINT: Adjust the codebase to the new np.array copy keyword meaning * Add copy is docstring * Use asarray where possible --------- Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
Hi!
This PR addresses changes planned for NumPy in numpy/numpy#25168 (new
copy
keyword fornp.asarray
andnp.array
).np.array(..., copy=False)
will now throw and exception if a copy is needed. To retain the same behaviornp.asarray(...)
can be used, so a copy is made only when needed.I applied changes in a backward-compatible way, so that no NumPy version check & branching is needed.