Skip to content

Commit bc3a9c8

Browse files
authored
fix modelchain poa tests (pvlib#1052)
* fix modelchain poa tests * poa_data_keys to poa_keys
1 parent 766b0ca commit bc3a9c8

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

pvlib/modelchain.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@
2121
# keys that are used to detect input data and assign data to appropriate
2222
# ModelChain attribute
2323
# for ModelChain.weather
24-
WEATHER_KEYS = {'ghi', 'dhi', 'dni', 'wind_speed', 'temp_air',
25-
'precipitable_water'}
24+
WEATHER_KEYS = ('ghi', 'dhi', 'dni', 'wind_speed', 'temp_air',
25+
'precipitable_water')
2626

2727
# for ModelChain.total_irrad
28-
POA_DATA_KEYS = {'poa_global', 'poa_direct', 'poa_diffuse'}
28+
POA_KEYS = ('poa_global', 'poa_direct', 'poa_diffuse')
2929

3030
# Optional keys to communicate temperature data. If provided,
3131
# 'cell_temperature' overrides ModelChain.temperature_model and sets
3232
# ModelChain.cell_temperature to the data. If 'module_temperature' is provdied,
3333
# overrides ModelChain.temperature_model with
3434
# pvlib.temperature.sapm_celL_from_module
35-
TEMPERATURE_KEYS = {'module_temperature', 'cell_temperature'}
35+
TEMPERATURE_KEYS = ('module_temperature', 'cell_temperature')
3636

37-
DATA_KEYS = WEATHER_KEYS | POA_DATA_KEYS | TEMPERATURE_KEYS
37+
DATA_KEYS = WEATHER_KEYS + POA_KEYS + TEMPERATURE_KEYS
3838

3939
# these dictionaries contain the default configuration for following
4040
# established modeling sequences. They can be used in combination with
@@ -1090,7 +1090,7 @@ def _assign_weather(self, data):
10901090
return self
10911091

10921092
def _assign_total_irrad(self, data):
1093-
key_list = [k for k in POA_DATA_KEYS if k in data]
1093+
key_list = [k for k in POA_KEYS if k in data]
10941094
self.total_irrad = data[key_list].copy()
10951095
return self
10961096

pvlib/tests/test_modelchain.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ def weather():
181181
@pytest.fixture
182182
def total_irrad(weather):
183183
return pd.DataFrame({'poa_global': [800., 500.],
184-
'poa_diffuse': [300., 200.],
185-
'poa_direct': [500., 300.]}, index=weather.index)
184+
'poa_direct': [500., 300.],
185+
'poa_diffuse': [300., 200.]}, index=weather.index)
186186

187187

188188
def test_ModelChain_creation(sapm_dc_snl_ac_system, location):
@@ -336,21 +336,25 @@ def test_run_model_tracker(sapm_dc_snl_ac_system, location, weather, mocker):
336336

337337
def test__assign_total_irrad(sapm_dc_snl_ac_system, location, weather,
338338
total_irrad):
339-
weather[['poa_global', 'poa_diffuse', 'poa_direct']] = total_irrad
339+
data = pd.concat([weather, total_irrad], axis=1)
340340
mc = ModelChain(sapm_dc_snl_ac_system, location)
341-
mc._assign_total_irrad(weather)
342-
for k in modelchain.POA_DATA_KEYS:
343-
assert_series_equal(mc.total_irrad[k], total_irrad[k])
341+
mc._assign_total_irrad(data)
342+
assert_frame_equal(mc.total_irrad, total_irrad)
344343

345344

346345
def test_prepare_inputs_from_poa(sapm_dc_snl_ac_system, location,
347346
weather, total_irrad):
348-
data = weather.copy()
349-
data[['poa_global', 'poa_diffuse', 'poa_direct']] = total_irrad
347+
data = pd.concat([weather, total_irrad], axis=1)
350348
mc = ModelChain(sapm_dc_snl_ac_system, location)
351349
mc.prepare_inputs_from_poa(data)
350+
weather_expected = weather.copy()
351+
weather_expected['temp_air'] = 20
352+
weather_expected['wind_speed'] = 0
353+
# order as expected
354+
weather_expected = weather_expected[
355+
['ghi', 'dhi', 'dni', 'wind_speed', 'temp_air']]
352356
# weather attribute
353-
assert_frame_equal(mc.weather, weather)
357+
assert_frame_equal(mc.weather, weather_expected)
354358
# total_irrad attribute
355359
assert_frame_equal(mc.total_irrad, total_irrad)
356360

0 commit comments

Comments
 (0)