Skip to content
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

Merged
merged 6 commits into from
Jul 31, 2024
Merged

Pandas warnings fixes #1089

merged 6 commits into from
Jul 31, 2024

Conversation

uvchik
Copy link
Member

@uvchik uvchik commented Jul 3, 2024

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 the FutureWarning

@uvchik
Copy link
Member Author

uvchik commented Jul 3, 2024

My IDE complains if the docstring is not correct. I know, this should be a different PR. Please forgive my laziness 😄

@uvchik uvchik added this to the v0.5.x milestone Jul 3, 2024
@uvchik
Copy link
Member Author

uvchik commented Jul 3, 2024

Somehow the values for the OffsetConverter are build differently so one test fails with my changes. I could not find the reason.

FAILED tests/test_components/test_offset_converter.py::test_OffsetConverter_05x_compatibility - IndexError: index 1 is out of bounds for axis 0 with size 1

Copy link
Member

@p-snft p-snft left a 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:

  1. Cast to numpy.array when it is really needed.
  2. 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)
Copy link
Member

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.
Comment on lines -289 to 291
slope = sequence(slope[0])
offset = sequence(offset[0])
slope = slope[0]
offset = offset[0]

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

@p-snft p-snft left a 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.

@p-snft p-snft merged commit c2d44e4 into dev Jul 31, 2024
14 checks passed
@p-snft p-snft deleted the pandas-warnings-fixes branch July 31, 2024 12:13
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants