unicefdata 2.3.2__tar.gz → 2.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {unicefdata-2.3.2/unicefdata.egg-info → unicefdata-2.4.0}/PKG-INFO +19 -1
- {unicefdata-2.3.2 → unicefdata-2.4.0}/README.md +18 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/pyproject.toml +19 -1
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_404_fallback.py +2 -2
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_dimensions.py +6 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_download.py +6 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_fallback_fix.py +8 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_pipeline_mocked.py +5 -5
- unicefdata-2.4.0/tests/test_query_status.py +147 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_transformations.py +8 -9
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/__init__.py +1 -1
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/unicefdata.py +165 -25
- {unicefdata-2.3.2 → unicefdata-2.4.0/unicefdata.egg-info}/PKG-INFO +19 -1
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata.egg-info/SOURCES.txt +1 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/LICENSE +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/setup.cfg +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_deterministic.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_direct_metadata.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_discovery.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_error_conditions.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_hardcoded_removal_validation.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_list_dataflows.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_metadata_manager.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_python_integration.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_quick_python.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_sdmx_client_dataflow.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_sync_pipeline.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/tests/test_unicef_api.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/config.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/config_loader.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/flows.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/indicator_registry.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/_unicefdata_sync_history.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/_dataflow_fallback_sequences.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/_unicefdata_codelists.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/_unicefdata_countries.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/_unicefdata_dataflows.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/_unicefdata_indicators.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/_unicefdata_indicators_metadata.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/_unicefdata_regions.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflow_index.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CAUSE_OF_DEATH.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CCRI.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CHILD_RELATED_SDG.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CHLD_PVTY.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_CAUSE_OF_DEATH.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_COUNTRY_PROFILES_DATA.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_DF_2021_WQ.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNATIONAL.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_AGO.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_BDI.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_BEN.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_BGD.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_CMR.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_ETH.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_GHA.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_GIN.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_HTI.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_KEN.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_LAO.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_LBR.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_LSO.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_MDG.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_MLI.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_MMR.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_MRT.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_MWI.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_NAM.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_NGA.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_NPL.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_PAK.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_RWA.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_SEN.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_SLE.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_TCD.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_TGO.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_TZA.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_UGA.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_ZMB.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_ZWE.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/COVID.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/COVID_CASES.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/DM.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/DM_PROJECTIONS.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/ECD.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/ECONOMIC.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/EDUCATION.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/EDUCATION_FLS.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/EDUCATION_UIS_SDG.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/FUNCTIONAL_DIFF.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/GENDER.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/GLOBAL_DATAFLOW.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/HIV_AIDS.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/IMMUNISATION.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/MG.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/MNCH.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/NUTRITION.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/PT.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/PT_CM.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/PT_CM_SUBNATIONAL.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/PT_CONFLICT.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/PT_FGM.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/SDG_PROG_ASSESSMENT.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/SOC_PROTECTION.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/WASH_HEALTHCARE_FACILITY.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/WASH_HOUSEHOLDS.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/WASH_HOUSEHOLD_MH.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/WASH_HOUSEHOLD_SUBNAT.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/WASH_SCHOOLS.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/WT.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/unicef_indicators_metadata.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-03/codelists.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-03/dataflows.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-03/indicators.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-03/summary.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-05/_unicefdata_codelists.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-05/_unicefdata_countries.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-05/_unicefdata_dataflows.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-05/_unicefdata_indicators.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-05/_unicefdata_regions.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-05/summary.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-07/_unicefdata_codelists.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-07/_unicefdata_countries.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-07/_unicefdata_dataflows.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-07/_unicefdata_indicators.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-07/_unicefdata_regions.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-07/summary.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2026-01-21/_unicefdata_codelists.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2026-01-21/_unicefdata_countries.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2026-01-21/_unicefdata_dataflows.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2026-01-21/_unicefdata_indicators.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2026-01-21/_unicefdata_regions.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2026-01-21/summary.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2026-01-25/_unicefdata_codelists.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2026-01-25/_unicefdata_countries.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2026-01-25/_unicefdata_dataflows.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2026-01-25/_unicefdata_indicators.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2026-01-25/_unicefdata_regions.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2026-01-25/summary.yaml +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata_manager.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/run_sync.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/schema_cache.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/schema_sync.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/sdmx.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/sdmx_client.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/utils.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/yaml_formatter.py +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata.egg-info/dependency_links.txt +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata.egg-info/requires.txt +0 -0
- {unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: unicefdata
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.0
|
|
4
4
|
Summary: Python library for downloading UNICEF indicators via SDMX API
|
|
5
5
|
Author-email: Joao Pedro Azevedo <jpazevedo@unicef.org>
|
|
6
6
|
License: MIT
|
|
@@ -82,6 +82,24 @@ print(unicefdata.__version__)
|
|
|
82
82
|
|
|
83
83
|
---
|
|
84
84
|
|
|
85
|
+
## What's New in 2.4.0
|
|
86
|
+
|
|
87
|
+
- **Query status codes**: Empty results now tell you *why* via `df.attrs["query_status"]`:
|
|
88
|
+
- `year_not_found` — country has data, but not for the requested year (gap in time series)
|
|
89
|
+
- `year_beyond_range` — requested year is before the earliest or after the latest data point
|
|
90
|
+
- `country_not_found` — indicator exists but not for this country (includes `available_countries`)
|
|
91
|
+
- `indicator_not_found` — indicator doesn't exist in any dataflow
|
|
92
|
+
- **Client-side year filtering**: Fixes 6 survey-based indicators (NUTRITION, MNCH, EDUCATION) that failed with year filters due to an SDMX API quirk
|
|
93
|
+
- **Smarter fallback logic**: No longer wastes API calls trying non-existent fallback dataflows when data simply doesn't exist for the requested country/year
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
df = unicefData("MNCH_CSEC", countries=["BRA"], year=2020)
|
|
97
|
+
# len(df) == 0
|
|
98
|
+
print(df.attrs["query_status"]) # "year_not_found"
|
|
99
|
+
print(df.attrs["available_years"]) # [2000, 2001, ..., 2019]
|
|
100
|
+
print(df.attrs["nearest_year"]) # 2019
|
|
101
|
+
```
|
|
102
|
+
|
|
85
103
|
## What's New in 2.2.2
|
|
86
104
|
|
|
87
105
|
- **`UNICEFSDMXClient` dataflow resolution fixed**: `fetch_indicator()` now auto-detects the correct dataflow from metadata instead of always defaulting to `GLOBAL_DATAFLOW`, consistent with `unicefData()`
|
|
@@ -41,6 +41,24 @@ print(unicefdata.__version__)
|
|
|
41
41
|
|
|
42
42
|
---
|
|
43
43
|
|
|
44
|
+
## What's New in 2.4.0
|
|
45
|
+
|
|
46
|
+
- **Query status codes**: Empty results now tell you *why* via `df.attrs["query_status"]`:
|
|
47
|
+
- `year_not_found` — country has data, but not for the requested year (gap in time series)
|
|
48
|
+
- `year_beyond_range` — requested year is before the earliest or after the latest data point
|
|
49
|
+
- `country_not_found` — indicator exists but not for this country (includes `available_countries`)
|
|
50
|
+
- `indicator_not_found` — indicator doesn't exist in any dataflow
|
|
51
|
+
- **Client-side year filtering**: Fixes 6 survey-based indicators (NUTRITION, MNCH, EDUCATION) that failed with year filters due to an SDMX API quirk
|
|
52
|
+
- **Smarter fallback logic**: No longer wastes API calls trying non-existent fallback dataflows when data simply doesn't exist for the requested country/year
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
df = unicefData("MNCH_CSEC", countries=["BRA"], year=2020)
|
|
56
|
+
# len(df) == 0
|
|
57
|
+
print(df.attrs["query_status"]) # "year_not_found"
|
|
58
|
+
print(df.attrs["available_years"]) # [2000, 2001, ..., 2019]
|
|
59
|
+
print(df.attrs["nearest_year"]) # 2019
|
|
60
|
+
```
|
|
61
|
+
|
|
44
62
|
## What's New in 2.2.2
|
|
45
63
|
|
|
46
64
|
- **`UNICEFSDMXClient` dataflow resolution fixed**: `fetch_indicator()` now auto-detects the correct dataflow from metadata instead of always defaulting to `GLOBAL_DATAFLOW`, consistent with `unicefData()`
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "unicefdata"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.4.0"
|
|
8
8
|
description = "Python library for downloading UNICEF indicators via SDMX API"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = {text = "MIT"}
|
|
@@ -55,3 +55,21 @@ include = ["unicefdata*"]
|
|
|
55
55
|
|
|
56
56
|
[tool.setuptools.package-data]
|
|
57
57
|
unicefdata = ["metadata/**/*.yaml"]
|
|
58
|
+
|
|
59
|
+
[tool.pytest.ini_options]
|
|
60
|
+
testpaths = ["tests"]
|
|
61
|
+
markers = [
|
|
62
|
+
"network: tests that make live HTTP calls to external APIs (deselect with -m 'not network')",
|
|
63
|
+
"slow: tests that take more than 10 seconds",
|
|
64
|
+
]
|
|
65
|
+
filterwarnings = [
|
|
66
|
+
"ignore::DeprecationWarning",
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
[tool.coverage.run]
|
|
70
|
+
source = ["unicefdata"]
|
|
71
|
+
omit = ["tests/*", "scripts/*"]
|
|
72
|
+
|
|
73
|
+
[tool.coverage.report]
|
|
74
|
+
show_missing = true
|
|
75
|
+
skip_empty = true
|
|
@@ -56,9 +56,9 @@ class Test404Fallback:
|
|
|
56
56
|
col in column_names
|
|
57
57
|
for col in ['iso3', 'ref_area', 'period', 'time_period', 'value', 'obs_value', 'dataflow']
|
|
58
58
|
)
|
|
59
|
-
# If we have columns, at least one should be
|
|
59
|
+
# If we have columns, at least one should be a recognized SDMX column
|
|
60
60
|
if len(df.columns) > 0:
|
|
61
|
-
assert has_standard_col
|
|
61
|
+
assert has_standard_col, f"No standard columns found in: {column_names}"
|
|
62
62
|
|
|
63
63
|
@responses.activate
|
|
64
64
|
def test_valid_indicator_after_404_still_works(self, mock_sdmx_data_endpoints):
|
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Converts the previous script into proper tests and expands coverage via
|
|
4
4
|
parameterization across common UNICEF dataflows.
|
|
5
|
+
|
|
6
|
+
NOTE: All tests in this module make live HTTP calls to sdmx.data.unicef.org.
|
|
7
|
+
Run with: pytest -m network
|
|
8
|
+
Skip with: pytest -m 'not network'
|
|
5
9
|
"""
|
|
6
10
|
|
|
7
11
|
import pytest
|
|
12
|
+
|
|
13
|
+
pytestmark = pytest.mark.network
|
|
8
14
|
import requests
|
|
9
15
|
import xml.etree.ElementTree as ET
|
|
10
16
|
|
|
@@ -3,10 +3,16 @@ Automated tests to verify Python can download indicators from various dataflows
|
|
|
3
3
|
after implementing the 3-tier fallback logic and simpler .INDICATOR. key pattern.
|
|
4
4
|
|
|
5
5
|
Uses golden indicators from validation/xval/golden_indicators.yaml
|
|
6
|
+
|
|
7
|
+
NOTE: All tests in this module make live HTTP calls to sdmx.data.unicef.org.
|
|
8
|
+
Run with: pytest -m network
|
|
9
|
+
Skip with: pytest -m 'not network'
|
|
6
10
|
"""
|
|
7
11
|
|
|
8
12
|
import pytest
|
|
9
13
|
|
|
14
|
+
pytestmark = pytest.mark.network
|
|
15
|
+
|
|
10
16
|
from unicefdata import unicefData
|
|
11
17
|
from unicefdata.sdmx_client import SDMXForbiddenError
|
|
12
18
|
|
|
@@ -7,9 +7,17 @@ Tests:
|
|
|
7
7
|
3. Verify that valid, non-empty data are returned for both indicators
|
|
8
8
|
|
|
9
9
|
Uses golden indicators from validation/xval/golden_indicators.yaml
|
|
10
|
+
|
|
11
|
+
NOTE: All tests in this module make live HTTP calls to sdmx.data.unicef.org.
|
|
12
|
+
Run with: pytest -m network
|
|
13
|
+
Skip with: pytest -m 'not network'
|
|
10
14
|
"""
|
|
11
15
|
|
|
12
16
|
import sys
|
|
17
|
+
|
|
18
|
+
import pytest
|
|
19
|
+
|
|
20
|
+
pytestmark = pytest.mark.network
|
|
13
21
|
import logging
|
|
14
22
|
from pathlib import Path
|
|
15
23
|
|
|
@@ -152,18 +152,18 @@ class TestPipelineMulti:
|
|
|
152
152
|
"""Unknown indicator should return empty DataFrame or raise"""
|
|
153
153
|
mock_pipeline_endpoints()
|
|
154
154
|
|
|
155
|
-
#
|
|
155
|
+
# Should either return empty DF or raise a known SDMX error
|
|
156
|
+
from unicefdata.sdmx_client import SDMXNotFoundError, SDMXError
|
|
156
157
|
try:
|
|
157
158
|
df = unicefData(
|
|
158
159
|
indicator="NONEXISTENT_INDICATOR_XYZ",
|
|
159
160
|
countries=["ALB"],
|
|
160
161
|
)
|
|
161
|
-
# If it returns,
|
|
162
|
+
# If it returns, must be empty DataFrame
|
|
162
163
|
assert isinstance(df, pd.DataFrame)
|
|
163
164
|
assert len(df) == 0
|
|
164
|
-
except
|
|
165
|
-
#
|
|
166
|
-
pass
|
|
165
|
+
except (SDMXNotFoundError, SDMXError):
|
|
166
|
+
pass # Expected: unknown indicator raises SDMX error
|
|
167
167
|
|
|
168
168
|
|
|
169
169
|
class TestPipelineColumnOrder:
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"""Tests for query status codes on empty results.
|
|
2
|
+
|
|
3
|
+
Verifies that unicefData() sets df.attrs["query_status"] correctly.
|
|
4
|
+
All tests use mocked HTTP responses — no network calls.
|
|
5
|
+
|
|
6
|
+
See docs/QUERY_STATUS_CODES.md for the full spec.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import re
|
|
10
|
+
import pytest
|
|
11
|
+
import responses
|
|
12
|
+
|
|
13
|
+
import unicefdata.unicefdata as _umod
|
|
14
|
+
from unicefdata import unicefData
|
|
15
|
+
from unicefdata.sdmx_client import SDMXNotFoundError
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
BASE_URL = "https://sdmx.data.unicef.org/ws/public/sdmxapi/rest/data"
|
|
19
|
+
SDMX_ANY = re.compile(r"https://sdmx\.data\.unicef\.org/.*")
|
|
20
|
+
|
|
21
|
+
MNCH_BRA_CSV = (
|
|
22
|
+
"DATAFLOW,REF_AREA,INDICATOR,SEX,TIME_PERIOD,OBS_VALUE,UNIT_MEASURE,OBS_STATUS,DATA_SOURCE\n"
|
|
23
|
+
"MNCH,BRA,MNCH_CSEC,_T,2015,55.5,PCT,AVAILABLE,SURVEY\n"
|
|
24
|
+
"MNCH,BRA,MNCH_CSEC,_T,2016,55.6,PCT,AVAILABLE,SURVEY\n"
|
|
25
|
+
"MNCH,BRA,MNCH_CSEC,_T,2017,55.8,PCT,AVAILABLE,SURVEY\n"
|
|
26
|
+
"MNCH,BRA,MNCH_CSEC,_T,2018,56.1,PCT,AVAILABLE,SURVEY\n"
|
|
27
|
+
"MNCH,BRA,MNCH_CSEC,_T,2019,56.4,PCT,AVAILABLE,SURVEY\n"
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
MNCH_BRA_GAP_CSV = (
|
|
31
|
+
"DATAFLOW,REF_AREA,INDICATOR,SEX,TIME_PERIOD,OBS_VALUE,UNIT_MEASURE,OBS_STATUS,DATA_SOURCE\n"
|
|
32
|
+
"MNCH,BRA,MNCH_CSEC,_T,2015,55.5,PCT,AVAILABLE,SURVEY\n"
|
|
33
|
+
"MNCH,BRA,MNCH_CSEC,_T,2019,56.4,PCT,AVAILABLE,SURVEY\n"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
MNCH_ARG_CSV = (
|
|
37
|
+
"DATAFLOW,REF_AREA,INDICATOR,SEX,TIME_PERIOD,OBS_VALUE,UNIT_MEASURE,OBS_STATUS,DATA_SOURCE\n"
|
|
38
|
+
"MNCH,ARG,MNCH_CSEC,_T,2020,32.1,PCT,AVAILABLE,SURVEY\n"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class _FakeSync:
|
|
43
|
+
def ensure_synced(self, **kwargs):
|
|
44
|
+
return False
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _reset():
|
|
48
|
+
"""Reset module state and disable metadata sync before each test."""
|
|
49
|
+
_umod._client = None
|
|
50
|
+
_umod.MetadataSync = _FakeSync
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _mock(csv_body, url_pattern=None):
|
|
54
|
+
"""Register mocked response + catch-all 404."""
|
|
55
|
+
if url_pattern and csv_body:
|
|
56
|
+
responses.add(responses.GET, url_pattern, body=csv_body, status=200, content_type="text/csv")
|
|
57
|
+
responses.add(responses.GET, SDMX_ANY, body="Not Found", status=404)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
MNCH_PATTERN = re.compile(rf"{re.escape(BASE_URL)}/UNICEF,MNCH.*MNCH_CSEC.*")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@responses.activate
|
|
64
|
+
def test_ok():
|
|
65
|
+
_reset()
|
|
66
|
+
_mock(MNCH_BRA_CSV, MNCH_PATTERN)
|
|
67
|
+
df = unicefData(indicator="MNCH_CSEC", countries=["BRA"], dataflow="MNCH")
|
|
68
|
+
assert len(df) > 0
|
|
69
|
+
assert df.attrs.get("query_status") == "ok"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@responses.activate
|
|
73
|
+
def test_year_not_found_gap():
|
|
74
|
+
_reset()
|
|
75
|
+
_mock(MNCH_BRA_GAP_CSV, MNCH_PATTERN)
|
|
76
|
+
df = unicefData(indicator="MNCH_CSEC", countries=["BRA"], year=2017, dataflow="MNCH")
|
|
77
|
+
assert len(df) == 0
|
|
78
|
+
assert df.attrs["query_status"] == "year_not_found"
|
|
79
|
+
assert 2015 in df.attrs["available_years"]
|
|
80
|
+
assert 2019 in df.attrs["available_years"]
|
|
81
|
+
assert df.attrs["nearest_year"] in (2015, 2019)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@responses.activate
|
|
85
|
+
def test_year_beyond_range_future():
|
|
86
|
+
_reset()
|
|
87
|
+
_mock(MNCH_BRA_CSV, MNCH_PATTERN)
|
|
88
|
+
df = unicefData(indicator="MNCH_CSEC", countries=["BRA"], year=2025, dataflow="MNCH")
|
|
89
|
+
assert len(df) == 0
|
|
90
|
+
assert df.attrs["query_status"] == "year_beyond_range"
|
|
91
|
+
assert df.attrs["nearest_year"] == 2019
|
|
92
|
+
assert "outside" in df.attrs["message"].lower()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@responses.activate
|
|
96
|
+
def test_year_beyond_range_past():
|
|
97
|
+
_reset()
|
|
98
|
+
_mock(MNCH_BRA_CSV, MNCH_PATTERN)
|
|
99
|
+
df = unicefData(indicator="MNCH_CSEC", countries=["BRA"], year=2010, dataflow="MNCH")
|
|
100
|
+
assert len(df) == 0
|
|
101
|
+
assert df.attrs["query_status"] == "year_beyond_range"
|
|
102
|
+
assert df.attrs["nearest_year"] == 2015
|
|
103
|
+
assert df.attrs["available_years"] == [2015, 2016, 2017, 2018, 2019]
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@responses.activate
|
|
107
|
+
def test_country_not_found():
|
|
108
|
+
_reset()
|
|
109
|
+
# Both fetches return ARG-only data
|
|
110
|
+
responses.add(responses.GET, MNCH_PATTERN, body=MNCH_ARG_CSV, status=200, content_type="text/csv")
|
|
111
|
+
responses.add(responses.GET, MNCH_PATTERN, body=MNCH_ARG_CSV, status=200, content_type="text/csv")
|
|
112
|
+
responses.add(responses.GET, SDMX_ANY, body="Not Found", status=404)
|
|
113
|
+
|
|
114
|
+
df = unicefData(indicator="MNCH_CSEC", countries=["BRA"], dataflow="MNCH")
|
|
115
|
+
assert len(df) == 0
|
|
116
|
+
assert df.attrs["query_status"] == "country_not_found"
|
|
117
|
+
assert "ARG" in df.attrs.get("available_countries", [])
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
@responses.activate
|
|
121
|
+
def test_indicator_not_found():
|
|
122
|
+
_reset()
|
|
123
|
+
responses.add(responses.GET, SDMX_ANY, body="Not Found", status=404)
|
|
124
|
+
with pytest.raises(SDMXNotFoundError):
|
|
125
|
+
unicefData(indicator="COMPLETELY_FAKE_XYZ", countries=["BRA"])
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@responses.activate
|
|
129
|
+
def test_attrs_survive():
|
|
130
|
+
_reset()
|
|
131
|
+
_mock(MNCH_BRA_CSV, MNCH_PATTERN)
|
|
132
|
+
df = unicefData(indicator="MNCH_CSEC", countries=["BRA"], year=2025, dataflow="MNCH")
|
|
133
|
+
for key in ["query_status", "query_indicator", "query_countries", "available_years", "nearest_year", "message"]:
|
|
134
|
+
assert key in df.attrs, f"Missing attr: {key}"
|
|
135
|
+
assert isinstance(df.attrs["available_years"], list)
|
|
136
|
+
assert isinstance(df.attrs["message"], str)
|
|
137
|
+
assert len(df.attrs["message"]) > 0
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
@responses.activate
|
|
141
|
+
def test_year_range_beyond():
|
|
142
|
+
_reset()
|
|
143
|
+
_mock(MNCH_BRA_CSV, MNCH_PATTERN)
|
|
144
|
+
df = unicefData(indicator="MNCH_CSEC", countries=["BRA"], year="2025:2028", dataflow="MNCH")
|
|
145
|
+
assert len(df) == 0
|
|
146
|
+
assert df.attrs["query_status"] == "year_beyond_range"
|
|
147
|
+
assert "2025" in df.attrs["message"]
|
|
@@ -270,18 +270,17 @@ class TestDiscovery:
|
|
|
270
270
|
assert result is not None, "CME_MRY0T4 should resolve to a dataflow"
|
|
271
271
|
assert isinstance(result, str)
|
|
272
272
|
|
|
273
|
-
def test_get_indicator_info(self):
|
|
273
|
+
def test_get_indicator_info(self, monkeypatch):
|
|
274
274
|
"""get_indicator_info should return metadata dict."""
|
|
275
275
|
import unicefdata.indicator_registry as reg
|
|
276
276
|
|
|
277
|
-
# Pre-seed the module cache from fixture
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
reg._cache_loaded = True
|
|
277
|
+
# Pre-seed the module cache from fixture via monkeypatch (safe — auto-reverted)
|
|
278
|
+
cache_file = METADATA_FIXTURES / "unicef_indicators_metadata.yaml"
|
|
279
|
+
if cache_file.exists():
|
|
280
|
+
with open(cache_file, 'r', encoding='utf-8') as f:
|
|
281
|
+
data = yaml.safe_load(f)
|
|
282
|
+
monkeypatch.setattr(reg, '_indicator_cache', data.get('indicators', {}))
|
|
283
|
+
monkeypatch.setattr(reg, '_cache_loaded', True)
|
|
285
284
|
|
|
286
285
|
info = reg.get_indicator_info("CME_MRY0T4")
|
|
287
286
|
assert info is not None
|
|
@@ -5,7 +5,7 @@ This library provides a simplified interface for fetching child welfare and deve
|
|
|
5
5
|
indicators from UNICEF's SDMX data repository.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
__version__ = "2.
|
|
8
|
+
__version__ = "2.4.0"
|
|
9
9
|
|
|
10
10
|
def _build_user_agent() -> str:
|
|
11
11
|
"""Build a User-Agent string including package version and Python runtime."""
|
|
@@ -501,28 +501,146 @@ def _fetch_indicator_with_fallback(
|
|
|
501
501
|
# Log fallback attempts (matching R's verbose output)
|
|
502
502
|
if df_attempt != dataflows_to_try[0]:
|
|
503
503
|
_logger.info(f"Trying fallback dataflow '{df_attempt}'...")
|
|
504
|
-
|
|
504
|
+
|
|
505
505
|
try:
|
|
506
|
+
# Fetch WITHOUT year filter to get all available data.
|
|
507
|
+
# Year filtering is done client-side to:
|
|
508
|
+
# 1. Avoid SDMX API 404 quirk on survey dataflows (NUTRITION, MNCH, EDUCATION)
|
|
509
|
+
# 2. Enable query_status classification (country_not_found vs year_not_found)
|
|
506
510
|
df = client.fetch_indicator(
|
|
507
511
|
indicator_code=indicator_code,
|
|
508
512
|
countries=countries,
|
|
509
|
-
start_year=
|
|
510
|
-
end_year=
|
|
513
|
+
start_year=None,
|
|
514
|
+
end_year=None,
|
|
511
515
|
dataflow=df_attempt,
|
|
512
516
|
sex_disaggregation=sex,
|
|
513
517
|
totals=False,
|
|
514
518
|
max_retries=max_retries,
|
|
515
519
|
return_raw=not tidy,
|
|
516
520
|
)
|
|
517
|
-
|
|
518
|
-
if
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
521
|
+
|
|
522
|
+
if df.empty:
|
|
523
|
+
# Dataflow returned 200 but 0 rows for these countries.
|
|
524
|
+
# Don't try fallbacks — the dataflow exists, data just
|
|
525
|
+
# isn't available for these countries.
|
|
526
|
+
empty = pd.DataFrame()
|
|
527
|
+
all_countries = set()
|
|
528
|
+
# Probe API without country filter to discover which countries
|
|
529
|
+
# have data. This downloads the full indicator dataset (can be
|
|
530
|
+
# large for CME ~65K rows). No lighter alternative exists in
|
|
531
|
+
# the SDMX API — there is no availability/summary endpoint.
|
|
532
|
+
try:
|
|
533
|
+
df_probe = client.fetch_indicator(
|
|
534
|
+
indicator_code=indicator_code,
|
|
535
|
+
countries=None,
|
|
536
|
+
start_year=None,
|
|
537
|
+
end_year=None,
|
|
538
|
+
dataflow=df_attempt,
|
|
539
|
+
sex_disaggregation=sex,
|
|
540
|
+
max_retries=1,
|
|
541
|
+
return_raw=True,
|
|
523
542
|
)
|
|
524
|
-
|
|
525
|
-
|
|
543
|
+
if not df_probe.empty:
|
|
544
|
+
ref_col = 'REF_AREA' if 'REF_AREA' in df_probe.columns else 'iso3'
|
|
545
|
+
if ref_col in df_probe.columns:
|
|
546
|
+
all_countries = set(df_probe[ref_col].unique())
|
|
547
|
+
except Exception:
|
|
548
|
+
pass
|
|
549
|
+
|
|
550
|
+
if all_countries:
|
|
551
|
+
sample = sorted(all_countries)[:20]
|
|
552
|
+
empty.attrs["query_status"] = "country_not_found"
|
|
553
|
+
empty.attrs["query_indicator"] = indicator_code
|
|
554
|
+
empty.attrs["query_countries"] = countries or []
|
|
555
|
+
empty.attrs["available_countries"] = sample
|
|
556
|
+
empty.attrs["message"] = (
|
|
557
|
+
f"No data for {countries} for indicator '{indicator_code}'. "
|
|
558
|
+
f"Data exists for {len(all_countries)} countries including: "
|
|
559
|
+
f"{', '.join(sample[:5])}..."
|
|
560
|
+
)
|
|
561
|
+
_logger.info(empty.attrs["message"])
|
|
562
|
+
else:
|
|
563
|
+
empty.attrs["query_status"] = "indicator_not_found"
|
|
564
|
+
empty.attrs["query_indicator"] = indicator_code
|
|
565
|
+
empty.attrs["message"] = (
|
|
566
|
+
f"Indicator '{indicator_code}' returned no data from "
|
|
567
|
+
f"dataflow '{df_attempt}'."
|
|
568
|
+
)
|
|
569
|
+
return empty
|
|
570
|
+
|
|
571
|
+
# Data found — apply year filter client-side
|
|
572
|
+
if start_year or end_year:
|
|
573
|
+
period_col = 'period' if 'period' in df.columns else 'TIME_PERIOD'
|
|
574
|
+
if period_col in df.columns:
|
|
575
|
+
df_pre_filter = df.copy()
|
|
576
|
+
|
|
577
|
+
# Coerce period to numeric year for robust comparison
|
|
578
|
+
# Handles both tidy (float) and raw (string '2020' or '2020-01')
|
|
579
|
+
years = pd.to_numeric(
|
|
580
|
+
df[period_col].astype(str).str.slice(0, 4),
|
|
581
|
+
errors="coerce",
|
|
582
|
+
)
|
|
583
|
+
mask = pd.Series(True, index=df.index)
|
|
584
|
+
if start_year:
|
|
585
|
+
mask &= years >= start_year
|
|
586
|
+
if end_year:
|
|
587
|
+
mask &= years <= end_year
|
|
588
|
+
df = df[mask]
|
|
589
|
+
|
|
590
|
+
if df.empty:
|
|
591
|
+
# Country has data but not for the requested year(s)
|
|
592
|
+
years_pre = pd.to_numeric(
|
|
593
|
+
df_pre_filter[period_col].astype(str).str.slice(0, 4),
|
|
594
|
+
errors="coerce",
|
|
595
|
+
)
|
|
596
|
+
avail = sorted(years_pre.dropna().unique())
|
|
597
|
+
avail_years = [int(y) for y in avail]
|
|
598
|
+
min_year = min(avail_years) if avail_years else None
|
|
599
|
+
max_year = max(avail_years) if avail_years else None
|
|
600
|
+
|
|
601
|
+
# Handle year range queries
|
|
602
|
+
if start_year and end_year and start_year != end_year:
|
|
603
|
+
target = (start_year + end_year) // 2
|
|
604
|
+
year_desc = f"{start_year}-{end_year}"
|
|
605
|
+
else:
|
|
606
|
+
target = start_year or end_year
|
|
607
|
+
year_desc = str(target)
|
|
608
|
+
|
|
609
|
+
nearest = min(avail_years, key=lambda y: abs(y - target)) if avail_years else None
|
|
610
|
+
|
|
611
|
+
# Distinguish: gap year vs beyond all available data
|
|
612
|
+
if avail_years and (target > max_year or target < min_year):
|
|
613
|
+
df.attrs["query_status"] = "year_beyond_range"
|
|
614
|
+
df.attrs["message"] = (
|
|
615
|
+
f"Year {year_desc} is outside the available data range "
|
|
616
|
+
f"for {countries}. "
|
|
617
|
+
f"Data covers {min_year}-{max_year}. "
|
|
618
|
+
f"Nearest available: {nearest}."
|
|
619
|
+
)
|
|
620
|
+
else:
|
|
621
|
+
df.attrs["query_status"] = "year_not_found"
|
|
622
|
+
df.attrs["message"] = (
|
|
623
|
+
f"No data for {countries} in {year_desc}. "
|
|
624
|
+
f"Data exists for other years: {avail_years}. "
|
|
625
|
+
f"Nearest available: {nearest}."
|
|
626
|
+
)
|
|
627
|
+
|
|
628
|
+
df.attrs["query_indicator"] = indicator_code
|
|
629
|
+
df.attrs["query_countries"] = countries or []
|
|
630
|
+
df.attrs["query_year"] = target
|
|
631
|
+
df.attrs["available_years"] = avail_years
|
|
632
|
+
df.attrs["nearest_year"] = nearest
|
|
633
|
+
_logger.info(df.attrs["message"])
|
|
634
|
+
return df
|
|
635
|
+
|
|
636
|
+
if df_attempt != dataflows_to_try[0]:
|
|
637
|
+
_logger.info(
|
|
638
|
+
f"Successfully fetched '{indicator_code}' using fallback "
|
|
639
|
+
f"dataflow '{df_attempt}' (primary '{dataflows_to_try[0]}' failed)"
|
|
640
|
+
)
|
|
641
|
+
df.attrs["query_status"] = "ok"
|
|
642
|
+
return df
|
|
643
|
+
|
|
526
644
|
except SDMXNotFoundError as e:
|
|
527
645
|
last_error = e
|
|
528
646
|
if df_attempt != dataflows_to_try[-1]:
|
|
@@ -531,24 +649,29 @@ def _fetch_indicator_with_fallback(
|
|
|
531
649
|
f"trying next dataflow..."
|
|
532
650
|
)
|
|
533
651
|
continue
|
|
534
|
-
|
|
652
|
+
|
|
535
653
|
except Exception as e:
|
|
536
654
|
# For non-404 errors, don't try alternatives (fatal errors)
|
|
537
655
|
_logger.error(f"Error fetching '{indicator_code}': {e}")
|
|
538
656
|
raise
|
|
539
|
-
|
|
540
|
-
# All dataflows
|
|
657
|
+
|
|
658
|
+
# All dataflows returned 404 — indicator truly not found
|
|
659
|
+
empty = pd.DataFrame()
|
|
660
|
+
tried_str = ", ".join(dataflows_to_try)
|
|
661
|
+
error_msg = (
|
|
662
|
+
f"Indicator '{indicator_code}' not found in any dataflow.\n"
|
|
663
|
+
f" Tried dataflows: {tried_str}\n"
|
|
664
|
+
f" Browse available indicators at: https://data.unicef.org/"
|
|
665
|
+
)
|
|
666
|
+
empty.attrs["query_status"] = "indicator_not_found"
|
|
667
|
+
empty.attrs["query_indicator"] = indicator_code
|
|
668
|
+
empty.attrs["message"] = error_msg
|
|
669
|
+
_logger.error(error_msg)
|
|
670
|
+
|
|
541
671
|
if last_error:
|
|
542
|
-
tried_str = ", ".join(dataflows_to_try)
|
|
543
|
-
error_msg = (
|
|
544
|
-
f"Not Found (404): Indicator '{indicator_code}' not found in any dataflow.\n"
|
|
545
|
-
f" Tried dataflows: {tried_str}\n"
|
|
546
|
-
f" Browse available indicators at: https://data.unicef.org/"
|
|
547
|
-
)
|
|
548
|
-
_logger.error(error_msg)
|
|
549
672
|
raise SDMXNotFoundError(error_msg)
|
|
550
673
|
|
|
551
|
-
return
|
|
674
|
+
return empty
|
|
552
675
|
|
|
553
676
|
|
|
554
677
|
def _fetch_with_fallback(
|
|
@@ -588,6 +711,7 @@ def _fetch_with_fallback(
|
|
|
588
711
|
_client = UNICEFSDMXClient()
|
|
589
712
|
|
|
590
713
|
dfs = []
|
|
714
|
+
failed_indicators = {} # {indicator_code: {status attrs}}
|
|
591
715
|
for ind in indicators:
|
|
592
716
|
df = _fetch_indicator_with_fallback(
|
|
593
717
|
client=_client,
|
|
@@ -602,11 +726,27 @@ def _fetch_with_fallback(
|
|
|
602
726
|
)
|
|
603
727
|
if not df.empty:
|
|
604
728
|
dfs.append(df)
|
|
605
|
-
|
|
729
|
+
elif df.attrs.get("query_status"):
|
|
730
|
+
failed_indicators[ind] = df.attrs.copy()
|
|
731
|
+
|
|
606
732
|
if not dfs:
|
|
733
|
+
# All indicators failed — return the last empty with status
|
|
734
|
+
if failed_indicators:
|
|
735
|
+
last_key = list(failed_indicators.keys())[-1]
|
|
736
|
+
empty = pd.DataFrame()
|
|
737
|
+
empty.attrs.update(failed_indicators[last_key])
|
|
738
|
+
if len(failed_indicators) > 1:
|
|
739
|
+
empty.attrs["failed_indicators"] = failed_indicators
|
|
740
|
+
return empty
|
|
607
741
|
return pd.DataFrame()
|
|
608
|
-
|
|
609
|
-
|
|
742
|
+
|
|
743
|
+
result = pd.concat(dfs, ignore_index=True)
|
|
744
|
+
if failed_indicators:
|
|
745
|
+
result.attrs["query_status"] = "partial"
|
|
746
|
+
result.attrs["failed_indicators"] = failed_indicators
|
|
747
|
+
else:
|
|
748
|
+
result.attrs["query_status"] = "ok"
|
|
749
|
+
return result
|
|
610
750
|
|
|
611
751
|
|
|
612
752
|
# =============================================================================
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: unicefdata
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.0
|
|
4
4
|
Summary: Python library for downloading UNICEF indicators via SDMX API
|
|
5
5
|
Author-email: Joao Pedro Azevedo <jpazevedo@unicef.org>
|
|
6
6
|
License: MIT
|
|
@@ -82,6 +82,24 @@ print(unicefdata.__version__)
|
|
|
82
82
|
|
|
83
83
|
---
|
|
84
84
|
|
|
85
|
+
## What's New in 2.4.0
|
|
86
|
+
|
|
87
|
+
- **Query status codes**: Empty results now tell you *why* via `df.attrs["query_status"]`:
|
|
88
|
+
- `year_not_found` — country has data, but not for the requested year (gap in time series)
|
|
89
|
+
- `year_beyond_range` — requested year is before the earliest or after the latest data point
|
|
90
|
+
- `country_not_found` — indicator exists but not for this country (includes `available_countries`)
|
|
91
|
+
- `indicator_not_found` — indicator doesn't exist in any dataflow
|
|
92
|
+
- **Client-side year filtering**: Fixes 6 survey-based indicators (NUTRITION, MNCH, EDUCATION) that failed with year filters due to an SDMX API quirk
|
|
93
|
+
- **Smarter fallback logic**: No longer wastes API calls trying non-existent fallback dataflows when data simply doesn't exist for the requested country/year
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
df = unicefData("MNCH_CSEC", countries=["BRA"], year=2020)
|
|
97
|
+
# len(df) == 0
|
|
98
|
+
print(df.attrs["query_status"]) # "year_not_found"
|
|
99
|
+
print(df.attrs["available_years"]) # [2000, 2001, ..., 2019]
|
|
100
|
+
print(df.attrs["nearest_year"]) # 2019
|
|
101
|
+
```
|
|
102
|
+
|
|
85
103
|
## What's New in 2.2.2
|
|
86
104
|
|
|
87
105
|
- **`UNICEFSDMXClient` dataflow resolution fixed**: `fetch_indicator()` now auto-detects the correct dataflow from metadata instead of always defaulting to `GLOBAL_DATAFLOW`, consistent with `unicefData()`
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/_dataflow_fallback_sequences.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/_unicefdata_codelists.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/_unicefdata_countries.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/_unicefdata_dataflows.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/_unicefdata_indicators.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CAUSE_OF_DEATH.yaml
RENAMED
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CHILD_RELATED_SDG.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_CAUSE_OF_DEATH.yaml
RENAMED
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_DF_2021_WQ.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNATIONAL.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_AGO.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_BDI.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_BEN.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_BGD.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_CMR.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_ETH.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_GHA.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_GIN.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_HTI.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_KEN.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_LAO.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_LBR.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_LSO.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_MDG.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_MLI.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_MMR.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_MRT.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_MWI.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_NAM.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_NGA.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_NPL.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_PAK.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_RWA.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_SEN.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_SLE.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_TCD.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_TGO.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_TZA.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_UGA.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_ZMB.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/CME_SUBNAT_ZWE.yaml
RENAMED
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/COVID_CASES.yaml
RENAMED
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/DM_PROJECTIONS.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/EDUCATION_FLS.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/EDUCATION_UIS_SDG.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/FUNCTIONAL_DIFF.yaml
RENAMED
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/GLOBAL_DATAFLOW.yaml
RENAMED
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/IMMUNISATION.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/PT_CM_SUBNATIONAL.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/PT_CONFLICT.yaml
RENAMED
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/SDG_PROG_ASSESSMENT.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/SOC_PROTECTION.yaml
RENAMED
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/WASH_HOUSEHOLDS.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/WASH_HOUSEHOLD_MH.yaml
RENAMED
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/dataflows/WASH_SCHOOLS.yaml
RENAMED
|
File without changes
|
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/current/unicef_indicators_metadata.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-03/codelists.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-03/dataflows.yaml
RENAMED
|
File without changes
|
{unicefdata-2.3.2 → unicefdata-2.4.0}/unicefdata/metadata/vintages/2025-12-03/indicators.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|