Repository navigation
BUG: fix compatibility with numpy 2.0 copy semantics - #16142
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
Whoops, the whole CI just broke with TypeError: unsupported operand type(s) for *: 'Unit' and 'float'Incidentally, this is the "other error" that I saw as I tested against numpy dev locally, but I didn't realise that it was actually caused by this patch. So the good news is that we probably have only one problem to solve here ! The bad news is that it's worth than I thought. |
72b5086 to
217a906
Compare
This was an unintended regression in |
|
Thanks for jumping in @rgommers ! As for the TypeError VS warning, it doesn't make a difference on our side since warnings are treated as errors in CI, and in both case it's very useful information. Still, a warning would indeed be nicer for end users. Any way, thank you for all your work on numpy 2 ! |
d5bc025 to
aa7214e
Compare
mhvk
left a comment
There was a problem hiding this comment.
Thanks! Looking through the changes,I think two things would simplify this:
- I think we should define
COPY_IF_NEEDED = False if NUMPY_LT_2_0 else Noneinnumpycompatand just import that. - The
__array__implementations can all havecopy=COPY_IF_NEEDEDas an argument, independent of numpy version.
| """ | ||
| Array representation of the kernel. | ||
| """ | ||
| return self._array |
There was a problem hiding this comment.
Separately, I'm actually not sure this implementation is correct, I think it should be return self._array.astype(dtype=dtype, copy=copy) but then the default would have to be False (which I think is fine).
There was a problem hiding this comment.
I've added this to my personal TODO list and will make sure to address it in a follow up PR. Thanks !
I'll note that that is pretty much exactly what we did in SciPy: scipy/scipy#20172. Looks pretty clean that way. |
|
Thanks @mhvk ! Right now I'm trying to eliminate any regressions seen in CI but I'll get to your suggestions next ! |
|
One regression to go before refactoring. Not sure I'll have time to finish this today but I should see the end of it tomorrow. |
fdbf75c to
cf59a18
Compare
|
I'm not done refactoring, but I'm going to leave this in a functioning state for today. |
958a22f to
7b23323
Compare
Sure! It is looking good - just continue to use |
7061621 to
4f137de
Compare
|
@mhvk I will only have very limited access to a keyboard (possibly none) until Wednesday so feel free to change this bit. |
|
OK, will push up changes (they turn out to be minimal, thankfully), and then try to get this in. Thanks for all of this - it was non-trivial! |
mhvk
left a comment
There was a problem hiding this comment.
Approving. Since this now introduces no API changes at all, i.e., just accounts for the change in np.array in numpy 2.0, I'll go ahead and approve and set ready to merge. @neutrinoceros will open a new issue/PR with plans for how to do this going forward.
|
Are you sure you want to auto-merge? numpy-dev job is not required to pass before it kicks in. UPDATE: devdeps failed -- I disabled it. |
|
Hmm... Is this related? |
df9ab49 to
6068539
Compare
|
Yay, devdeps is green again! Merging... |
This comment was marked as resolved.
This comment was marked as resolved.
Backport PR #16142: BUG: fix compatibility with numpy 2.0 copy semantics
Description
This adresses an new incompatibility with numpy dev:
np.array(..., copy=False)now raises aValueErrorif a copy cannot be avoided. The suggested replacement, implemented in scikit-learn by the author of the breaking change, is to usenp.asarray(...)instead, which will only create a copy if necessary, as desired.xref numpy/numpy#25168
Note that this doesn't fix devdeps by itself: there's also an upstream issue in pyerfa,~ and another incompat with
Unitthat I'll need to bisect, and which I think can be addressed separately.~update: turns out this other incompatibility was an artifact of my first attempt at this patch, not an actual issue.