From 0128477e7e21feae530367db0792540e76521d4f Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sat, 10 Feb 2024 23:28:45 +0100 Subject: [PATCH] Add test --- pvlib/irradiance.py | 13 ++++++++----- pvlib/tests/test_irradiance.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index bf65b37680..7dfd356d04 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -1513,11 +1513,14 @@ def poa_error(ghi): full_output=True, disp=False, ) - except ValueError: - # this occurs when poa_error has the same sign at both end points - ghi = np.nan - conv = False - niter = -1 + except ValueError as e: + # this may occur because poa_error has the same sign at both end points + if "f(a) and f(b) must have different signs" in e.args: + ghi = np.nan + conv = False + niter = -1 + else: + raise e else: ghi = result[0] conv = result[1].converged diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 55fef490ba..fcb141b71a 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -1,6 +1,7 @@ import datetime from collections import OrderedDict import warnings +import re import numpy as np from numpy import array, nan @@ -825,6 +826,16 @@ def test_ghi_from_poa_driesse(): expected = [0, -1, 0] assert_allclose(expected, niter) + # test xtol propagation by producing an exception + poa_global = pd.Series([20, 300, 1000], index=times) + xtol = -3.14159 # negative value raises exception in scipy.optimize.bisect + with pytest.raises( + ValueError, + match=re.escape("xtol too small (%g <= 0)" % xtol)): + output = irradiance.ghi_from_poa_driesse_2023( + surface_tilt, surface_azimuth, zenith, azimuth, + poa_global, dni_extra=1366.1, xtol=xtol) + def test_gti_dirint(): times = pd.DatetimeIndex(