Skip to content

Guard spatial lag enrichment for small universes - #367

Open
mividtim wants to merge 1 commit into
larsiusprime:masterfrom
fabrica-land:hobnob/eng-3031-spatial-lag-guard-on-3290
Open

mividtim wants to merge 1 commit into
larsiusprime:masterfrom
fabrica-land:hobnob/eng-3031-spatial-lag-guard-on-3290

Conversation

@mividtim

Copy link
Copy Markdown

Summary

Adds a guard around _enrich_universe_spatial_lag so spatial-lag enrichment does not crash when the universe is smaller than the requested neighbor count.

Why

Small or heavily filtered universes can have fewer parcels than k; the nearest-neighbor model should degrade gracefully instead of raising.

Validation

  • Added regression coverage in tests/test_data.py for one-row and zero-training small-universe cases.
  • Included in the fabrica-land integration branch; py-compile validation passed there.
  • Full upstream CI should run the complete pytest matrix.

cKDTree.query(..., k=k) returns an out-of-range sentinel index when the
universe has fewer training parcels than k, raising IndexError at
parcel_values[indices]. Add an n_train==0 early return and clamp
k = min(k, n_train), mirroring the sales-side guard in
_enrich_sup_spatial_lag_for_model_group. Fixes a crash when spatial-lag
enrichment runs on sparse universes (Fabrica ENG-3031).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution.
Please sign our CLA at the following link:
Click here to sign the CLA.

No action is required from you in this PR thread. Once you have signed the CLA externally, a maintainer will verify your signature and record it here on your behalf by commenting:


I affirm that this contributor has signed the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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