-
Notifications
You must be signed in to change notification settings - Fork 16
Find Unexpected Values for geo_id #426
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
Changes from 6 commits
5d8f220
f2562e6
ac28c33
0ea0a79
69881a4
06ba36c
538d98e
45046cb
ad32bd3
42ad65e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,7 @@ def __init__(self, params): | |
""" | ||
# Get user settings from params or if not provided, set default. | ||
self.data_source = params['data_source'] | ||
self.validator_static_file_dir = params.get('validator_static_file_dir', '../validator/static') | ||
|
||
# Date/time settings | ||
self.span_length = timedelta(days=params['span_length']) | ||
|
@@ -244,9 +245,26 @@ def check_df_format(self, df_to_test, nameformat): | |
|
||
self.increment_total_checks() | ||
|
||
def check_bad_geo_id(self, df_to_test, nameformat, geo_type): | ||
def check_bad_geo_id_value(self, df_to_test, filename, geo_type): | ||
""" | ||
Check validity of geo type and values, according to regex pattern. | ||
Check for bad geo_id values, by comparing to a list of known values (drawn from historical data) | ||
|
||
Arguments: | ||
- df_to_test: pandas dataframe of CSV source data containing the geo_id column to check | ||
- geo_type: string from CSV name specifying geo type (state, county, msa, etc.) of data | ||
""" | ||
file_path = join(self.validator_static_file_dir, geo_type + '_geo.csv') | ||
valid_geo_df = pd.read_csv(file_path, dtype = {'geo_id': str}) | ||
valid_geos = valid_geo_df['geo_id'].values | ||
unexpected_geos = [geo for geo in df_to_test['geo_id'] if geo not in valid_geos] | ||
if len(unexpected_geos) > 0: | ||
self.raised_errors.append(ValidationError( | ||
("check_bad_geo_id_value", filename), | ||
unexpected_geos, "Unrecognized geo_ids (not in historical data)")) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Increment check counter with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this still need to be fixed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in latest commit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, waiting on this and a few other changes! |
||
def check_bad_geo_id_format(self, df_to_test, nameformat, geo_type): | ||
""" | ||
Check validity of geo_type and format of geo_ids, according to regex pattern. | ||
|
||
Arguments: | ||
- df_to_test: pandas dataframe of CSV source data | ||
|
@@ -720,8 +738,9 @@ def validate(self, export_dir): | |
data_df = load_csv(join(export_dir, filename)) | ||
|
||
self.check_df_format(data_df, filename) | ||
self.check_bad_geo_id( | ||
self.check_bad_geo_id_format( | ||
data_df, filename, match.groupdict()['geo_type']) | ||
self.check_bad_geo_id_value(data_df, filename, match.groupdict()['geo_type']) | ||
self.check_bad_val(data_df, filename, match.groupdict()['signal']) | ||
self.check_bad_se(data_df, filename) | ||
self.check_bad_sample_size(data_df, filename) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
library(covidcast) | ||
|
||
geo_types = c("county", "state", "hrr", "msa") | ||
for(type in geo_types){ | ||
dtf = covidcast_signal("indicator-combination", "confirmed_7dav_incidence_num", start_day = "2020-10-01", end_day = "2020-10-01", geo_type = type) | ||
file_name = paste0("../static/", type, "_geo.csv") | ||
write.table(unique(dtf$geo_value), file = file_name, row.names = F, col.names = "geo_id") | ||
} | ||
|
||
dtf = covidcast_signal("ght", "raw_search", start_day = "2020-10-01", end_day = "2020-10-01", geo_type = "dma") | ||
file_name = paste0("../static/dma_geo.csv") | ||
write.table(unique(dtf$geo_value), file = file_name, row.names = F, col.names = "geo_id") |
Uh oh!
There was an error while loading. Please reload this page.