Skip to content

7dav new geo ids #1416

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 10 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
36 changes: 36 additions & 0 deletions _delphi_utils_python/delphi_utils/validator/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def validate(self, all_frames, report):
self.check_max_allowed_max_date(
max_date, geo_type, signal_type, report)

self.check_na_vals(geo_sig_df, geo_type, signal_type, report)

# Get relevant reference data from API dictionary.
api_df_or_error = all_api_df[(geo_type, signal_type)]

Expand Down Expand Up @@ -168,6 +170,40 @@ def validate(self, all_frames, report):
if self.test_mode and kroc == 2:
break

def check_na_vals(self, geo_sig_df, geo_type, signal_type, report):
"""Check if there are any NA values.

In particular, make sure that error doesn't occur for new Geo IDs introduced.

Arguments:
- geo_type: str; geo type name (county, msa, hrr, state) as in the CSV name
- signal_type: str; signal name as in the CSV name
- report: ValidationReport; report where results are added

Returns:
- None
"""
def replace_first_six(df):
x = df.val.isnull()
# First 6 days have to be null
x.iloc[:6] = False
return df.time_value[x]

grouped_df = geo_sig_df.groupby('geo_id')
error_df = grouped_df.apply(replace_first_six)

if not error_df.empty:
for index, value in error_df.iteritems():
report.add_raised_error(
ValidationFailure(f"check_val_missing (geo_id {index[0]})",
geo_type=geo_type,
signal=signal_type,
date=value
)
)

report.increment_total_checks()

def check_min_allowed_max_date(self, max_date, geo_type, signal_type, report):
"""Check if time since data was generated is reasonable or too long ago.

Expand Down
8 changes: 0 additions & 8 deletions _delphi_utils_python/delphi_utils/validator/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,6 @@ def check_bad_val(self, df_to_test, nameformat, signal_type, report):

report.increment_total_checks()

if df_to_test['val'].isnull().values.any():
report.add_raised_error(
ValidationFailure("check_val_missing",
filename=nameformat,
message="val column can't have any cell that is NA"))

report.increment_total_checks()

if not df_to_test[(df_to_test['val'] < 0)].empty:
report.add_raised_error(
ValidationFailure("check_val_lt_0",
Expand Down
20 changes: 19 additions & 1 deletion _delphi_utils_python/tests/validator/test_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,25 @@ def test_0_vs_many(self):

assert len(report.raised_errors) == 1
assert report.raised_errors[0].check_name == "check_rapid_change_num_rows"

class TestCheckNaVals:
params = {
"common": {
"data_source": "",
"span_length": 1,
"end_date": "2020-09-02"
}
}
def test_missing(self):
validator = DynamicValidator(self.params)
report = ValidationReport([])
data = {"val": [np.nan] * 14, "geo_id": [0,1] * 7, "time_value": ["2021-09-01"] * 14 }
df = pd.DataFrame(data)
#df.set_index(range(7), inplace=True)
validator.check_na_vals(df, "geo", "signal", report)

assert len(report.raised_errors) == 2
assert report.raised_errors[0].check_name == "check_val_missing (geo_id 0)"
assert report.raised_errors[1].check_name == "check_val_missing (geo_id 1)"

class TestCheckAvgValDiffs:
params = {
Expand Down
9 changes: 0 additions & 9 deletions _delphi_utils_python/tests/validator/test_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,6 @@ def test_empty_df(self):

assert len(report.raised_errors) == 0

def test_missing(self):
validator = StaticValidator(self.params)
report = ValidationReport([])
df = pd.DataFrame([np.nan], columns=["val"])
validator.check_bad_val(df, FILENAME, "signal", report)

assert len(report.raised_errors) == 1
assert report.raised_errors[0].check_name == "check_val_missing"

def test_lt_0(self):
validator = StaticValidator(self.params)
report = ValidationReport([])
Expand Down