Skip to content

Fix FAO_Currency_statvar Golden Validation Error - #2284

Open
shvngisingh wants to merge 2 commits into
datacommonsorg:masterfrom
shvngisingh:fix-fao-currency-statvar
Open

shvngisingh wants to merge 2 commits into
datacommonsorg:masterfrom
shvngisingh:fix-fao-currency-statvar

Conversation

@shvngisingh

@shvngisingh shvngisingh commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

FAO_Currency_statvar: Fix Naoero Place Mapping and Update Validation Config

1. Overview

Fixes the weekly production validation failure in FAO_Currency_statvar (statvar_imports/fao_currency_and_exchange_rate/fao_currency_statvar:FAO_Currency_statvar, e.g., Cloud Batch job fao-currency-statvar-1792047600) where check_goldens_summary_report and check_goldens_output_csv failed and 791 Nauru (dcid:country/NRU) observations were dropped.


2. Root Cause & Changes

Two upstream changes in the FAO source file (Exchange_rate_E_All_Data.csv) caused the failure:

  1. Upstream Place Rename ("Nauru" -> "Naoero") — CurrencyFAO_place_map.csv:

    • Upstream FAO renamed Nauru (Area Code = 148, M49 = '520) to "Naoero".
    • Because Naoero was missing from CurrencyFAO_place_map.csv, stat_var_processor.py dropped all 791 dcid:country/NRU observations (1:process_input_dropped-svobs-unresolved-place: 791), reducing NumPlaces by 1 for two Australian Dollar (AUD) StatVars (LocalCurrency_ExchangeRate_Currency_FromCurrency_USD_ToCurrency_AUD: 6 -> 5; StandardizedCurrency_ExchangeRate_Currency_FromCurrency_USD_ToCurrency_AUD: 4 -> 3).
    • Fix: Added Naoero,country/NRU to CurrencyFAO_place_map.csv (retaining Nauru,country/NRU for backward compatibility), restoring all 791 country/NRU observations (150,346 -> 151,137 rows) and returning NumPlaces to 6 and 4.
  2. Brittle Static Golden Checks on Upstream Historical Backfills — manifest.json, validation_config.json, & golden_data/:

    • Upstream FAO backfilled monthly (January–December, mapped to P1M) rows in addition to Annual value for Lao PDR (LAJ, +120 observations) and Mauritania (MRU, +103 observations), updating observationPeriods in summary_report.csv from "[P1Y]" to "[P1Y, P1M]".
    • Fix: Removed the static golden_data/ directory (golden_observations.csv and golden_summary_report.csv), removed "golden_data/*.csv" from source_files in manifest.json, and updated validation_config.json to replace static GOLDENS_CHECK rules with dynamic validation rules:
      • check_deleted_records_percent (DELETED_RECORDS_PERCENT, threshold: 0.1)
      • check_min_value (MIN_VALUE_CHECK, minimum: 0 — verifies non-negativity across all 429 StatVars, noting that 22 historical pre-redenomination hyperinflation currencies have 1970s–1990s rates < 5e-6 that round to 0.0 at stat_var_processor.py's default 5-decimal precision)
      • check_num_places_count (NUM_PLACES_COUNT, minimum: 1)
      • check_positive_exchange_rate_values (SQL_VALIDATOR — verifies MaxValue > 0 across all 429 StatVars and MinValue > 0 across all 407 non-redenominated StatVars)
      • check_active_currency_date_freshness (SQL_VALIDATOR — verifies monthly LocalCurrency_ active major currencies EUR|INR|GBP|JPY|CAD|AUD|CHF|CNY have MaxDate >= '2026-01' and all 149 active annual StandardizedCurrency_ series have MaxDate >= '2025')
      • Plus inherited default checks (check_empty_import, check_missing_refs_count, check_lint_error_count).

3. Testing & Verification

  • Hermetic Unit Tests: ./run_tests.sh -p statvar_imports/fao_currency_and_exchange_rate/fao_currency_statvar (1/1 PASSED in 0.001s).
  • Cloud Batch Test Job (datcom-infosys-dev, against Prod Baseline 2026_09_10T00_03_06_615047_07_00):
    • Job ID: fao-currency-statvar-shvngisingh-20261023-082902 (uid: fao-currency-statv-96bb9749-8659-4f990)
    • Status: SUCCEEDED (ImportStatus.STAGING, num_rows_processed: 151,137, execution_time: 1254s)
    • Staging GCS URI: gs://datcom-import-test/statvar_imports/fao_currency_and_exchange_rate/fao_currency_statvar/FAO_Currency_statvar/2026_10_23T01_32_10_227337_07_00/ (Pantheon Link)
    • Differ Summary (input0/validation/differ_summary.json): current_obs_count: 151,137, previous_obs_count: 145,749, added_obs_count: 5,391, deleted_obs_count: 3 (0.0021%), modified_obs_count: 1,402 (Pantheon Link)
    • Validation Results (input0/validation/validation_output.csv) — 8/8 Rules PASSED (Pantheon Link):
ValidationName Status Details ValidationParams
check_deleted_records_percent PASSED {"deleted_records_count": 3, "previous_obs_count": 145749, "percent": 0.0020583331618055697, "threshold": 0.1} {"threshold": 0.1}
check_empty_import PASSED {"num_nodes": 151137, "num_rows": 151137}
check_missing_refs_count PASSED {"missing_refs_count": 0} {"threshold": 0}
check_lint_error_count PASSED {"lint_error_count": 0} {"threshold": 0}
check_min_value PASSED {"rows_processed": 429, "rows_succeeded": 429, "rows_failed": 0} {"minimum": 0}
check_num_places_count PASSED {"rows_processed": 429, "rows_succeeded": 429, "rows_failed": 0} {"minimum": 1}
check_positive_exchange_rate_values PASSED {"query": "SELECT StatVar, MinValue, MaxValue FROM stats", "condition": "MaxValue > 0 AND (MinValue > 0 OR regexp_matches(StatVar, '_ToCurrency_(AOA|AOK|AON|AOS|ARP|ARS|BRB|BRC|BRN|BRL|BYN|CDF|GEL|NIC|NIG|NIO|PEN|PES|RSD|TMT|VED|ZRZ)$'))"}
check_active_currency_date_freshness PASSED {"query": "SELECT StatVar, MaxDate FROM stats WHERE regexp_matches(StatVar, '_ToCurrency_(EUR|INR|GBP|JPY|CAD|AUD|CHF|CNY)$') OR (StatVar LIKE 'StandardizedCurrency_%' AND NOT regexp_matches(StatVar, '_ToCurrency_(YUN|CSK|NIO)$'))", "condition": "(StatVar LIKE 'LocalCurrency_%' AND MaxDate >= '2026-01') OR (StatVar LIKE 'StandardizedCurrency_%' AND MaxDate >= '2025')"}

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds 'Naoero' mapped to 'country/NRU' in the FAO currency place map CSV file. Additionally, it updates two entries in the golden summary report CSV file to include '[P1Y, P1M]' instead of '[P1Y]'. There are no review comments to address, and I have no feedback to provide.

@shvngisingh
shvngisingh force-pushed the fix-fao-currency-statvar branch 2 times, most recently from d63d19d to 39188bc Compare October 21, 2026 07:37
@shvngisingh
shvngisingh force-pushed the fix-fao-currency-statvar branch from 39188bc to a8d4d83 Compare October 21, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant