Skip to content

Mongolia_Employment: Fix duplicate region formation and missing references in registered unemployment - #2216

Open
kartik-s21 wants to merge 60 commits into
datacommonsorg:masterfrom
kartik-s21:fix-mongolia-employment-missing-refs
Open

kartik-s21 wants to merge 60 commits into
datacommonsorg:masterfrom
kartik-s21:fix-mongolia-employment-missing-refs

Conversation

@kartik-s21

@kartik-s21 kartik-s21 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Import validation for Mongolia_Employment failed with Found 7366 missing references in input 5 (registered_unemployed_by_education_level_region_gender_month`).

Root Cause

  1. Upstream NSO API table DT_NSO_0400_002V5.px contains both code 5 ("Ulaanbaatar") and duplicate indented code 511 (" Ulaanbaatar").
  2. When whitespace is stripped during processing, both resolve to wikidataId/Q23430.
  3. For months 2008-01 through 2011-09, code 511 contains conflicting counts (234, 0, ..), causing 430 mismatched duplicate SVObs.
  4. stat_var_processor.py flagged 10 StatVars with #ErrorDuplicateSVObs and dropped them from the generated MCF, including newly defined schema StatVar Count_Person_Unemployed_UpperSecondaryEducation.
  5. Observations in the output CSV referencing Count_Person_Unemployed_UpperSecondaryEducation failed reference existence checks in validation (3,683 rows × 2 passes = 7,366 missing references).

Solution

  • Configured Бүс in common_download_script.py for registered_unemployed_by_education_level_region_gender_month.csv to exclude code 511 and keep all 27 valid regions.
  • Passed table.get('query') for EMPLOYMENT_TABLES in common_download_script.py.
  • Added defense-in-depth sanitization in run.sh before running input 5 to strip any indented duplicate Ulaanbaatar rows from existing input files.
  • Added test coverage in common_download_script_test.py.

Verification

  • Tested with stat_var_processor.py:
    • error-mismatched-svobs: 430 -> 0
    • error-statvar-with-dup-svobs: 10 -> 0
    • dropped-invalid-statvars: 10 -> 0
    • Output StatVars in MCF: 27 / 27 (all generated, including Count_Person_Unemployed_UpperSecondaryEducation)
    • Output places: 23 (country/MNG + 22 aimags/capital, matching golden data)
    • Missing reference count: 0 (PASS)
  • Ran python3 -m unittest statvar_imports/mongolia_imports/common_download_script_test.py (7/7 passed).
  • Ran Cloud Batch Job (test env) - link
  • Validation Output - input0 input1 input2 input3 input4 input5

Documentation

  • CRA Report - link
  • Postmortem Report - link

@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 a query filter to the Mongolian registered unemployed data download configuration to exclude duplicate Ulaanbaatar entries, along with a corresponding unit test. It also updates the execution script to strip duplicate indented Ulaanbaatar entries from the downloaded CSV using sed. Feedback was provided regarding the portability of sed -i across macOS and Linux, suggesting the use of a temporary file instead.

Comment thread statvar_imports/mongolia_imports/mongolia_employment/run.sh Outdated
@kartik-s21 kartik-s21 changed the title Mongolia_Employment: Fix duplicate Ulaanbaatar and missing references in registered unemployment Mongolia_Employment: Fix duplicate region formation and missing references in registered unemployment Sep 9, 2026
…rg#2216

- Use co-located temporary file, atomic move, non-empty check, and exit trap in run.sh
- Forward table.get('query') uniformly across all domain table loops in common_download_script.py
- Add unit test verifying runtime query parameter propagation in common_download_script_test.py
- Add MAX_DATE_CONSISTENT and SQL_VALIDATOR date freshness rules to validation_config.json
Comment thread statvar_imports/mongolia_imports/mongolia_employment/run.sh
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.

3 participants