Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,7 @@ def __setattr__(self, key, value):
super().__setattr__(key, value)

def __repr__(self):
# once per MC
mc_attrs = ['weather', 'solar_position', 'airmass', 'tracking', 'aoi',
'aoi_modifier', 'total_irrad', 'spectral_modifier',
'effective_irradiance', 'cell_temperature', 'diode_params',
'dc', 'dc_ohmic_losses', 'losses', 'ac']
mc_attrs = dir(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using dir sorts the list of attributes alphabetically instead of conceptually. Not necessarily a downside.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, once I saw the alphabetized list my thought was "that's easier to use"


def _head(obj):
try:
Expand All @@ -433,12 +429,12 @@ def _head(obj):
desc1 = ('=== ModelChainResult === \n')
desc2 = (f'Number of Arrays: {num_arrays} \n')
attr = 'times'
desc3 = ('Times (first 3)\n' +
desc3 = ('times (first 3)\n' +
f'{_head(_getmcattr(self, attr))}' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f'{_head(_getmcattr(self, attr))}' +
f'{self.times[:3]}' +

Seems like this should be fine as long as it's safe to assume self.times is a DatetimeIndex

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't work if times is a DatetimeStamp. Maybe that can't happen, idk.

'\n')
lines = []
for attr in mc_attrs:
if hasattr(self, attr):
if not (attr.startswith('_') or attr=='times'):
lines.append(f' {attr}: ' + _mcr_repr(getattr(self, attr)))
desc4 = '\n'.join(lines)
return (desc1 + desc2 + desc3 + desc4)
Expand Down
37 changes: 37 additions & 0 deletions pvlib/tests/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2063,3 +2063,40 @@ def test__irrad_for_celltemp():
assert len(poa) == 2
assert_series_equal(poa[0], effect_irrad)
assert_series_equal(poa[1], effect_irrad)


@pytest.mark.parametrize('strategy, strategy_str', [
('south_at_latitude_tilt', 'south_at_latitude_tilt'),
(None, 'None')]) # GitHub issue 352
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this test back. I think this decorator is no longer needed and can be deleted.

def test_ModelChain___repr__(sapm_dc_snl_ac_system, location, strategy,
strategy_str):

mc = ModelChain(sapm_dc_snl_ac_system, location,
name='my mc')

expected = '\n'.join([
'ModelChain: ',
' name: my mc',
' clearsky_model: ineichen',
' transposition_model: haydavies',
' solar_position_method: nrel_numpy',
' airmass_model: kastenyoung1989',
' dc_model: sapm',
' ac_model: sandia_inverter',
' aoi_model: sapm_aoi_loss',
' spectral_model: sapm_spectral_loss',
' temperature_model: sapm_temp',
' losses_model: no_extra_losses'
])

assert mc.__repr__() == expected


def test_ModelChainResult___repr__(sapm_dc_snl_ac_system, location, weather):
mc = ModelChain(sapm_dc_snl_ac_system, location)
mc.run_model(weather)
mcres = mc.results.__repr__()
mc_attrs = dir(mc.results)
mc_attrs = [a for a in mc_attrs if not a.startswith('_')]
assert all([a in mcres for a in mc_attrs])