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
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 14 additions & 3 deletions src/oemof/solph/_plumbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from collections import abc
from itertools import repeat

import numpy as np


def sequence(iterable_or_scalar):
"""Tests if an object is iterable (except string) or scalar and returns
Expand All @@ -27,8 +29,17 @@ def sequence(iterable_or_scalar):

Examples
--------
>>> sequence([1,2])
[1, 2]
>>> y = sequence([1,2,3,4,5,6,7,8,9,10,11])
>>> y[0]
1

>>> y[10]
11

>>> import pandas as pd
>>> s1 = sequence(pd.Series([1,5,9]))
>>> s1[2]
9

>>> x = sequence(10)
>>> x[0]
Expand All @@ -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

else:
return _Sequence(default=iterable_or_scalar)

Expand Down
8 changes: 4 additions & 4 deletions src/oemof/solph/components/_offset_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,12 @@ def normed_offset_and_conversion_factors_from_coefficients(
c0, c1 = slope_offset_from_nonconvex_output(
flow.max[i], flow.min[i], eta_at_max, eta_at_min
)
slope += [c0]
offset += [c1]
slope.append(c0)
offset.append(c1)

if max_len == 1:
slope = sequence(slope[0])
offset = sequence(offset[0])
slope = slope[0]
offset = offset[0]

Comment on lines -289 to 291
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.

conversion_factors = {input_bus: slope}
normed_offsets = {input_bus: offset}
Expand Down
2 changes: 1 addition & 1 deletion src/oemof/solph/components/_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Sink(Node):

Parameters
----------
label : str
label : str or tuple
String holding the label of the Sink object.
The label of each object must be unique.

Expand Down
2 changes: 1 addition & 1 deletion src/oemof/solph/components/_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Source(Node):

Parameters
----------
label : str
label : str or tuple
String holding the label of the Source object.
The label of each object must be unique.

Expand Down
Loading