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

Đang mở Phù hợp với người mới
#1,701 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
numpy, pandas, python
Lĩnh vực
data

Hướng nghiên cứu

Bắt đầu từ phép nghịch đảo của AllocateToReferencePerson trong concept_mapping.py:2728-2734 (tại 9505a0da1c), ba dòng ép kiểu sang float64, cộng theo hộ gia đình và điền bằng 0. Sau đó đọc hàm gọi read_populace_us_donor và khối kiểm tra hợp lệ tại transport.py:868-876, nơi duy nhất sử dụng phép giải mã này và là chỗ số 0 lọt qua các kiểm tra null, không hữu hạn và giới hạn. Hoàn thành khi một giá trị nguồn rỗng, không hữu hạn hoặc không phải số thực bị từ chối trước khi cộng, với một kiểm thử cho mỗi trường hợp; tái sử dụng probe trong issue để xác nhận cả hai trường hợp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
0
Fork
6
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
190

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của PolicyEngine/microcosm

Tất cả issue của PolicyEngine/microcosm

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.