Skip to content

Commit 80bf796

Browse files
mikofskiwholmgren
authored andcommitted
BUG: fix klucher nan output for numpy (#509)
* BUG: fix klucher nan output for numpy * fixes #508 * use `F = np.where(np.isnan(F), 0, F) to only replace `nan` with zero * previously if numpy array with nan, then entire array was zeroed so output differed from pandas series input * update klucker tests * the original test had the bug in it, because floats don't have `fillna` attribute, **but** that doesn't mean that the value was `NaN`! * instead of hard-coding the expected value, what we really expect is that it should produce the same value as the pandas series result * also compare the pandas series result to a numpy array of the same * DOC: MAINT: update what's new
1 parent 2498040 commit 80bf796

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

docs/sphinx/source/whatsnew/v0.6.0.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ Bug fixes
5959
Location.get_clearsky. Fixed. (:issue:`481`)
6060
* Add User-Agent specification to TMY3 remote requests to avoid rejection.
6161
(:issue:`493`)
62-
62+
* Fix ``pvlib.irradiance.klucher`` output is different for Pandas Series vs.
63+
floats and NumPy arrays. (:issue:`508`)
6364

6465
Documentation
6566
~~~~~~~~~~~~~

pvlib/irradiance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ def klucher(surface_tilt, surface_azimuth, dhi, ghi, solar_zenith,
629629
# fails with single point input
630630
F.fillna(0, inplace=True)
631631
except AttributeError:
632-
F = 0
632+
F = np.where(np.isnan(F), 0, F)
633633

634634
term1 = 0.5 * (1 + tools.cosd(surface_tilt))
635635
term2 = 1 + F * (tools.sind(0.5 * surface_tilt) ** 3)

pvlib/test/test_irradiance.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,33 @@ def test_isotropic_series():
114114

115115

116116
def test_klucher_series_float():
117-
result = irradiance.klucher(40, 180, 100, 900, 20, 180)
118-
assert_allclose(result, 88.3022221559)
117+
# klucher inputs
118+
surface_tilt, surface_azimuth = 40.0, 180.0
119+
dhi, ghi = 100.0, 900.0
120+
solar_zenith, solar_azimuth = 20.0, 180.0
121+
# expect same result for floats and pd.Series
122+
expected = irradiance.klucher(
123+
surface_tilt, surface_azimuth,
124+
pd.Series(dhi), pd.Series(ghi),
125+
pd.Series(solar_zenith), pd.Series(solar_azimuth)
126+
) # 94.99429931664851
127+
result = irradiance.klucher(
128+
surface_tilt, surface_azimuth, dhi, ghi, solar_zenith, solar_azimuth
129+
)
130+
assert_allclose(result, expected[0])
119131

120132

121133
def test_klucher_series():
122134
result = irradiance.klucher(40, 180, irrad_data['dhi'], irrad_data['ghi'],
123135
ephem_data['apparent_zenith'],
124136
ephem_data['azimuth'])
125137
assert_allclose(result, [0, 37.446276, 109.209347, 56.965916], atol=1e-4)
138+
# expect same result for np.array and pd.Series
139+
expected = irradiance.klucher(
140+
40, 180, irrad_data['dhi'].values, irrad_data['ghi'].values,
141+
ephem_data['apparent_zenith'].values, ephem_data['azimuth'].values
142+
)
143+
assert_allclose(result, expected, atol=1e-4)
126144

127145

128146
def test_haydavies():

0 commit comments

Comments
 (0)