Skip to content

Reformat NSSP county zip code #1976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nssp/delphi_nssp/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
"timestamp": "datetime64[ns]",
"geography": str,
"county": str,
"fips": int,
"fips": str,
}
)
3 changes: 3 additions & 0 deletions nssp/delphi_nssp/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,8 @@ def pull_nssp_data(socrata_token: str):
except KeyError as exc:
raise ValueError(warn_string(df_ervisits, TYPE_DICT)) from exc

# Format county fips to all be 5 digits with leading zeros
df_ervisits["fips"] = df_ervisits["fips"].apply(lambda x: str(x).zfill(5) if str(x) != "0" else "0")

keep_columns = ["timestamp", "geography", "county", "fips"]
return df_ervisits[SIGNALS + keep_columns]
21 changes: 21 additions & 0 deletions nssp/tests/test_data/page.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,26 @@
"hsa_nci_id": "All",
"fips": "0",
"trend_source": "United States"
},
{
"week_end": "2023-05-13T00:00:00.000",
"geography": "Colorado",
"county": "Jefferson",
"percent_visits_combined": "0.84",
"percent_visits_covid": "0.59",
"percent_visits_influenza": "0.23",
"percent_visits_rsv": "0.03",
"percent_visits_smoothed": "0.83",
"percent_visits_smoothed_covid": "0.62",
"percent_visits_smoothed_1": "0.18",
"percent_visits_smoothed_rsv": "0.02",
"ed_trends_covid": "Decreasing",
"ed_trends_influenza": "No Change",
"ed_trends_rsv": "Decreasing",
"hsa": "Denver (Denver), CO - Jefferson, CO",
"hsa_counties": "Adams, Arapahoe, Clear Creek, Denver, Douglas, Elbert, Gilpin, Grand, Jefferson, Park, Summit",
"hsa_nci_id": "688",
"fips": "8059",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just confirming, this is a test example with 4 rather than 5 digits to make sure it bumps to 5?

"trend_source": "HSA"
}
]
1 change: 1 addition & 0 deletions nssp/tests/test_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_pull_nssp_data(self, mock_socrata):
assert result["geography"].notnull().all(), "geography has rogue NaN"
assert result["county"].notnull().all(), "county has rogue NaN"
assert result["fips"].notnull().all(), "fips has rogue NaN"
assert result["fips"].apply(lambda x: isinstance(x, str) and len(x) != 4).all(), "fips formatting should always be 5 digits; include leading zeros if aplicable"

# Check for each signal in SIGNALS
for signal in SIGNALS:
Expand Down
Loading