Skip to content

Commit 922cc96

Browse files
authored
Document and test np.nan handling in spectrum.average_photon_energy (#2426)
* docs: tentative wording * test: single+all nan (series+df) * insert blank line * fix test assert statement * fix tests * combine assert out1 lines * equal->is * Update v0.12.1.rst
1 parent 0812192 commit 922cc96

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Enhancements
1919
Documentation
2020
~~~~~~~~~~~~~
2121
* Add a supporting reference to :py:func:`pvlib.atmosphere.get_relative_airmass` (:issue:`2390`, :pull:`2424`)
22+
* Documented how `np.nan` values are handled by :py:func:`~pvlib.spectrum.average_photon_energy`
23+
(:issue:`2423`, :pull:`2426`)
2224

2325
Testing
2426
~~~~~~~
@@ -31,3 +33,4 @@ Maintenance
3133
Contributors
3234
~~~~~~~~~~~~
3335
* Cliff Hansen (:ghuser:`cwhanse`)
36+
* Rajiv Daxini (:ghuser:`RDaxini`)

pvlib/spectrum/irradiance.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def average_photon_energy(spectra):
138138
ape : numeric or pandas.Series
139139
Average Photon Energy [eV].
140140
Note: returns ``np.nan`` in the case of all-zero spectral irradiance
141-
input.
141+
input, or where one or more spectral irradiance values is
142+
``np.nan``.
142143
143144
Notes
144145
-----

tests/spectrum/test_irradiance.py

+21
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,24 @@ def test_average_photon_energy_zero_irr():
130130
expected_2 = np.nan
131131
assert_allclose(out_1, expected_1, atol=1e-3)
132132
assert_allclose(out_2, expected_2, atol=1e-3)
133+
134+
135+
def test_average_photon_energy_nan_irr():
136+
# test for handling NaN input
137+
138+
spectra_df_nan = spectrum.get_reference_spectra().T
139+
spectra_df_nan.loc["global", 315.0] = np.nan
140+
spectra_df_nan.loc['extraterrestrial', :] = np.nan
141+
142+
spectra_series_nan = spectrum.get_reference_spectra()['global']
143+
spectra_series_singlenan = spectra_series_nan.copy()
144+
spectra_series_singlenan.loc[315.0] = np.nan
145+
spectra_series_allnan = spectra_series_nan*np.nan
146+
147+
out1 = spectrum.average_photon_energy(spectra_df_nan)
148+
out2 = spectrum.average_photon_energy(spectra_series_singlenan)
149+
out3 = spectrum.average_photon_energy(spectra_series_allnan)
150+
151+
assert np.all(np.isnan(out1[['global', 'extraterrestrial']]))
152+
assert np.all(np.isnan(out2))
153+
assert np.all(np.isnan(out3))

0 commit comments

Comments
 (0)