Skip to content

Commit a43e363

Browse files
committed
Expand .iso documentation
1 parent 53f1c10 commit a43e363

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

doc/iso.rst

+58
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,62 @@
11
International Organization for Standardization (ISO)
22
****************************************************
33

4+
This module provides SDMX structures based on code lists ultimately maintained by the ISO.
5+
6+
The ISO does *not* provide SDMX (meta)data directly.
7+
Rather:
8+
9+
- The Debian `pkg-isocodes <https://salsa.debian.org/iso-codes-team/iso-codes>`_ provides these lists and their translations into at least 159 languages.
10+
- These are mirrored and exposed in Python by `pycountry <https://github.com/pycountry/pycountry>`_.
11+
- The current module, :mod:`.transport_data.iso`, converts these into SDMX.
12+
13+
The resulting code lists have SDMX URNs like ``Codelist=ISO:3166-1_alpha_2(24.6.1)`` that combine the ISO standard number (in the example, ``3166-1``); the field from the upstream data that is used for the code IDs (``alpha_2``), and a version number that is derived from the version of :mod:`pycountry` (``24.6.1``).
14+
Thus:
15+
16+
- In ``Codelist=ISO:3166-1_alpha_2(24.6.1)``, the code for the country Canada has ID ``CA``.
17+
- In ``Codelist=ISO:3166-1_alpha_3(24.6.1)``, the code for the country Canada has ID ``CAN``.
18+
- In ``Codelist=ISO:3166-1_numeric(24.6.1)``, the code for the country Canada has ID ``124``.
19+
20+
The pycountry README states:
21+
22+
**Data update policy**:
23+
No changes to the data will be accepted into pycountry.
24+
This is a pure wrapper around the ISO standard using the `pkg-isocodes` database from Debian *as is*.
25+
If you need changes to the political situation in the world, please talk to the ISO or Debian people, not me.
26+
27+
In the same way, :mod:`.transport_data.iso` *only* provides conversion to SDMX, and the converted code lists will not be modified to add, remove, or modify codes.
28+
Instead, data providers who wish to use code lists derived from the ISO lists can do so by reference.
29+
For example:
30+
31+
.. code-block:: Python
32+
33+
from copy import deepcopy
34+
35+
from sdmx.model import common
36+
from transport_data import STORE
37+
38+
# Retrieve the code list with ISO 3166-1 alpha-2 codes,
39+
# their translations and annotations
40+
cl_iso = STORE.get("Codelist=ISO:3166-1_alpha_2(24.6.1)")
41+
42+
# Create a new code list
43+
cl = common.codelist(id="GEO_CUSTOM")
44+
45+
# Copy 1 or more codes from the ISO list; give each an
46+
# annotation like "urn…Code=ISO:3166-1_alpha_2(24.6.1).AW"
47+
# that clearly associates it with the original
48+
for id_ in ("AW", "ZE"):
49+
c = deepcopy(cl_iso.get(id_))
50+
c.annotations.append(
51+
common.Annotation(id="same-as", text=c.urn)
52+
)
53+
cl.append(c)
54+
55+
# Add other code(s) not in the ISO standard
56+
cl.append(
57+
common.Code(id="XX", name="Custom code not in ISO 3166-1")
58+
)
59+
60+
.. todo:: Possibly update this submodule to load data directly from the Debian iso-codes repo, instead of via :mod:`pycountry`.
61+
462
.. include:: _api/transport_data.iso.rst

0 commit comments

Comments
 (0)