-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Labels
Description
High level idea
This is an idea to potentially simplify a reoccurring pattern and harmonize the syntax of functions.
Description
The adjust_XYZ(...)
functions in technologies.py
generally return the changed data in combination with the unchanged data.
This needs to be manually implemented in each function.
Instead we could have a decorator that takes care of this.
Example
E.g.
- the decorator could be called
@keep_all_data
- we wrap
adjust_scale(..)
as
@keep_all_data
def adjust_scale(...)
adjust_scale(...)
works as it does until now, but we remove keeping track of theunchanged_data
and thepd.concat([changed_data, unchanged_data])
in the end- In the decorator logic:
a) we first create a copy ofself.data
and then call the function
b) after the function has completed and before we returnself
inside the decorator, we concatenate the originalself.data
with the newself.data
,all_self_data = pd.concat([self.data, original_self_data], ignore_index=True)
c) At the end of the decorator we assign the combined data to the objectself.data = all_self_data
.
Notes, ideas, potential issues
- This might create a situation that creates duplicate values, so we need to
drop_duplicates(...)
on a suitablesubset=[...]
of columns of theall_self_data
. This subset might need to be flexible? Could add a parameter to the decorator this. - Maybe someone wants to only get the new or modified values, not all values. This could be done by using the decorator to add a new function parameter to each decorated function. The parameter is consumed by the decorator and not passed to the function and changes the behaviour of the decorator.
- I like decorators, we should put them into
decorators.py
or so, definitely somewhere separate :)
Happy to hear your thoughts @finozzifa