Skip to content

Commit

Permalink
Account for different index levels
Browse files Browse the repository at this point in the history
  • Loading branch information
coroa committed Jun 28, 2022
1 parent 9f4ad08 commit 3536803
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pyam/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1872,11 +1872,21 @@ def _apply_filters(self, level=None, **filters):

elif col == "index":
if not isinstance(values, pd.MultiIndex):
values = pd.MultiIndex.from_tuples(values)
values = pd.MultiIndex.from_tuples(values, names=self.index.names)
elif values.names == [None, None, None]:
values = values.rename(names=self.index.names)
elif not set(values.names).subset(self.index.names):
index_levels = ", ".join(self.index.names)
values_levels = ", ".join(values.names)
raise AttributeError(
f"Filtering by `index` with a MultiIndex object needs to have "
f"the IamDataFrame index levels {index_levels}, "
f"but has {values_levels}"
)
index = self._data.index
keep_col = index.droplevel(
index.names.difference(["model", "scenario"])
).isin(values)
keep_col = index.droplevel(index.names.difference(index.names)).isin(
values
)

elif col == "time_domain":
# fast-pass if `self` already has selected time-domain
Expand Down

0 comments on commit 3536803

Please sign in to comment.