Skip to content

Commit

Permalink
Verify weather includes 'dhi' in ModelChain.prepare_inputs() (pvlib#1093
Browse files Browse the repository at this point in the history
)

* Verify `weather` include 'dhi' in ModelChain.prepare_inputs()

* Fix whitespace

* Add entry to whatsnew under Bug Fixes
  • Loading branch information
wfvining authored Nov 23, 2020
1 parent 11c356f commit 1024194
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/sphinx/source/whatsnew/v0.8.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Bug fixes
~~~~~~~~~
* Fix issue with :py:func:`pvlib.temperature.fuentes` with timezone-aware
inputs. (:issue:`1071`, :pull:`1072`)
* Raise ``ValueError`` from :py:meth:`pvlib.modelchain.ModelChain.prepare_inputs`
when input does not have a 'dhi' column. (:issue:`1092`, :pull:`1093`)

Testing
~~~~~~~
Expand All @@ -46,3 +48,4 @@ Contributors
* Siyan (Veronica) Guo (:ghuser:`veronicaguo`)
* Will Holmgren (:ghuser:`wholmgren`)
* Cliff Hansen (:ghuser:`cwhanse`)
* Will Vining (:ghuser:`wfvining`)
2 changes: 1 addition & 1 deletion pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ def prepare_inputs(self, weather):
ModelChain.complete_irradiance
"""

self._verify_df(weather, required=['ghi', 'dni', 'ghi'])
self._verify_df(weather, required=['ghi', 'dni', 'dhi'])
self._assign_weather(weather)

self.times = self.weather.index
Expand Down
10 changes: 10 additions & 0 deletions pvlib/tests/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ def test_prepare_inputs_no_irradiance(sapm_dc_snl_ac_system, location):
mc.prepare_inputs(weather)


@pytest.mark.parametrize("missing", ['dhi', 'ghi', 'dni'])
def test_prepare_inputs_missing_irrad_component(
sapm_dc_snl_ac_system, location, missing):
mc = ModelChain(sapm_dc_snl_ac_system, location)
weather = pd.DataFrame({'dhi': [1, 2], 'dni': [1, 2], 'ghi': [1, 2]})
weather.drop(columns=missing, inplace=True)
with pytest.raises(ValueError):
mc.prepare_inputs(weather)


def test_run_model_perez(sapm_dc_snl_ac_system, location):
mc = ModelChain(sapm_dc_snl_ac_system, location,
transposition_model='perez')
Expand Down

0 comments on commit 1024194

Please sign in to comment.