FrenchCastle's picture
v1.1.0: consolidated panel + panel_dictionary, isora.py loader, World Bank income groups (current + per fiscal year), thousands flag on derived expenditure aggregates
9f0fcd7 verified
Raw History Blame Contribute Delete
4.43 kB
"""Constants shared by the pipeline: API endpoints, dataflows, rounds, sentinel codes, paths."""
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[2]
RAW_DIR = PROJECT_ROOT / "raw"
RAW_DATA_DIR = RAW_DIR / "data"
RAW_STRUCTURES_DIR = RAW_DIR / "structures"
OUT_DIR = PROJECT_ROOT / "hf_dataset"
SDMX3_BASE = "https://api.imf.org/external/sdmx/3.0"
SDMX21_BASE = "https://api.imf.org/external/sdmx/2.1"
AGENCY = "ISORA"
USER_AGENT = "isora-hf/0.1 (+https://huggingface.co; data pipeline; contact via dataset card)"
ISORA_PORTAL_URL = "https://data.imf.org/en/datasets/ISORA:ISORA_LATEST_DATA_PUB"
TERMS_URL = "https://data.imf.org/en/Datasets/RAFIT-Consolidated/Terms-and-Conditions"
DISCLAIMER_URL = "https://data.imf.org/en/Datasets/RAFIT-Consolidated/Disclaimer"
ABOUT_URL = "https://data.imf.org/en/Datasets/RAFIT-Consolidated/About-RA-FIT"
@dataclass(frozen=True)
class Dataflow:
"""One published ISORA dataflow (a questionnaire generation)."""
id: str
version: str
dsd_version: str
generation: str # human-readable questionnaire generation
fiscal_years: tuple[int, ...]
geo_dimension: str # COUNTRY (numeric IMF codes) or JURISDICTION (alpha-3)
indicator_codelist: str
form_status_attr: str
DATAFLOWS: tuple[Dataflow, ...] = (
Dataflow(
id="ISORA_2016_DATA_PUB",
version="2.0.0",
dsd_version="1.0.0",
generation="ISORA 2016",
fiscal_years=(2014, 2015),
geo_dimension="COUNTRY",
indicator_codelist="CL_INDICATOR",
form_status_attr="FORM_STATUS",
),
Dataflow(
id="ISORA_2018_DATA_PUB",
version="2.0.0",
dsd_version="2.0.0",
generation="ISORA 2018",
fiscal_years=(2016, 2017),
geo_dimension="JURISDICTION",
indicator_codelist="CL_ISORA_TAX",
form_status_attr="FORMSTATUS",
),
Dataflow(
id="ISORA_LATEST_DATA_PUB",
version="5.0.0",
dsd_version="6.0.0",
generation="ISORA 2020+",
fiscal_years=(2018, 2019, 2020, 2021, 2022, 2023, 2024),
geo_dimension="JURISDICTION",
indicator_codelist="CL_ISORA_TAX",
form_status_attr="FORMSTATUS",
),
)
# Older published versions of the consolidated dataflow, still served by the API.
# They are earlier release vintages of the same FY2018+ series and let us track revisions.
VINTAGES: tuple[tuple[str, str, str], ...] = (
# (dataflow version, release label, fiscal years covered)
("2.0.0", "ISORA 2023 release (FY2018-FY2022)", "2018-2022"),
("4.0.0", "ISORA 2024 release (FY2018-FY2023)", "2018-2023"),
("5.0.0", "ISORA 2025 release (FY2018-FY2024)", "2018-2024"),
)
# Fiscal year -> survey round in which that fiscal year was first collected.
FISCAL_YEAR_TO_ROUND: dict[int, str] = {
2014: "ISORA 2016",
2015: "ISORA 2016",
2016: "ISORA 2018",
2017: "ISORA 2018",
2018: "ISORA 2020",
2019: "ISORA 2020",
2020: "ISORA 2021",
2021: "ISORA 2022",
2022: "ISORA 2023",
2023: "ISORA 2024",
2024: "ISORA 2025",
}
# Published participation counts (About ISORA page + ISORA 2025 news item), for the card.
ROUND_PARTICIPATION: dict[str, int] = {
"ISORA 2016": 135,
"ISORA 2018": 159,
"ISORA 2020": 156,
"ISORA 2021": 156,
"ISORA 2022": 165,
"ISORA 2023": 166,
"ISORA 2024": 164,
"ISORA 2025": 166,
}
# Sentinel strings found in the OBSERVATION column.
NOT_AVAILABLE_CODES = frozenset({"D"})
NOT_APPLICABLE_STRINGS = frozenset({"not applicable", "n/a", "na"})
UNRECOGNIZED_CODES = frozenset({"P"}) # ISORA 2016 only; not documented in surviving material
# DissemScale annotation -> normalized indicator type
INDICATOR_TYPE_MAP: dict[str, str] = {
"binary": "binary",
"counting": "count",
"currency": "currency",
"percent": "percent",
"nominal": "nominal",
"ordinal": "ordinal",
"text": "text",
"date": "date",
"na": "unspecified",
"": "unspecified",
}
# Derived level aggregates in the consolidated dataflow that are published in thousands of local
# currency with SCALE=0 (verified: they equal ~1/1000 of net revenue x cost-of-collection ratio),
# unlike the raw money questions which carry SCALE=3 and are already in base units.
LATEST_THOUSANDS_CODES = frozenset({"337_176", "337_177", "337_178", "337_179"})