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

Numpy 2.0 compatibility #2027

Merged
merged 6 commits into from
May 1, 2024
Merged

Numpy 2.0 compatibility #2027

merged 6 commits into from
May 1, 2024

Conversation

kandersolar
Copy link
Member

  • Closes pvlib v0.10.4 is incompatible with numpy 2.0 #2026
  • I am familiar with the contributing guidelines
  • Tests added
  • [ ] Updates entries in docs/sphinx/source/reference for API changes.
  • Adds description and name entries in the appropriate "what's new" file in 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.
  • Pull request is nearly complete and ready for detailed review.
  • Maintainer: Appropriate GitHub Labels (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

The necessary changes are all minor:

  • Rename np.NaN to np.nan
  • Rename np.Inf to np.inf
  • Fix a small np.uint8 casting issue
  • Use scipy.integrate.trapezoid instead of np.trapz

The last item is only to address a deprecation warning: numpy 2.0 deprecated np.trapz in favor of either np.trapezoid or scipy.integrate.trapezoid. To avoid the small code cruft of using try/except for importing from numpy (to support both trapz for numpy < 2 and trapezoid for numpy >= 2), I opted to use the scipy function. That required increasing our minimum version from 1.5 to 1.6.

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`.
@kandersolar kandersolar added this to the v0.10.5 milestone Apr 30, 2024
@cwhanse
Copy link
Member

cwhanse commented Apr 30, 2024

Use scipy.integrate.trapezoid instead of np.trapz

Thumbs up here. We probably used np.trapz when scipy was optional.

@kandersolar kandersolar merged commit 8668a61 into pvlib:main May 1, 2024
33 of 35 checks passed
@kandersolar kandersolar deleted the numpy-2.0 branch May 1, 2024 11:20
echedey-ls pushed a commit to echedey-ls/pvlib-python that referenced this pull request May 22, 2024
* 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
@NikosAlexandris
Copy link

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 ?

@echedey-ls
Copy link
Contributor

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.

@NikosAlexandris
Copy link

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.

@echedey-ls
Copy link
Contributor

@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:

  • Operative System + version
  • Python interpreter version (python --version in command line)
  • Installed packages and versions (pip freeze in command line)
  • A minimal error-reproducible script just in case

Remember, it's difficult to diagnose software problems without the full details, and not providing them may discourage people from helping you.
Anyway, best of luck with your projects!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pvlib v0.10.4 is incompatible with numpy 2.0
4 participants