|
24 | 24 | #: |
25 | 25 | #: - Applied to whole strings along each dimension. |
26 | 26 | #: - These columns have :meth:`str.title` applied before these replacements. |
| 27 | +#: |
| 28 | +#: See also :func:`add_replacements`. |
27 | 29 | REPLACE_DIMS: dict[str, dict[str, str]] = { |
28 | 30 | "c": { |
29 | 31 | # in land_out, for CH4 emissions from GLOBIOM |
|
36 | 38 | "t": dict(), |
37 | 39 | } |
38 | 40 |
|
39 | | -#: Replacements used in :meth:`collapse` after the 'variable' column is assembled. |
40 | | -#: These are applied using :meth:`pandas.DataFrame.replace` with ``regex=True``; see |
41 | | -#: the documentation of that method. For documentation of regular expressions, see |
| 41 | +#: Replacements used in :func:`collapse` after 'variable' labels are constructed. These |
| 42 | +#: are applied using :meth:`pandas.DataFrame.replace` with ``regex=True``; see the |
| 43 | +#: documentation of that method. For documentation of regular expressions, see |
42 | 44 | #: https://docs.python.org/3/library/re.html and https://regex101.com. |
43 | 45 | #: |
44 | | -#: .. todo:: These may be particular or idiosyncratic to a single "template". The |
45 | | -#: strings used to collapse multiple conceptual dimensions into the IAMC "variable" |
46 | | -#: column are known to vary in poorly-documented ways across these templates. |
| 46 | +#: .. todo:: These may be particular or idiosyncratic to a single 'template'. The |
| 47 | +#: strings used to collapse multiple conceptual dimensions into the IAMC 'variable' |
| 48 | +#: dimension are known to vary across these templates, in ways that are sometimes not |
| 49 | +#: documented. |
47 | 50 | #: |
48 | 51 | #: This setting is currently applied universally. To improve, specify a different |
49 | 52 | #: mapping with the replacements needed for each individual template, and load the |
@@ -212,18 +215,19 @@ def collapse(df: pd.DataFrame, var=[]) -> pd.DataFrame: |
212 | 215 | """Callback for the `collapse` argument to :meth:`~.Reporter.convert_pyam`. |
213 | 216 |
|
214 | 217 | Replacements from :data:`REPLACE_DIMS` and :data:`REPLACE_VARS` are applied. |
215 | | - The dimensions listed in the `var` arguments are automatically dropped from the |
216 | | - returned :class:`pyam.IamDataFrame`. If ``var[0]`` contains the word "emissions", |
217 | | - then :meth:`collapse_gwp_info` is invoked. |
| 218 | + The dimensions listed in the `var` argument are automatically dropped from the |
| 219 | + returned :class:`pyam.IamDataFrame`. If :py:`var[0]` contains the word "emissions", |
| 220 | + then :func:`collapse_gwp_info` is invoked. |
218 | 221 |
|
219 | 222 | Adapted from :func:`genno.compat.pyam.collapse`. |
220 | 223 |
|
221 | 224 | Parameters |
222 | 225 | ---------- |
223 | 226 | var : list of str, optional |
224 | | - Strings or dimensions to concatenate to the 'Variable' column. The first of |
225 | | - these is usually a string value used to populate the column. These are joined |
226 | | - using the pipe ('|') character. |
| 227 | + Strings or dimensions to concatenate to a 'variable' string. The first of these |
| 228 | + usually a :class:`str` used to populate the column; others may be fixed strings |
| 229 | + or the IDs of dimensions in the input data. The components are joined using the |
| 230 | + pipe ('|') character. |
227 | 231 |
|
228 | 232 | See also |
229 | 233 | -------- |
@@ -314,7 +318,25 @@ def copy_ts(rep: Reporter, other: str, filters: dict | None) -> Key: |
314 | 318 |
|
315 | 319 |
|
316 | 320 | def add_replacements(dim: str, codes: Iterable[Code]) -> None: |
317 | | - """Update :data:`REPLACE_DIMS` for dimension `dim` with values from `codes`.""" |
| 321 | + """Update :data:`REPLACE_DIMS` for dimension `dim` with values from `codes`. |
| 322 | +
|
| 323 | + For every code in `codes` that has an annotation with the ID ``report``, the code |
| 324 | + ID is mapped to the value of the annotation. For example, the following in one of |
| 325 | + the :doc:`/pkg-data/codelists`: |
| 326 | +
|
| 327 | + .. code-block:: yaml |
| 328 | +
|
| 329 | + foo: |
| 330 | + report: fOO |
| 331 | +
|
| 332 | + bar: |
| 333 | + report: Baz |
| 334 | +
|
| 335 | + qux: {} # No "report" annotation → no mapping |
| 336 | +
|
| 337 | + …results in entries :py:`{"foo": "fOO", "bar": "Baz"}` added to :data:`REPLACE_DIMS` |
| 338 | + and used by :func:`collapse`. |
| 339 | + """ |
318 | 340 | for code in codes: |
319 | 341 | try: |
320 | 342 | label = str(code.get_annotation(id="report").text) |
|
0 commit comments