Skip to content

Commit

Permalink
export: support float ages, convert to integers
Browse files Browse the repository at this point in the history
Rarely ages are in float, this is more precision than necessary,
so they are converted to integers. This fixes a ValueError
encountered on float ages
  • Loading branch information
abhidg committed Oct 15, 2022
1 parent 93c04ce commit 965f4d9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions data-serving/scripts/export-data/test_convert_age.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ demographics.ageRange.start,demographics.ageRange.end,demographics.ageBuckets
0,0,[]
,,["0"]
,,"[""26-30"",""31-35""]"
1.5,1.5,[]
2 changes: 1 addition & 1 deletion data-serving/scripts/export-data/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def convert_age_data():
"row,expected_age",
zip(convert_age_data(), [
(20, 30), (21, 25), None, (21, 25),
(20, 30), (0, 0), (0, 0), (26, 35)
(20, 30), (0, 0), (0, 0), (26, 35), (1, 5),
])
)
def test_convert_age(row, expected_age, age_buckets):
Expand Down
4 changes: 2 additions & 2 deletions data-serving/scripts/export-data/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ def convert_age(row: dict[str, Any], buckets: list[dict[str, Any]]) -> Optional[
):
return None

age_start = int(row["demographics.ageRange.start"])
age_end = int(row["demographics.ageRange.end"])
age_start = int(float(row["demographics.ageRange.start"]))
age_end = int(float(row["demographics.ageRange.end"]))
age_window = age_end - age_start + 1

if age_window >= MINIMUM_AGE_WINDOW:
Expand Down

0 comments on commit 965f4d9

Please sign in to comment.