Skip to content

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

Merged
Show file tree
Hide file tree
Changes from 6 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
25 changes: 22 additions & 3 deletions validator/delphi_validator/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down Expand Up @@ -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)"))

Copy link
Contributor

Choose a reason for hiding this comment

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

Increment check counter with self.increment_total_checks().

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this still need to be fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in latest commit

Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions validator/params.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"end_date": "2020-09-08",
"span_length": 3,
"ref_window_size": 7,
"validator_static_file_dir": "../validator/static",
"minimum_sample_size": 100,
"missing_se_allowed": true,
"missing_sample_size_allowed": true,
Expand Down
12 changes: 12 additions & 0 deletions validator/scripts/unique_geoids.R
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")
Loading