diff --git a/docs/sphinx/source/whatsnew/v0.8.1.rst b/docs/sphinx/source/whatsnew/v0.8.1.rst index 1a9fc75b73..4028e49f79 100644 --- a/docs/sphinx/source/whatsnew/v0.8.1.rst +++ b/docs/sphinx/source/whatsnew/v0.8.1.rst @@ -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 ~~~~~~~ @@ -46,3 +48,4 @@ Contributors * Siyan (Veronica) Guo (:ghuser:`veronicaguo`) * Will Holmgren (:ghuser:`wholmgren`) * Cliff Hansen (:ghuser:`cwhanse`) +* Will Vining (:ghuser:`wfvining`) diff --git a/pvlib/modelchain.py b/pvlib/modelchain.py index e5becc4a1a..5c9ad84b37 100644 --- a/pvlib/modelchain.py +++ b/pvlib/modelchain.py @@ -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 diff --git a/pvlib/tests/test_modelchain.py b/pvlib/tests/test_modelchain.py index d02611bbf3..61c7227979 100644 --- a/pvlib/tests/test_modelchain.py +++ b/pvlib/tests/test_modelchain.py @@ -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')