Code reference

Utilities for sdmx.

Functions

anno_generated(obj)

Annotate the obj with information about how it was generated.

fields_to_mda(cls, rs[, cs])

Populate rs with MetadataAttributes corresponding to dataclass fields of cls.

make_obs(row, dsd)

Helper function for making sdmx.model.Observation objects.

read_csv(path, structure[, adapt])

Read or adapt SDMX-CSV from path.

structure_from_csv(path)

Infer a data flow and arguments for read_csv() from path.

transport_data.util.sdmx.anno_generated(obj: sdmx.model.common.AnnotableArtefact) None[source]

Annotate the obj with information about how it was generated.

transport_data.util.sdmx.fields_to_mda(cls: type, rs: sdmx.model.v21.ReportStructure, cs: sdmx.model.common.ConceptScheme | None = None) None[source]

Populate rs with MetadataAttributes corresponding to dataclass fields of cls.

Examples

>>> @dataclass
... class MDSExample:
...     #: Foo
...     #:
...     #: Description of Foo.
...     foo: str
...
...     bar: int
...
... fields_to_mda(MDSExample)

In this example, two metadata attributes will be added to rs:

  1. With id=”foo” and an annotation with id=”data-type” and text=”<class ‘str’>”. The concept identity for the metadata attribute will also have id=”foo”, name=”Foo”, and description=”Description of Foo.”

  2. With id=”bar” and an annotation with id=”data-type” and text=”<class ‘int’>”.

transport_data.util.sdmx.make_obs(row: pd.Series, dsd: sdmx.model.v21.DataStructureDefinition) sdmx.model.v21.Observation[source]

Helper function for making sdmx.model.Observation objects.

transport_data.util.sdmx.read_csv(path: pathlib.Path, structure: sdmx.model.v30.Dataflow | sdmx.model.v30.DataStructureDefinition, adapt: dict | None = None) sdmx.message.DataMessage[source]

Read or adapt SDMX-CSV from path.

Parameters:
  • path – A file in SDMX-CSV or CSV format.

  • structure – Data flow or data structure describing the contents of path.

  • adapt – Keyword arguments to CSVAdapter. If given, the contents of path are adapted from a ‘simplified’ or ‘reduced’ CSV format to SDMX-CSV on-the-fly. See the class documentation for details.

transport_data.util.sdmx.structure_from_csv(path: pathlib.Path) tuple[sdmx.model.v30.Dataflow, dict][source]

Infer a data flow and arguments for read_csv() from path.

Returns:

with 2 elements:

  1. a sdmx.model.v30.Dataflow.

  2. dict, a value for the adapt argument of read_csv().

Return type:

tuple

Classes

CSVAdapter(path[, structure, structure_id, ...])

Adapt CSV content from path into SDMX-CSV.