Skip to content
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

Fix KeyError parsing for Cuba #2778

Merged
merged 4 commits into from
Aug 16, 2022
Merged
Changes from 1 commit
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
23 changes: 15 additions & 8 deletions ingestion/functions/parsing/cuba/cuba.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,23 @@ def parse_cases(raw_data_file, source_id, source_url):
# First make dict mapping code names of diagnostic and treament centers
# to actual locations
hospital_map = {}
for centre_type in ['centros_aislamiento', 'centros_diagnostico']:
for centre in json_data[centre_type]:
hospital_map[centre] = json_data[centre_type][centre]['nombre'] + \
", " + json_data[centre_type][centre]['provincia']
try:
for centre_type in ['centros_aislamiento', 'centros_diagnostico']:
for centre in json_data[centre_type]:
hospital_map[centre] = json_data[centre_type][centre]['nombre'] + \
", " + json_data[centre_type][centre]['provincia']
except:
Copy link
Contributor

Choose a reason for hiding this comment

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

use except KeyError here - in case some other exception is raised. Also good to use logging.info to print a message saying that key was not found

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

New commit [6c96b56] deals with this.

#key not found
pass

# Get schema_version
schema_version = json_data['schema-version']
if schema_version != 7:
logger.warning(
f'Schema version has been updated from 7 to {schema_version}')
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

Was schema-version removed? A change in schema-version should break the script, as we might not be capturing the correct fields.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

schema-version was removed. There is no mention of schema-version in covid19-cuba-1.json.

schema_version = json_data['schema-version']
if schema_version != 7:
logger.warning(
f'Schema version has been updated from 7 to {schema_version}')
except:
schema_version = "(undef)"

for day in json_data['casos']['dias']:
if 'diagnosticados' in json_data['casos']['dias'][day]:
Expand Down