diff --git a/docs/sphinx/source/whatsnew/v0.17.0.rst b/docs/sphinx/source/whatsnew/v0.17.0.rst new file mode 100644 index 0000000000..da4241bb9f --- /dev/null +++ b/docs/sphinx/source/whatsnew/v0.17.0.rst @@ -0,0 +1,46 @@ +.. _whatsnew_0_X_Y: + + +v0.X.Y (Month XX, 20YY) +----------------------- + +Breaking Changes +~~~~~~~~~~~~~~~~ +* ``ModelChain`` no longer fills NaN with 0 in DC power and AC power. + (:issue:`1409`, :pull:`2955`) + +Deprecations +~~~~~~~~~~~~ + + +Bug fixes +~~~~~~~~~ + + +Enhancements +~~~~~~~~~~~~ + + +Documentation +~~~~~~~~~~~~~ + + +Testing +~~~~~~~ + + +Benchmarking +~~~~~~~~~~~~ + + +Requirements +~~~~~~~~~~~~ + + +Maintenance +~~~~~~~~~~~ + + +Contributors +~~~~~~~~~~~~ +* Cliff Hansen (:ghuser:`cwhanse`) diff --git a/pvlib/modelchain.py b/pvlib/modelchain.py index d2112ac25a..0623efcc37 100644 --- a/pvlib/modelchain.py +++ b/pvlib/modelchain.py @@ -626,7 +626,6 @@ def _make_diode_params(photocurrent, saturation_current, self.results.dc, unwrap=False ) - self.results.dc = tuple(dc.fillna(0) for dc in self.results.dc) # If the system has one Array, unwrap the single return value # to preserve the original behavior of ModelChain if self.system.num_arrays == 1: @@ -726,8 +725,7 @@ def adr_inverter(self): return self def pvwatts_inverter(self): - ac = self.system.get_ac('pvwatts', self.results.dc) - self.results.ac = ac.fillna(0) + self.results.ac = self.system.get_ac('pvwatts', self.results.dc) return self @property diff --git a/tests/test_modelchain.py b/tests/test_modelchain.py index 6b443ac0fc..a12396cdd6 100644 --- a/tests/test_modelchain.py +++ b/tests/test_modelchain.py @@ -1282,6 +1282,40 @@ def test_singlediode_dc_arrays(location, dc_model, assert isinstance(dc, (pd.Series, pd.DataFrame)) +@pytest.mark.parametrize('case', ['cec_dc', 'pvwatts_ac']) +def test_nan_policy(location, case, cec_dc_snl_ac_arrays, + pvwatts_dc_pvwatts_ac_system_arrays): + times = pd.date_range('20160101 1200-0700', periods=2, freq='6h') + weather = pd.DataFrame({'ghi': [500, np.nan], + 'dni': [800, 0], 'dhi': [100, 0]}, + index=times) + temp_model_params = {'a': -3.40641, 'b': -0.0842075, 'deltaT': 3} + temp_model = 'sapm' + cases = {'cec_dc': cec_dc_snl_ac_arrays, + 'pvwatts_ac': pvwatts_dc_pvwatts_ac_system_arrays} + system = cases[case] + for array in system.arrays: + array.temperature_model_parameters = temp_model_params + mc = ModelChain(system, location, + aoi_model='no_loss', spectral_model='no_loss', + temperature_model=temp_model) + mc.run_model(weather) + assert isinstance(mc.results.dc, tuple) + assert len(mc.results.dc) == system.num_arrays + # check each array + for dc in mc.results.dc: + # ghi is NaN at 2nd time step, all DC outputs should be NaN + if isinstance(dc, pd.DataFrame): + assert (dc.iloc[1, :].isna()).all() + elif isinstance(dc, pd.Series): + assert np.isnan(dc.iloc[1]) + else: + assert False + assert isinstance(mc.results.ac, (pd.Series)) + # ghi is NaN at 2nd time step, AC output should be NaN + assert np.isnan(mc.results.ac.iloc[1]) + + @pytest.mark.parametrize('temp_model', [ 'sapm_temp', 'faiman_temp', 'pvsyst_temp', 'fuentes_temp', 'noct_sam_temp'])