Repository: pvlib/pvanalytics
Pull request #211 (2024-06-25 14:17:54)

Numpy 2.0 compatibility
- ~[ ] Closes #xxx~
- [x] Added tests to cover all new or modified code.
- ~[ ] Clearly documented all new API functions with [PEP257](https://www.python.org/dev/peps/pep-0257/) and [numpydoc](https://numpydoc.readthedocs.io/en/latest/format.html) compliant docstrings.~
- ~[ ] Added new API functions to `docs/api.rst`.~
- ~[ ] Non-API functions clearly documented with docstrings or comments as necessary.~
- [x] Adds description and name entries in the appropriate "what's new" file 
      in [`docs/whatsnew`](https://github.com/pvlib/pvanalytics/tree/main/docs/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` ``).
- [x] Pull request is nearly complete and ready for detailed review.
- [x] Maintainer: Appropriate GitHub Labels and Milestone are assigned to the Pull Request and linked Issue.

This PR adds compatibility for numpy 2.0, requiring minor changes (just `NaN` and `Inf` capitalization) to both the code base and the test suite.  


Patch:
diff --git a/docs/whatsnew/0.2.1.rst b/docs/whatsnew/0.2.1.rst
index 094cf94..b54d3ae 100644
--- a/docs/whatsnew/0.2.1.rst
+++ b/docs/whatsnew/0.2.1.rst
@@ -6,6 +6,7 @@
 
 Enhancements
 ~~~~~~~~~~~~
+* Compatibility with numpy 2.0. (:pull:`211`)
 
 
 Bug Fixes
diff --git a/pvanalytics/quality/irradiance.py b/pvanalytics/quality/irradiance.py
index 7828ab1..c4b08fd 100644
--- a/pvanalytics/quality/irradiance.py
+++ b/pvanalytics/quality/irradiance.py
@@ -19,20 +19,20 @@ QCRAD_CONSISTENCY = {
     'ghi_ratio': {
         'low_zenith': {
             'zenith_bounds': [0.0, 75],
-            'ghi_bounds': [50, np.Inf],
+            'ghi_bounds': [50, np.inf],
             'ratio_bounds': [0.92, 1.08]},
         'high_zenith': {
             'zenith_bounds': [75, 93],
-            'ghi_bounds': [50, np.Inf],
+            'ghi_bounds': [50, np.inf],
             'ratio_bounds': [0.85, 1.15]}},
     'dhi_ratio': {
         'low_zenith': {
             'zenith_bounds': [0.0, 75],
-            'ghi_bounds': [50, np.Inf],
+            'ghi_bounds': [50, np.inf],
             'ratio_bounds': [0.0, 1.05]},
         'high_zenith': {
             'zenith_bounds': [75, 93],
-            'ghi_bounds': [50, np.Inf],
+            'ghi_bounds': [50, np.inf],
             'ratio_bounds': [0.0, 1.10]}}}
 
 
@@ -392,7 +392,7 @@ def clearsky_limits(measured, clearsky, csi_max=1.1):
     csi = pvlib.irradiance.clearsky_index(
         measured,
         clearsky,
-        max_clearsky_index=np.Inf
+        max_clearsky_index=np.inf
     )
     return quality.util.check_limits(
         csi, upper_bound=csi_max, inclusive_upper=True


Test patch:
diff --git a/pvanalytics/tests/quality/test_outliers.py b/pvanalytics/tests/quality/test_outliers.py
index cb52c26..3cc0d9d 100644
--- a/pvanalytics/tests/quality/test_outliers.py
+++ b/pvanalytics/tests/quality/test_outliers.py
@@ -45,21 +45,21 @@ def test_tukey_lower_criteria():
 
 
 def test_zscore_raise_nan_input():
-    data = pd.Series([1, 0, -1, 0, np.NaN, 1, -1, 10])
+    data = pd.Series([1, 0, -1, 0, np.nan, 1, -1, 10])
 
     with pytest.raises(ValueError):
         outliers.zscore(data, nan_policy='raise')
 
 
 def test_zscore_invalid_nan_policy():
-    data = pd.Series([1, 0, -1, 0, np.NaN, 1, -1, 10])
+    data = pd.Series([1, 0, -1, 0, np.nan, 1, -1, 10])
 
     with pytest.raises(ValueError):
         outliers.zscore(data, nan_policy='incorrect_str')
 
 
 def test_zscore_omit_nan_input():
-    data = pd.Series([1, 0, -1, 0, np.NaN, 1, -1, 10])
+    data = pd.Series([1, 0, -1, 0, np.nan, 1, -1, 10])
     assert_series_equal(
         pd.Series([False, False, False, False, False, False, False, True]),
         outliers.zscore(outliers.zscore(data, nan_policy='omit'))