-
Notifications
You must be signed in to change notification settings - Fork 1.1k
ModelChainResult.__repr__ #1236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm not unhappy with the print of ModelChainResult here. The code is clumsy, because ModelChainResult doesn't hew to any standards for the type of each attribute (e.g., with 2 Arrays, the value can be None, a single float, or a tuple of something). Here's what the report looks like for a simple ModelChain (system with one Array). I'm "head"ing any Series or DataFrames. Any if you read this far, look at the name of the last Series for
|
@kandersolar your call if this is for v0.10 or later. |
I think using
Code for the above: def _mcr_repr(obj):
if isinstance(obj, tuple):
return "Tuple (" + ", ".join([_mcr_repr(o) for o in obj]) + ")"
if isinstance(obj, pd.DataFrame):
return "DataFrame ({} rows x {} columns)".format(*obj.shape)
if isinstance(obj, pd.Series):
return "Series (length {})".format(len(obj))
# scalar, None, other?
return repr(obj)
def __repr__(self):
lines = ['ModelChainResult:']
attrs = [
'weather', 'solar_position', 'airmass',
'tracking', 'aoi', 'aoi_modifier', 'total_irrad', 'spectral_modifier',
'effective_irradiance', 'cell_temperature', 'dc', 'dc_ohmic_losses', 'losses', 'ac'
]
for attr in attrs:
lines.append(f" {attr}: " + _mcr_repr(getattr(self, attr)))
return "\n".join(lines) |
I had three outcomes in mind:
So I'll drop the |
Code I'm using to display the report for different PVSystems
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth a test? We used to have a ModelChain.__repr__
test, but it looks like I incorrectly removed it in #1181, oops. We should probably bring that back.
desc2 = (f'Number of Arrays: {num_arrays} \n') | ||
attr = 'times' | ||
desc3 = ('Times (first 3)\n' + | ||
f'{_head(_getmcattr(self, attr))}' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
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.
I added the For the |
pvlib/tests/test_modelchain.py
Outdated
@pytest.mark.parametrize('strategy, strategy_str', [ | ||
('south_at_latitude_tilt', 'south_at_latitude_tilt'), | ||
(None, 'None')]) # GitHub issue 352 |
There was a problem hiding this comment.
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.
'aoi_modifier', 'total_irrad', 'spectral_modifier', | ||
'effective_irradiance', 'cell_temperature', 'diode_params', | ||
'dc', 'dc_ohmic_losses', 'losses', 'ac'] | ||
mc_attrs = dir(self) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"
Thanks @cwhanse! |
[ ] Tests addeddocs/sphinx/source/api.rst
for API changes.[ ] Adds description and name entries in the appropriate "what's new" file indocs/sphinx/source/whatsnew
for all changes. Includes link to the GitHub Issue with:issue:`num`
or this Pull Request with:pull:`num`
. Includes contributor name and/or GitHub username (link with:ghuser:`user`
).