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

未关闭 适合新手
#1,701 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
numpy, pandas, python
领域
data

调研方向

从 concept_mapping.py:2728-2734(提交 9505a0da1c)中 AllocateToReferencePerson 的逆向函数开始,即转换为 float64、按住户求和并用 0 填充的三行代码。然后阅读调用方 read_populace_us_donor 以及 transport.py:868-876 的校验代码块,这是该解码唯一被使用的地方,0 在这里绕过了空值、非有限值和范围检查。完成标准是:在求和之前拒绝空的、非有限的或非实数的源值,每种情况各有一个测试;复用 issue 中的探针来确认这两种情况。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
0
派生
6
平均合并
1 天 17 小时
30 天内合并 PR
190

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

PolicyEngine/microcosm 的其他 Issue

查看 PolicyEngine/microcosm 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。