-
Notifications
You must be signed in to change notification settings - Fork 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
Numpy 2.0 compatibility #2027
Numpy 2.0 compatibility #2027
Conversation
AttributeError: `np.Inf` was removed in the NumPy 2.0 release. Use `np.inf` instead.
AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead.
OverflowError: Python integer 450 out of bounds for uint8
DeprecationWarning: `trapz` is deprecated. Use `trapezoid` instead, or one of the numerical integration functions in `scipy.integrate`.
Thumbs up here. We probably used np.trapz when scipy was optional. |
* change `np.Inf` to `np.inf` AttributeError: `np.Inf` was removed in the NumPy 2.0 release. Use `np.inf` instead. * change `np.NaN` to `np.nan` AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead. * fix np.uint8 range issue OverflowError: Python integer 450 out of bounds for uint8 * use `scipy.integrate.trapezoid` instead of `np.trapz` DeprecationWarning: `trapz` is deprecated. Use `trapezoid` instead, or one of the numerical integration functions in `scipy.integrate`. * advance minimum scipy from 1.5 to 1.6 for integrate.trapezoid * whatsnew PR number
Using https://github.com/pvlib/pvlib-python/releases/tag/v0.11.1, I just got to update NumPy to version 2.0.2 for a prototype project that also uses pvlib. And I got : ..
import pvlib
File "/.venv/lib/python3.11/site-packages/pvlib/__init__.py", line 3, in <module>
from pvlib import ( # noqa: F401
File "/.venv/lib/python3.11/site-packages/pvlib/clearsky.py", line 13, in <module>
import h5py
File "/.venv/lib/python3.11/site-packages/h5py/__init__.py", line 25, in <module>
from . import _errors
File "h5py/_errors.pyx", line 1, in init h5py._errors
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject Is this new ? |
Hi @NikosAlexandris , can you post which versions are you using and the full traceback? My first suspicion is a problem with the h5py version, maybe you can try to update it. |
I depend currently, I realised, on NumPy 1.6.5 and need to upgrade soonish. So I reverted back to it for now. But I think h5py was indeed the problem in first place (then NumPy < 2 was my second blocker). If I get back to this problem, I'll report back here. |
@NikosAlexandris feel free to chat with us through the mailing list or open a new issue whenever you need. I heavily recommend reporting the full environment details so we can help:
Remember, it's difficult to diagnose software problems without the full details, and not providing them may discourage people from helping you. |
[ ] Updates entries indocs/sphinx/source/reference
for API changes.docs/sphinx/source/whatsnew
for all changes. Includes link to the GitHub Issue with:issue:`num`
or this Pull Request with:pull:`num`
. Includes contributor name and/or GitHub username (link with:ghuser:`user`
).[ ] New code is fully documented. Includes numpydoc compliant docstrings, examples, and comments where necessary.remote-data
) and Milestone are assigned to the Pull Request and linked Issue.The necessary changes are all minor:
np.NaN
tonp.nan
np.Inf
tonp.inf
np.uint8
casting issuescipy.integrate.trapezoid
instead ofnp.trapz
The last item is only to address a deprecation warning: numpy 2.0 deprecated
np.trapz
in favor of eithernp.trapezoid
orscipy.integrate.trapezoid
. To avoid the small code cruft of usingtry/except
for importing from numpy (to support bothtrapz
for numpy < 2 andtrapezoid
for numpy >= 2), I opted to use the scipy function. That required increasing our minimum version from 1.5 to 1.6.