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
Increase test coverage of solph.models module #549
Increase test coverage of solph.models module #549
Conversation
First thing to discuss in this context: At the moment a To leave the opportunity to create your own time increment I would add the possibility to pass it directly to the model, otherwise solph tries to get it from the ACTUAL VERSION: def __init__(self, energysystem, **kwargs):
super().__init__()
self.name = kwargs.get('name', type(self).__name__)
self.es = energysystem
try:
self.timeincrement = sequence(self.es.timeindex.freq.nanos / 3.6e12)
except AttributeError:
logging.warning(
'Could not get timeincrement from pd.DateTimeIndex! ' +
'To avoid this warning, make sure the `freq` attribute of ' +
'your timeindex is not None. Setting timeincrement to 1...')
self.timeincrement = sequence(1) MY PROPOSAL: def __init__(self, energysystem, **kwargs):
super().__init__()
self.name = kwargs.get('name', type(self).__name__)
self.es = energysystem
self.timeincrement = kwargs.get(timeincrement, None)
If self.timeincrement is None:
self.timeincrement = sequence(self.es.timeindex.freq.nanos / 3.6e12) The if block could also look like this to make it more clear for the user. If self.timeincrement is None:
try:
self.timeincrement = sequence(self.es.timeindex.freq.nanos / 3.6e12)
except AttributeError:
raise AttributeError(our_message) I stumbled over this issue while I was thinking about how to test these lines. |
As nobody commented the idea above I pushed a concrete proposal. If nobody objects I will merge. |
@oemof/oemof-solph See commit 2f6430 to review the changes on the time increment. |
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.
Will it still be possible to set a timeindex with length one?
Since v0.2.1 it is possible and since PR #519 it is tested. If all tests pass it is possible The cleanest way is the following:
Until now the following code also worked but I do not like it because it is hidden magic.
With commit fb316ca the default timeindex of an EnergySystem object is |
@simnh Do have any objections? May you approve this? |
There are some special conditions in this module and we should remove them or test them.
Furthermore
custom.py
is removed from the test coverage check, because we announced that it is not necessary to write tests for the custom components but we should warn users about this.