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

improve error message in set_meta_from_data() #660

Open
gidden opened this issue May 16, 2022 · 0 comments
Open

improve error message in set_meta_from_data() #660

gidden opened this issue May 16, 2022 · 0 comments

Comments

@gidden
Copy link
Member

gidden commented May 16, 2022

A naive user (read: me) can obtain an obscure error message if set_meta_from_data() is used in an unintended way.

Take for example the regional SR15 dataframe. The following code will elicit the following error message:

df.set_meta_from_data(
    name='CO2 Emissions in 2050',
    variable='Emissions|CO2',
    year=2050,
)
...
File c:\users\gidden\work\iiasa\pyam\pyam\core.py:890, in IamDataFrame.set_meta_from_data(self, name, method, column, **kwargs)
    888 else:
    889     meta = _data.groupby(META_IDX)[column].apply(method)
--> 890 self.set_meta(meta, name)

File c:\users\gidden\work\iiasa\pyam\pyam\core.py:853, in IamDataFrame.set_meta(self, meta, name, index)
    851 # raise error if index is not unique
    852 if index.duplicated().any():
--> 853     raise ValueError("Non-unique ['model', 'scenario'] index!")
    855 # create pd.Series from meta, index and name if provided
    856 meta = pd.Series(data=meta, index=index, name=name)

ValueError: Non-unique ['model', 'scenario'] index!

The reason for this is that there is regional data as well, so indeed there are non-unique model/scenario indicies (by factor 6 in this case for 5 regions + world).

We could, e.g., tell a user that they have multiple entries in one of the non-sliced columns to improve this.

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

No branches or pull requests

1 participant