Skip to content

Commit 1024194

Browse files
authored
Verify weather includes 'dhi' in ModelChain.prepare_inputs() (#1093)
* Verify `weather` include 'dhi' in ModelChain.prepare_inputs() * Fix whitespace * Add entry to whatsnew under Bug Fixes
1 parent 11c356f commit 1024194

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Bug fixes
2424
~~~~~~~~~
2525
* Fix issue with :py:func:`pvlib.temperature.fuentes` with timezone-aware
2626
inputs. (:issue:`1071`, :pull:`1072`)
27+
* Raise ``ValueError`` from :py:meth:`pvlib.modelchain.ModelChain.prepare_inputs`
28+
when input does not have a 'dhi' column. (:issue:`1092`, :pull:`1093`)
2729

2830
Testing
2931
~~~~~~~
@@ -46,3 +48,4 @@ Contributors
4648
* Siyan (Veronica) Guo (:ghuser:`veronicaguo`)
4749
* Will Holmgren (:ghuser:`wholmgren`)
4850
* Cliff Hansen (:ghuser:`cwhanse`)
51+
* Will Vining (:ghuser:`wfvining`)

pvlib/modelchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ def prepare_inputs(self, weather):
11331133
ModelChain.complete_irradiance
11341134
"""
11351135

1136-
self._verify_df(weather, required=['ghi', 'dni', 'ghi'])
1136+
self._verify_df(weather, required=['ghi', 'dni', 'dhi'])
11371137
self._assign_weather(weather)
11381138

11391139
self.times = self.weather.index

pvlib/tests/test_modelchain.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ def test_prepare_inputs_no_irradiance(sapm_dc_snl_ac_system, location):
249249
mc.prepare_inputs(weather)
250250

251251

252+
@pytest.mark.parametrize("missing", ['dhi', 'ghi', 'dni'])
253+
def test_prepare_inputs_missing_irrad_component(
254+
sapm_dc_snl_ac_system, location, missing):
255+
mc = ModelChain(sapm_dc_snl_ac_system, location)
256+
weather = pd.DataFrame({'dhi': [1, 2], 'dni': [1, 2], 'ghi': [1, 2]})
257+
weather.drop(columns=missing, inplace=True)
258+
with pytest.raises(ValueError):
259+
mc.prepare_inputs(weather)
260+
261+
252262
def test_run_model_perez(sapm_dc_snl_ac_system, location):
253263
mc = ModelChain(sapm_dc_snl_ac_system, location,
254264
transposition_model='perez')

0 commit comments

Comments
 (0)