The donor reader reads a blank household cost as zero before validation

Aperta Adatta ai principianti
#1,701 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
numpy, pandas, python
Ambito
data

Direzione di ricerca

Parti dall'inversa di AllocateToReferencePerson in concept_mapping.py:2728-2734 (a 9505a0da1c), le tre righe che convertono in float64, sommano per nucleo familiare e riempiono con 0. Poi leggi il chiamante read_populace_us_donor e il blocco di validazione in transport.py:868-876, l'unico punto in cui questa decodifica viene usata e dove lo 0 sfugge ai controlli di null, non finito e limiti. È completato quando un valore sorgente vuoto, non finito o non reale viene rifiutato prima della somma, con un test per caso; riutilizza la sonda della issue per confermare entrambi i casi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

read_populace_us_donor decodes three household costs from person columns: rent from pre_subsidy_rent, mortgage interest from home_mortgage_interest and property tax from real_estate_taxes. Each binding uses AllocateToReferencePerson, and its inverse (concept_mapping.py:2728-2734 at 9505a0da1c) casts the person column to float64, sums it by household and fills a household with no persons with 0.

pandas skips blanks in that sum. A household whose persons all hold a blank cost reads 0, and a blank beside a value reads as that value. The cast also drops the imaginary part of a complex value, with a ComplexWarning and no error.

The reader validates the decoded tables next (transport.py:876). Its checks for nulls, non-finite values and bounds would refuse a blank cost, but they receive 0, so the reader accepts the donor. Only the reader calls this decode (transport.py:868).

A probe with the inverse's three lines shows both cases:

invert(pd.Series([np.nan, 5.0, np.nan]), person_household=[1, 1, 2], households=[1, 2, 3])
# array([5., 0., 0.])
invert(pd.Series([7 + 99j, 1 + 0j]), person_household=[1, 2], households=[1, 2])
# array([7., 1.]), with a ComplexWarning

I have not checked whether any donor file in use holds a blank in these columns.

A fix could refuse a blank, non-finite or non-real value in the source column before the sum, with one test per case. The check of #1698 found this; #1698 leaves decode unchanged, and its profiled read and the plain read decode these costs the same way.

Lingua principale
Python
Stelle
0
Fork
6
Merge medio
1g 17h
PR unite (30g)
190

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PolicyEngine/microcosm

Tutte le issue di PolicyEngine/microcosm

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.