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

ingestion: fix datetime parsing error on NK #18

Merged
merged 1 commit into from
Apr 18, 2023
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
15 changes: 6 additions & 9 deletions scripts/ingestion/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import sys
import re

import boto3
import pandas as pd
Expand Down Expand Up @@ -105,19 +106,15 @@ def get_data_with_estimated_onset(df: pd.DataFrame) -> pd.DataFrame:
)

def estimate_onset(row):
if isinstance(row.Date_onset, str) and (
"NA" not in row.Date_onset or "NK" not in row.Date_onset
):
if isinstance(row.Date_onset, str) and re.match(REGEX_DATE, row.Date_onset):
return pd.to_datetime(row.Date_onset)
if isinstance(row.Date_death, str) and (
"NA" not in row.Date_death or "NK" not in row.Date_death
):
if isinstance(row.Date_death, str) and re.match(REGEX_DATE, row.Date_death):
return pd.to_datetime(row.Date_death) - delay_death
if (
isinstance(row.Date_of_first_consult, str)
and "NA" not in row.Date_of_first_consult
if isinstance(row.Date_of_first_consult, str) and re.match(
REGEX_DATE, row.Date_of_first_consult
):
return pd.to_datetime(row.Date_of_first_consult) - delay_to_consult_hosp
return None

df["Date_onset_estimated"] = df.apply(estimate_onset, axis=1)
return df
Expand Down
2 changes: 1 addition & 1 deletion scripts/ingestion/test_data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ ID,Case_status,Age,Gender,Date_onset,Date_death,Date_of_first_consult,Data_up_to
2,probable,40-46,female,2023-02-06,2023-02-14,,2023-04-04,Bata,1,ZZ,household contact
3,confirmed,20,male,2023-02-19,,2023-02-25,2023-04-04,Nsoc Nsomo,2,AA,
4,confirmed,99,female,2023-01-05,2023-01-11,,2023-04-04,Nsoc Nsomo,,ZK,school
5,probable,65,male,,2023-01-19,,2023-04-04,Ebiebyin,,KR,household contact
5,probable,65,male,NK,2023-01-19,,2023-04-04,Ebiebyin,,KR,household contact
6,confirmed,59,female,,,2023-04-02,2023-04-04,Ebiebyin,,ZZ,
7,confirmed,0,male,2023-02-11,,2023-02-13,2023-04-04,Nsork,,ZZ,
4 changes: 2 additions & 2 deletions scripts/ingestion/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
2,probable,female,40-46,2023-02-06,2023-02-06,,2023-02-14,Bata,2023-04-04,1
3,confirmed,male,20,2023-02-19,2023-02-19,2023-02-25,,Nsoc Nsomo,2023-04-04,2
4,confirmed,female,99,2023-01-05,2023-01-05,,2023-01-11,Nsoc Nsomo,2023-04-04,
5,probable,male,65,,2023-01-13,,2023-01-19,Ebiebyin,2023-04-04,
5,probable,male,65,NK,2023-01-13,,2023-01-19,Ebiebyin,2023-04-04,
6,confirmed,female,59,,2023-03-29,2023-04-02,,Ebiebyin,2023-04-04,
7,confirmed,male,0,2023-02-11,2023-02-11,2023-02-13,,Nsork,2023-04-04,
"""
Expand All @@ -40,7 +40,7 @@
2,probable,female,40-46,2023-02-06,2023-02-06,,2023-02-14,Bata,2023-04-04
3,confirmed,male,20,2023-02-19,2023-02-19,2023-02-25,,Nsoc Nsomo,2023-04-04
4,confirmed,female,99,2023-01-05,2023-01-05,,2023-01-11,Nsoc Nsomo,2023-04-04
5,probable,male,65,,2023-01-13,,2023-01-19,Ebiebyin,2023-04-04
5,probable,male,65,NK,2023-01-13,,2023-01-19,Ebiebyin,2023-04-04
6,confirmed,female,59,,2023-03-29,2023-04-02,,Ebiebyin,2023-04-04
7,confirmed,male,0,2023-02-11,2023-02-11,2023-02-13,,Nsork,2023-04-04
"""
Expand Down