Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle validFrom, validTo, and annotations on ItemSchemes #143

Merged
merged 5 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ What's new?
Next release
============

- Fix two bugs in parsing :class:`.ItemScheme` from SDMX-ML: :attr:`.VersionableArtefact.valid_from`, :attr:`~.VersionableArtefact.valid_to` not stored, and :class:`Annotations <.Annotation>` for the scheme itself erroneously collected by the first :class:`.Item` in the scheme (:pull:`143`; thanks :gh-user:`goatsweater` for :issue:`142`).
- Update :ref:`OECD <OECD>` to support the provider's recently-added SDMX-ML API (:pull:`140`).
Rename the corresponding, older SDMX-JSON source :ref:`OECD_JSON <OECD_JSON>`; work around a known issue with its SSL configuration (see :func:`.oecd_json.Client`).

Expand Down
13 changes: 10 additions & 3 deletions sdmx/reader/xml/v21.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,15 @@ def maintainable(self, cls, elem, **kwargs):
the same object ID will return references to the same object.
"""
kwargs.setdefault("is_external_reference", elem is None)
setdefault_attrib(kwargs, elem, "isExternalReference", "isFinal", "version")
setdefault_attrib(
kwargs,
elem,
"isExternalReference",
"isFinal",
"validFrom",
"validTo",
"version",
)
kwargs["is_final"] = kwargs.get("is_final", None) == "true"

# Create a candidate object
Expand Down Expand Up @@ -956,7 +964,7 @@ def _item_start(reader, elem):
# No child elements; stash() anyway, but it will be a no-op
pass

reader.stash("Name", "Description")
reader.stash(model.Annotation, "Name", "Description")


@end(
Expand Down Expand Up @@ -1393,7 +1401,6 @@ def _cc(reader, elem):
else:
content.add(resolved)

# return reader.nameable(
return reader.maintainable(
cls,
elem,
Expand Down
1 change: 1 addition & 0 deletions sdmx/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def __init__(self, base_path):
("UNICEF", "GLOBAL_DATAFLOW-structure.xml"),
("UNSD", "codelist_partial.xml"),
("SGR", "common-structure.xml"),
("TEST", "gh-142.xml"),
]
)

Expand Down
15 changes: 15 additions & 0 deletions sdmx/tests/reader/test_reader_xml_v21.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ def test_gh_116(specimen):
assert cl4.is_partial and 0 < len(cl4) < len(cl3)


def test_gh_142(specimen):
"""Test of https://github.com/khaeru/sdmx/issues/142."""
with specimen("TEST/gh-142.xml") as f:
msg = sdmx.read_sdmx(f)

# Annotations, valid_from and valid_to properties stored on the Codelist *per se*
cl = msg.codelist["CL_NAICS"]
assert 3 == len(cl.annotations)
assert "2021-01-24T08:00:00" == cl.valid_from
assert "2021-09-24T08:00:00" == cl.valid_to

# No annotations attached to any Code
assert all(0 == len(code.annotations) for code in cl)


# Each entry is a tuple with 2 elements:
# 1. an instance of lxml.etree.Element to be parsed.
# 2. Either:
Expand Down
Loading