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
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
2 participants