diff --git a/doc/whatsnew.rst b/doc/whatsnew.rst index 7d9c85aedb..34679aa378 100644 --- a/doc/whatsnew.rst +++ b/doc/whatsnew.rst @@ -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 ` (:pull:`134`). v2023.10.16 @@ -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 -------- diff --git a/message_ix_models/util/__init__.py b/message_ix_models/util/__init__.py index 7405a18431..90fea2b69d 100644 --- a/message_ix_models/util/__init__.py +++ b/message_ix_models/util/__init__.py @@ -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 @@ -44,7 +43,6 @@ "eval_anno", "ffill", "identify_nodes", - "iter_parameters", "load_package_data", "load_private_data", "local_data_path", @@ -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): @@ -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