Skip to content

Modernize harmony.py / retire the per-country food_prices_quantities_and_expenditures.py family #218

Description

@ligon

Background

lsms_library/harmony.py is a CLI cross-country consistency check that predates the Country API. It directly reads the legacy var/food_expenditures.parquet, var/food_prices.parquet, and var/household_characteristics.parquet for a given country, then uses local_tools.add_markets_from_other_features (whose only call site is harmony.py itself) to attach a market index via the obsolete other_features infrastructure (per CLAUDE.md).

Verified zero callers anywhere in the repo: notebooks, tests, scripts, docs, makefiles all clean. The helper it imports (add_markets_from_other_features) is similarly orphan.

Cascade

The legacy parquets harmony reads are produced by per-country food_prices_quantities_and_expenditures.py scripts. They currently exist in 12 countries: Afghanistan, Burkina_Faso, Cambodia, CotedIvoire, Ethiopia, GhanaLSS, GhanaSPS, Guatemala, Malawi, Panama, Senegal, Tanzania.

For 11 of these, the framework's _FOOD_DERIVED path in country.py:2541-2571 shadows the legacy outputs — Country(X).food_expenditures() / .food_prices() / .food_quantities() derive from food_acquired via transformations.food_*_from_acquired rather than reading the legacy parquets. The legacy script's outputs are written but never read by the Country API.

Uganda is the exception: derivation fails because food_acquired lacks a single Expenditure column (split into value_home/away/own/inkind). Per CLAUDE.md, blocked on #169 (canonical food_acquired columns).

Proposed direction

  1. Modern equivalent of harmony's checks, Country-API-based. Sketch:
    • Country(X).consistency_check() (or top-level lsms_library.harmony.audit(country)) calls Country(X).food_expenditures(), .food_prices(), .household_characteristics(), runs the same index-orientation / market-attachment / label-overlap assertions, raises clearly on failure.
    • All inputs go through _finalize_result (kinship expansion, canonical spelling, id_walk), so the audit operates on the canonical API form rather than the raw legacy parquet form.
  2. Once the modern equivalent exists, retire the per-country food_prices_quantities_and_expenditures.py (12 files, ~290 lines), the corresponding Makefile rules, the orphan local_tools.add_markets_from_other_features helper, and lsms_library/harmony.py itself. Leave Uganda alone until Design: food_acquired canonical columns (+ cascade to food_prices, food_quantities) #169 lands.

First step

A linked PR does Phase 1 for Malawi only — removes Malawi's instance of the legacy script (whose outputs are already shadowed), trims dead helpers in Malawi/_/malawi.py, and updates the Makefile / CONTENTS.org accordingly. Treats Malawi as the proof-of-concept for the cross-country pattern.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions