Skip to content

Commit 0128477

Browse files
committed
Add test
1 parent 049a02d commit 0128477

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

pvlib/irradiance.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,11 +1513,14 @@ def poa_error(ghi):
15131513
full_output=True,
15141514
disp=False,
15151515
)
1516-
except ValueError:
1517-
# this occurs when poa_error has the same sign at both end points
1518-
ghi = np.nan
1519-
conv = False
1520-
niter = -1
1516+
except ValueError as e:
1517+
# this may occur because poa_error has the same sign at both end points
1518+
if "f(a) and f(b) must have different signs" in e.args:
1519+
ghi = np.nan
1520+
conv = False
1521+
niter = -1
1522+
else:
1523+
raise e
15211524
else:
15221525
ghi = result[0]
15231526
conv = result[1].converged

pvlib/tests/test_irradiance.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
from collections import OrderedDict
33
import warnings
4+
import re
45

56
import numpy as np
67
from numpy import array, nan
@@ -825,6 +826,16 @@ def test_ghi_from_poa_driesse():
825826
expected = [0, -1, 0]
826827
assert_allclose(expected, niter)
827828

829+
# test xtol propagation by producing an exception
830+
poa_global = pd.Series([20, 300, 1000], index=times)
831+
xtol = -3.14159 # negative value raises exception in scipy.optimize.bisect
832+
with pytest.raises(
833+
ValueError,
834+
match=re.escape("xtol too small (%g <= 0)" % xtol)):
835+
output = irradiance.ghi_from_poa_driesse_2023(
836+
surface_tilt, surface_azimuth, zenith, azimuth,
837+
poa_global, dni_extra=1366.1, xtol=xtol)
838+
828839

829840
def test_gti_dirint():
830841
times = pd.DatetimeIndex(

0 commit comments

Comments
 (0)