oemof / oemof-solph

A model generator for energy system modelling and optimisation (LP/MILP).
https://oemof.org
MIT License
282 stars 124 forks source link

Using `custom_attributes` of `Source` and `Sink` classes fails #1059

Closed richartkeil closed 4 months ago

richartkeil commented 4 months ago

Currently, using custom_attributes of Source and Sink classes will lead to an exception. A similar issue was addressed in #1032, but the fix did not cover these classes. #929 Seems also to be related to this.

If there isn't more to it, I'll create a PR for a fix.

Reproduction

Setup fresh venv, run only pip install oemof-solph to get the following dependencies:

blinker==1.7.0
dill==0.3.8
networkx==3.2.1
numpy==1.26.4
oemof.network==0.5.0
oemof.solph==0.5.2
oemof.tools==0.4.3
pandas==2.2.1
ply==3.11
Pyomo==6.7.1
python-dateutil==2.9.0
pytz==2024.1
six==1.16.0
tzdata==2024.1

Run the following script:

from oemof.solph import components

components.Source(custom_attributes={"foo": "bar"})
components.Sink(custom_attributes={"foo": "bar"})

Get the exception:

Traceback (most recent call last):
  File "/Users/richartkeil/.../bug.py", line 3, in <module>
    components.Sink(custom_attributes={"foo": "bar"})
  File "/Users/richartkeil/.../.venv/lib/python3.12/site-packages/oemof/solph/components/_sink.py", line 66, in __init__
    super().__init__(label=label, inputs=inputs, **custom_attributes)
TypeError: Node.__init__() got an unexpected keyword argument 'foo'

(same for _source.py)

p-snft commented 4 months ago

Thanks for implementing this. (To be explicit for the others: The custom_attributes of nodes were never doing anything.)