-
Notifications
You must be signed in to change notification settings - Fork 125
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
Pandas warnings fixes #1089
Pandas warnings fixes #1089
Conversation
My IDE complains if the docstring is not correct. I know, this should be a different PR. Please forgive my laziness 😄 |
Somehow the values for the OffsetConverter are build differently so one test fails with my changes. I could not find the reason.
|
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.
I see that this feels like a quick fix, but unfortunately it is not. I see two options:
- Cast to numpy.array when it is really needed.
- Forbid sequences as arguments to sequences. (There might be further implications I do not see at the moment.)
@@ -43,7 +54,7 @@ def sequence(iterable_or_scalar): | |||
if isinstance(iterable_or_scalar, abc.Iterable) and not isinstance( | |||
iterable_or_scalar, str | |||
): | |||
return iterable_or_scalar | |||
return np.array(iterable_or_scalar) |
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.
There is a problem with this, as sequence
is used to create sequences of practically infinite length from scalar values. If you return a numpy.array instead, the following will happen:
# current implementation
s = sequence(sequence([5]))
s[0] = 5
s[5] = 5
# your suggestion
s = sequence(sequence([5]))
s[0] = 5
s[5] -> out of range
Note thatthis is just a workaround. chaned casts chould either work or be prohibited.
slope = sequence(slope[0]) | ||
offset = sequence(offset[0]) | ||
slope = slope[0] | ||
offset = offset[0] | ||
|
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.
Thank you for jumping in here @p-snft. I was actually wrapping my head around this sequence stuff the first time I saw it when implementing the changes for the OffsetConverter
and it took me quite a while to figure out what was going on. I see the practical point of the sequences, but I was wondering, if we could not just use scalars or numpy
arrays instead in general. Because if you (by accident) provide a half length sequence (with respect to the timeindex) you would end up with some kind of nonsense anyway, right? So why not let people either pass scalars or correct-length lists or arrays?
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.
The problem is that we do not know the correct length before the Entity is added to the EnergySystem. An option would be to just let scalar stay scalars until we need to have arrays.
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.
The problem with the sequence should be addressed in another PR. Adhering to the new Pandas API looks good.
A lot of inputs in solph can be single values or sequences.
Recently a
FutureWarning
from pandas warns that Series will not work in the future. A small change in our plumbing module will keep the old behaviour and avoid theFutureWarning