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
Numpy 2.0 will "clean up" the Python API (and change the C API) #1864
Comments
The following builds against numpy 1 but runs with numpy 2 (development) and shows some immediate problem areas:
|
In doing this we will also need to worry about backend issues (I've just seen some in |
@hamogu - here's an interesting one (hopefully astropy will hit this and come up with a plan): the string output for np values has changed, so how can we doctest this as the expected output depends on the numpy version:
and this is a np change:
|
I suggest we start worrying about all of those when the numpy 2.0 RC is out Numpy plans to supply a conversion tool similar to 2to3 form the Python 2 to 3 conversion (though, they say, less sophisticated so it won't catch call cases, but to most of the automatic, tedious conversion); so it's probably a waste of time to do changes now that a script could quickly do for us later. It's also not as big a change as Python 2->3 was. Numpy wants to make sure that all 2.0 compatible code also runs with 1.x; they are mostly dropping aliases (e.g. The main reason to look a little closer at this now is if we do changes in how we call numpy in a way that impacts users now (e.g. #1735). In that case, we should make sure that we design it in such a way that it's numpy 2x compatible. However, for #1735 specifically, I did not see anything about dropping the numpy legacy API for random numbers, so it's not an issue there, but we should keep that in mind for other PRs. For the specific case of doctests that @DougBurke raised above, one simple solution would be to run the doctests only with one version of numpy (either 1.x or 2.0) and change them when we change that numpy version. In my mind, doctests don't have to be run with all version of our matrix. We want to make sure they work, but we don't want to break it for details of the print output, precisely because they can depend sensitively the version of Python and numpy. |
That's not to say that I'm opposed to relatively small PRs like #1876 that @DougBurke put in while I was typing the above; anything that we can easily tick off right now increases the chances that (most of) Sherpa might just work with numpy 2.0, but I don't think it's worth our effort to spend excessive amounts of time to fix issues like string output in doctests that won't directly impact user's codes. |
One issue with the "only run doctests with a fixed version of X, Y, and Z" idea is that that means the tests become useless on my laptop where I'm running with different versions. However, that's something to worry about another day. |
@hamogu - from numpy/numpy#24300 they say
You mentioned above that the RC wouldn't be out until January 2024, which is a rather less-aggressive schedule. |
I was wrong, I don't know how January 2024 popped into my head; I'll edit the post above to clarify that I'm wrong. |
We will run them on CI in whatever version we choose. On your laptop, you have 50% chance to be in either <2.0 or >2.0 and CI will check if somethings goes wrong. Except for some string output, numpy promises that 2.0 code also runs with older versions, so what I'll do is to develop predominantly with 2.0 once it's out. I'm hoping that we can get the doctests to 2.0 relatively soon after. But that's just my plan - your mileage might vary. |
Numpy plans a release candidate for numpy 2.0 late in Dec 2023 with significant clean-up of the Python API and changes to the C API:
numpy/numpy#24300
There is almost certainly something lurking in Sherpa that will break. So, we should a "numpy < 2.0" in our requirements for this year and then start testing against numpy 2.0 when it becomes available.
The text was updated successfully, but these errors were encountered: