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

Metrics not to assume on pd.Series name #545

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MartinoMensio
Copy link
Contributor

Hey,
Thank you for the amazing features of this library. I found some limitations of the implemented metrics:

  • some of the metrics do not work if columns are named differently

I could rename columns before passing to the affected metrics, but it would be nicer if the functions don't rely on a column to be specifically named "load".

Example:

import pandas as pd
from openstef.metrics import metrics

df = pd.DataFrame(
    {
        "a_ground_truth": [1, 2, 3, 4],
        "a_forecast": [1.1, 2.1, 3.1, 4.1],
        "b_ground_truth": [1, 2, 3, 4],
        "b_forecast": [1.1, 2.1, 3.1, 4.1],
    }
)

a_r_mne_highest = metrics.r_mne_highest(df["a_ground_truth"], df["a_forecast"])
b_r_mne_highest = metrics.r_mne_highest(df["b_ground_truth"], df["b_forecast"])

print(a_r_mne_highest, b_r_mne_highest)

Trace of the exception:

Traceback (most recent call last):
  File "/home/martino/.cache/pypoetry/virtualenvs/load-forecasting-8OKFhNKY-py3.10/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 3805, in get_loc
    return self._engine.get_loc(casted_key)
  File "index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc
  File "index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/hashtable_class_helper.pxi", line 7081, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 7089, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'load'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/martino/code/energy-forecast/load-forecasting/example.py", line 13, in <module>
    a_r_mne_highest = metrics.r_mne_highest(df["a_ground_truth"], df["a_forecast"])
  File "/home/martino/.cache/pypoetry/virtualenvs/load-forecasting-8OKFhNKY-py3.10/lib/python3.10/site-packages/openstef/metrics/metrics.py", line 175, in r_mne_highest
    if (combined["load"].max() - combined["load"].min()) != 0
  File "/home/martino/.cache/pypoetry/virtualenvs/load-forecasting-8OKFhNKY-py3.10/lib/python3.10/site-packages/pandas/core/frame.py", line 4102, in __getitem__
    indexer = self.columns.get_loc(key)
  File "/home/martino/.cache/pypoetry/virtualenvs/load-forecasting-8OKFhNKY-py3.10/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc
    raise KeyError(key) from err
KeyError: 'load'

Signed-off-by: Martino Mensio <martino.mensio@tno.nl>
Signed-off-by: Clara De Smet <clara.de.smet@alliander.com>
@Jonasvdbo
Copy link
Contributor

@bartpleiter and @daanvanes, could you please provide an update on the status of this PR? It seems to have been open for quite some time now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants