@@ -1049,8 +1049,8 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
10491049 DHI is zero, then DNI is also zero, otherwise a FloatingPointError is
10501050 raised due to a division of a nonzero (and not NaN) value by zero. It is
10511051 also expected that extraterrestrial irradiance is positive. If airmass
1052- is NaN, then the total and all components are zero if they should not
1053- otherwise be NaN.
1052+ is NaN, then the total and all components are zero if they should not
1053+ otherwise be NaN because DHI or DNI was NaN .
10541054
10551055 Warning
10561056 -------
@@ -1218,10 +1218,15 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
12181218 sky_diffuse = np .maximum (dhi * (term1 + term2 + term3 ), 0 )
12191219
12201220 # we've preserved the input type until now, so don't ruin it!
1221+ airmass_nan_idx = np .logical_and (
1222+ np .isnan (airmass ), np .logical_not (
1223+ np .logical_or (np .isnan (dhi ), np .isnan (dni ))
1224+ )
1225+ )
12211226 if isinstance (sky_diffuse , pd .Series ):
1222- sky_diffuse [np . isnan ( airmass ) ] = 0
1227+ sky_diffuse [airmass_nan_idx ] = 0
12231228 else :
1224- sky_diffuse = np .where (np . isnan ( airmass ) , 0 , sky_diffuse )
1229+ sky_diffuse = np .where (airmass_nan_idx , 0 , sky_diffuse )
12251230
12261231 if return_components :
12271232 diffuse_components = OrderedDict ()
0 commit comments