IAMconsortium / pyam

Analysis & visualization of energy & climate scenarios
https://pyam-iamc.readthedocs.io/
Apache License 2.0
222 stars 116 forks source link

Filter by level does not work with multiple conditions #712

Open Rlamboll opened 1 year ago

Rlamboll commented 1 year ago

As far as I can work out, "df.filter(level=[1, 2])" always produces nothing, even when "df.filter(level=1)" and "df.filter(level=2)" produce reasonable values. I have been using workarounds so far, but at some point we should probably fix this!

danielhuppmann commented 1 year ago

The level argument is passed to https://github.com/IAMconsortium/pyam/blob/83b75423de26e3a322dcd1ea9c61069d234f4dc8/pyam/utils.py#L417

And the docstring of the function clearly states that it can be an int or a str (like 1+).

Fine for me to either extend the function or raise an explicit error.

Also, we should add level to the list of illegal column names in an IamDataFrame. Using an extra-column named level would cause unexpected behavior for the filter method.

https://github.com/IAMconsortium/pyam/blob/83b75423de26e3a322dcd1ea9c61069d234f4dc8/pyam/utils.py#L34