Skip to content

Decorator: Specify whether unchanged data should be returned or not #224

@euronion

Description

@euronion

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 the unchanged_data and the pd.concat([changed_data, unchanged_data]) in the end
  • In the decorator logic:
    a) we first create a copy of self.data and then call the function
    b) after the function has completed and before we return self inside the decorator, we concatenate the original self.data with the new self.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 object self.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 suitable subset=[...] of columns of the all_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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions