SDMX (compat.sdmx
)¶
Note that this package is available in PyPI as sdmx1
.
To install the correct package, use:
pip install genno[sdmx]
To ensure the operators are available:
c = Computer()
c.require_compat("sdmx")
c.add(..., "codelist_to_groups", ...)
|
Convert codes into a mapping from parent items to their children. |
|
Convert the coordinates of qty to a collection of |
|
|
|
Convert |
This module also registers an implementation of write_report()
that handles sdmx.message.DataMessage
objects, such as those produced by quantity_to_message()
.
- genno.compat.sdmx.operator.codelist_to_groups(codes: Codelist | Iterable[Code], dim: str | None = None) Mapping[str, Mapping[str, list[str]]] [source]¶
Convert codes into a mapping from parent items to their children.
The returned value is suitable for use with
aggregate()
.- Parameters:
codes – Either a
sdmx.Codelist
object or any iterable ofsdmx.Code
.dim (
str
, optional) – Dimension to aggregate. If codes is a code list and dim is not given, the ID of the code list is used; otherwise dim must be supplied.
- genno.compat.sdmx.operator.coords_to_codelists(qty: AnyQuantity, *, id_transform: ~collections.abc.Callable | None = <method 'upper' of 'str' objects>, **kwargs) list[sdmx.model.common.Codelist] [source]¶
Convert the coordinates of qty to a collection of
Codelist
.
- genno.compat.sdmx.operator.dataset_to_quantity(ds: sdmx.model.common.BaseDataSet) AnyQuantity [source]¶
-
- Returns:
The quantity may have the attributes:
”dataflow_urn”:
urn
of theDataflow
referenced by thedescribed_by
attribute of ds, if any.”structure_urn”:
urn
of theDataStructureDefinition
referenced by thestructured_by
attribute of ds, if any.
- Return type:
- genno.compat.sdmx.operator.quantity_to_dataset(qty: AnyQuantity, structure: sdmx.model.common.BaseDataStructureDefinition, *, observation_dimension: str | None = None, version: sdmx.format.Version | str | None = None) sdmx.model.common.BaseDataSet [source]¶
-
The resulting data set is structure-specific.
- Parameters:
observation_dimension (
str
orsdmx.model.common.DimensionComponent
, optional) – If given, the resulting data set is arranged in series, with the observation_dimension varying across observations within each series. If not given, the data set is flat, with all dimensions specified for each observation.version (
str
orsdmx.format.Version
, optional) – SDMX data model version to use; default 2.1.
- genno.compat.sdmx.operator.quantity_to_message(qty: AnyQuantity, structure: sdmx.model.v21.DataStructureDefinition, **kwargs) sdmx.message.DataMessage [source]¶
Convert
Quantity
toDataMessage
.- Parameters:
kwargs – observation_dimension and version parameters are both used and passed on to
quantity_to_dataset()
.