Skip to content

Commit

Permalink
Simplify ScenarioInfo.yv_ya using DataFrame.query()
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Oct 30, 2023
1 parent 37b825d commit 90f3c37
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions message_ix_models/util/scenarioinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,13 @@ def from_url(cls, url: str) -> "ScenarioInfo":
def yv_ya(self):
""":class:`pandas.DataFrame` with valid ``year_vtg``, ``year_act`` pairs."""
if self._yv_ya is None:
first = self.y0

# Product of all years
yv = ya = self.set["year"]

# Predicate for filtering years
def _valid(elem):
yv, ya = elem
return first <= yv <= ya

# - Cartesian product of all yv and ya.
# - Filter only valid years.
# - Convert to data frame.
# - Filter only valid years.
self._yv_ya = pd.DataFrame(
filter(_valid, product(yv, ya)), columns=["year_vtg", "year_act"]
)
product(self.set["year"], self.set["year"]),
columns=["year_vtg", "year_act"],
).query("@self.y0 <= year_vtg <= year_act")

return self._yv_ya

Expand Down

0 comments on commit 90f3c37

Please sign in to comment.