Skip to content

Commit

Permalink
Deprecate .util.iter_parameters()
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Nov 21, 2023
1 parent c7f139d commit de30f64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
3 changes: 2 additions & 1 deletion doc/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ What's new
Next release
============

- Deprecate :py:`iter_parameters()` in favour of :meth:`.Scenario.par_list` with :py:`indexed_by=...` argument from ixmp v3.8.0 (:pull:`137`).
- Add :mod:`message_ix_models.report.compat` :ref:`for emulating legacy reporting <report-legacy>` (:pull:`134`).

v2023.10.16
Expand Down Expand Up @@ -218,7 +219,7 @@ Earlier releases
---------

- Migrate :mod:`.model.bare`, :mod:`.model.build`, :mod:`.model.cli`, and associated documentation (:pull:`9`)
- Migrate utilities: :class:`.ScenarioInfo`, :func:`.add_par_data`, :func:`.eval_anno`, :func:`.iter_parameters`, and :func:`.strip_par_data`.
- Migrate utilities: :class:`.ScenarioInfo`, :func:`.add_par_data`, :func:`.eval_anno`, :py:`iter_parameters()`, and :func:`.strip_par_data`.

2021.3.3
--------
Expand Down
30 changes: 13 additions & 17 deletions message_ix_models/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import message_ix
import pandas as pd
import pint
from message_ix.models import MESSAGE_ITEMS

from ._convert_units import convert_units, series_of_pint_quantity
from .cache import cached
Expand Down Expand Up @@ -44,7 +43,6 @@
"eval_anno",
"ffill",
"identify_nodes",
"iter_parameters",
"load_package_data",
"load_private_data",
"local_data_path",
Expand Down Expand Up @@ -303,23 +301,21 @@ def _maybe_eval(df):
return pd.concat(dfs, ignore_index=True)


def iter_parameters(set_name):
def iter_parameters(set_name, scenario: "message_ix.Scenario"):
"""Iterate over MESSAGEix parameters with *set_name* as a dimension.
Parameters
----------
set_name : str
Name of a set.
Yields
------
str
Names of parameters that have `set_name` indexing ≥1 dimension.
.. deprecated:: 2023.11
Use :meth:`ixmp.Scenario.par_list` with the :py:`indexed_by=...` argument
instead.
"""
# TODO move upstream. See iiasa/ixmp#402 and iiasa/message_ix#444
for name, info in MESSAGE_ITEMS.items():
if info["ix_type"] == "par" and set_name in info["idx_sets"]:
yield name
try:
yield from scenario.items(indexed_by=set_name, par_data=False)
except TypeError: # ixmp < 3.8.0
import message_ix.models

for name, info in message_ix.models.MESSAGE_ITEMS.items():
if info["ix_type"] == "par" and set_name in info["idx_sets"]:
yield name


def make_io(src, dest, efficiency, on="input", **kwargs):
Expand Down Expand Up @@ -603,7 +599,7 @@ def strip_par_data( # noqa: C901
+ (" (DRY RUN)" if dry_run else "")
)
# Iterate over parameters with ≥1 dimensions indexed by `set_name`
pars = iter_parameters(set_name)
pars = iter_parameters(set_name, scenario=scenario)

for par_name in pars:
if par_name not in par_list: # pragma: no cover
Expand Down

0 comments on commit de30f64

Please sign in to comment.