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

Fix ILO entry point url and default parameters #97

Merged
merged 5 commits into from
Sep 15, 2022
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
13 changes: 8 additions & 5 deletions doc/sources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ SDMX-ML —
-------------------

SDMX-ML —
`Website <http://ec.europa.eu/eurostat/web/sdmx-web-services/rest-sdmx-2.1>`__
`Website <https://ec.europa.eu/eurostat/web/sdmx-web-services/rest-sdmx-2.1>`__

- Thousands of dataflows on a wide range of topics.
- No categorisations available.
Expand All @@ -170,17 +170,20 @@ SDMX-ML —
------------------------------------------

SDMX-ML —
`Website <www.ilo.org/ilostat/>`__
`Website <https://ilostat.ilo.org/resources/sdmx-tools/>`__

- :class:`sdmx.source.ilo.Source` handles some particularities of the ILO web service, including:

- The ``references=`` query parameter is not supported; any value is discarded with a warning.

- :class:`sdmx.source.ilo.Source` handles some particularities of the ILO
web service. Others that are not handled:
Others that are not handled:

- Data flow IDs take on the role of a filter.
E.g., there are dataflows for individual countries, ages, sexes etc. rather than merely for different indicators.
- The service returns 413 Payload Too Large errors for some queries, with messages like: "Too many results, please specify codelist ID".
Test for :class:`sdmx.exceptions.HTTPError` (= :class:`requests.exceptions.HTTPError`) and/or specify a ``resource_id``.

- It is highly recommended to read the `API guide <http://www.ilo.org/ilostat/content/conn/ILOSTATContentServer/path/Contribution%20Folders/statistics/web_pages/static_pages/technical_page/ilostat_appl/SDMX_User_Guide.pdf>`_.
- It is highly recommended to read the “ILOSTAT SDMX User Guide” linked from the above webpage.

.. autoclass:: sdmx.source.ilo.Source()
:members:
Expand Down
2 changes: 2 additions & 0 deletions doc/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ What's new?
Next release
============

- Update :ref:`ILO` web service URL and quirks handling (:pull:`97`).
- Use HTTPS for :ref:`ESTAT` (:pull:`97`).
- Bump minimum version of :mod:`pydantic` to 1.9.2 (:pull:`98`).
- Always return all objects parsed from a SDMX-ML :class:`.StructureMessage` (:pull:`99`).

Expand Down
25 changes: 14 additions & 11 deletions sdmx/source/ilo.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import logging

from . import Source as BaseSource

log = logging.getLogger(__name__)


class Source(BaseSource):
_id = "ILO"

def modify_request_args(self, kwargs):
"""Handle two limitations of ILO's REST service.
"""Handle limitations of ILO's REST service.

1. Service returns SDMX-ML 2.0 by default, whereas :mod:`sdmx` only
supports SDMX-ML 2.1. Set ``?format=generic_2_1`` query parameter.
2. The service does not support values 'parents', 'parentsandsiblings'
(the default), and 'all' for the ``references`` query parameter.
Override the default with ``?references=none``.

.. note:: Valid values are: none, parents, parentsandsiblings,
children, descendants, all, or a specific structure reference
such as 'codelist'.
1. Service returns SDMX-ML 2.0 by default, whereas :mod:`sdmx` only supports
SDMX-ML 2.1. Set ``?format=generic_2_1`` query parameter.
2. Service does not support the ``?references=…`` query parameter; discard.
"""
super().modify_request_args(kwargs)

kwargs.setdefault("params", {})
kwargs["params"].setdefault("format", "generic_2_1")
kwargs["params"].setdefault("references", "none")

references = kwargs["params"].pop("references", None)
if references:
log.warning(
f"{self.id} does not support references={references!r}; discarded"
)
6 changes: 3 additions & 3 deletions sdmx/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
},
{
"id": "ESTAT",
"documentation": "http://data.un.org/Host.aspx?Content=API",
"url": "http://ec.europa.eu/eurostat/SDMX/diss-web/rest",
"documentation": "https://ec.europa.eu/eurostat/web/sdmx-web-services/rest-sdmx-2.1",
"url": "https://ec.europa.eu/eurostat/SDMX/diss-web/rest",
"name": "Eurostat",
"supports": {
"agencyscheme": false,
Expand All @@ -63,7 +63,7 @@
{
"id": "ILO",
"name": "International Labor Organization",
"url": "http://www.ilo.org/ilostat/sdmx/ws/rest",
"url": "http://www.ilo.org/sdmx/rest",
"headers": {
"accept": "application/vnd.sdmx.structurespecificdata+xml;version=2.1"
},
Expand Down
5 changes: 5 additions & 0 deletions sdmx/tests/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ def test_codelist(self, cache_path, client):
"codelist", "CL_ECO", tofile=cache_path.with_suffix("." + "codelist-CL_ECO")
)

@pytest.mark.network
def test_gh_96(self, caplog, cache_path, client):
client.get("codelist", "CL_ECO", params=dict(references="parentsandsiblings"))
assert "ILO does not support references = parentsandsiblings; discarded"


class TestINEGI(DataSourceTest):
source_id = "INEGI"
Expand Down