Skip to content

Commit 7ca344f

Browse files
committed
BUG: raise ValueError in dirint when use_delta_kt_prime=True and len(times)<2
1 parent b2f1050 commit 7ca344f

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

pvlib/irradiance.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,9 @@ def dirint(ghi, solar_zenith, times, pressure=101325., use_delta_kt_prime=True,
19831983
SERI/TR-215-3087, Golden, CO: Solar Energy Research Institute, 1987.
19841984
"""
19851985

1986+
if use_delta_kt_prime and len(times) < 2:
1987+
raise ValueError('The DIRINT model requires at least two times')
1988+
19861989
disc_out = disc(ghi, solar_zenith, times, pressure=pressure,
19871990
min_cos_zenith=min_cos_zenith, max_zenith=max_zenith)
19881991
airmass = disc_out['airmass']

tests/test_irradiance.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,6 @@ def test_dirindex_min_cos_zenith_max_zenith():
11421142

11431143
def test_dirint_array_inputs():
11441144
"""np.array and pd.Series inputs work correctly. GH #2751"""
1145-
# dirint requires >= 2 time points
11461145
times = pd.date_range('2023-06-21 10:00', periods=2, freq='h', tz='UTC')
11471146

11481147
# np.array input → should return pd.Series
@@ -1165,15 +1164,25 @@ def test_dirint_array_inputs():
11651164
assert isinstance(result2, pd.Series)
11661165
assert (result2 >= 0).all()
11671166

1168-
# single time point → ValueError regardless of use_delta_kt_prime
1167+
# single time point + use_delta_kt_prime=True → ValueError
11691168
times_single = pd.DatetimeIndex(['2023-06-21 12:00'], tz='UTC')
11701169
with pytest.raises(ValueError, match="requires at least two times"):
11711170
irradiance.dirint(
11721171
ghi=np.array([500.0]),
11731172
solar_zenith=np.array([45.0]),
1174-
times=times_single
1173+
times=times_single,
1174+
use_delta_kt_prime=True
11751175
)
11761176

1177+
# single time point + use_delta_kt_prime=False → no error
1178+
result3 = irradiance.dirint(
1179+
ghi=np.array([500.0]),
1180+
solar_zenith=np.array([45.0]),
1181+
times=times_single,
1182+
use_delta_kt_prime=False
1183+
)
1184+
assert isinstance(result3, pd.Series)
1185+
11771186

11781187
def test_dni():
11791188
ghi = pd.Series([90, 100, 100, 100, 100])

0 commit comments

Comments
 (0)