Skip to content

Commit

Permalink
Warn about sequences that are too long
Browse files Browse the repository at this point in the history
  • Loading branch information
p-snft committed Aug 26, 2024
1 parent 71af2ba commit 32f9857
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/oemof/solph/_plumbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SPDX-License-Identifier: MIT
"""

import warnings
from collections import abc
from itertools import repeat

Expand Down Expand Up @@ -69,10 +69,20 @@ def valid_sequence(sequence, length: int) -> bool:
sequence.size = length
return True
if isinstance(sequence, np.ndarray):
if sequence.size >= length:
if sequence.size == length:
return True
# --- BEGIN: To be removed for versions >= v0.6 ---
elif sequence.size > length:
warnings.warn(
"Sequence longer than needed"
f" ({sequence.size} items instead of {length})."
" This will be trated as an error in the future.",
FutureWarning,
)
return True
# --- END ---
else:
raise ValueError(f"Lentgh of {sequence} should be {length}")
raise ValueError(f"Lentgh of {sequence} should be {length}.")

return False

Expand Down

0 comments on commit 32f9857

Please sign in to comment.