Skip to content

Feature('sample') oddities: int_t leak, Rural spellings, China/Azerbaijan weight quality #163

Description

@ligon

Sibling of #161 (Uganda cluster_features) and #162 (cross-country stray i).
Feature('sample') is structurally much healthier — no duplicate indices, no stray
i column — but it surfaces a separate set of issues worth tracking.

Summary

489,406 rows, 32 countries, clean (country, i, t) MultiIndex, no duplicates.

Issues

1. Stray int_t column (severity: medium)

int_t (dtype float64, 467,703 / 489,406 non-null) leaks into the sample output
despite belonging in interview_date. Almost certainly a wave-level data_info.yml
declaring int_t under a sample: stanza when it should be under
interview_date:. Grep across all countries to find the offenders.

2. China weight entirely null

China's sample DataFrame has 787 rows, all 787 with weight = <NA>. The
optional: true override applied in the v0.7.0 release makes this schema-valid,
but the data gap is real and worth a sanity check — is China's sample frame
genuinely unweighted, or did a mapping silently drop the column?

3. Rural spelling inconsistencies (canonical spellings gaps)

Rural        275290
Urban        178609
rural          5790   # lowercase variant — should map to 'Rural'
urban          4090   # lowercase variant — should map to 'Urban'
0              2263   # numeric code — some country has 0 for a category
Semi-urban     1578   # genuine third category
Informal         83   # genuine fourth category

Roughly 10K rows with case variants that the canonical spellings dict in
lsms_library/data_info.yml should catch but doesn't. 0 (2,263 rows) is a
numeric code that needs an explicit mapping: block in whichever country's wave
YAML surfaces it.

Suggested fixes:

  • Add rural, urban (lowercase) to the spellings lists for Rural/Urban in
    data_info.yml. Alternatively, apply .str.title() normalization in
    _enforce_canonical_spellings.
  • Locate the country producing '0' for Rural and map it.
  • Semi-urban / Informal are legitimate — should stay in the canonical set
    rather than being coerced to Rural/Urban.

4. Azerbaijan weights look like a fallback

Azerbaijan 1995 sample has 2,016 rows but the weight column has only 3
distinct values
(min 0.694, max 1.258). That's an extremely uniform
distribution and may indicate a default / fallback weight rather than true
survey weights. Worth verifying against the raw microdata (PP.dta per
the data_info.yml).

5. Resource-handle leak (minor / benign)

lsms_library/country.py:831 appears to load YAML without with context, leaving
file handles unclosed. Not behaviorally broken but flagged by the audit pipeline.

Out of scope

Not a release blocker — v0.7.0 has shipped. Queueing here for a v0.7.1 or
later cleanup pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions