-
Notifications
You must be signed in to change notification settings - Fork 19
South Korea dataset module #45
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
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 |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from task_geo.data_sources.covid.south_korea.south_korea_patients import south_korea_patients | ||
|
|
||
| __all__ = ['south_korea_patients'] | ||
|
Collaborator
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. Rename your data source to 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. Done |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import argparse | ||
|
|
||
| from south_korea_patients import south_korea_patients | ||
|
|
||
|
|
||
| def get_argparser(): | ||
| parser = argparse.ArgumentParser() | ||
|
|
||
| parser.add_argument( | ||
| '-o', '--output', required=True, | ||
| help='Destination file to store the processed dataset.') | ||
|
|
||
| return parser | ||
|
|
||
|
|
||
| def main(): | ||
| parser = get_argparser() | ||
| args = parser.parse_args() | ||
|
|
||
| dataset = south_korea_patients() | ||
| dataset.to_csv(args.output, index=False, header=True) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import io | ||
|
|
||
| import pandas as pd | ||
| import requests | ||
|
|
||
|
|
||
| def south_korea_patients_connector(*args, **kwargs): | ||
|
Collaborator
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. I'm not sure why the signature of the functions is with *args, and **kwargs if you are only expecting one argument. 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. Done, takes no argument now and the url has been set |
||
| """Retrieves data from south_korea_patients. | ||
|
|
||
| Arguments: | ||
| url(string): Dataset url | ||
| Returns: | ||
| pandas.DataFrame | ||
| """ | ||
| csv = requests.get(kwargs['url']).content | ||
| return pd.read_csv(io.StringIO(csv.decode('utf-8'))) | ||
|
|
||
|
|
||
| def south_korea_patients_formatter(df): | ||
| """Formats data retrieved from south_korea_patients. | ||
|
|
||
| Arguments: | ||
| df(pandas.DataFrame): | ||
|
|
||
| Returns: | ||
| pandas.DataFrame | ||
| """ | ||
| cols_ordered = [ | ||
| 'country', 'state', 'province', 'confirmed_date', | ||
| 'released_date', 'deceased_date', 'exposure_start', | ||
| 'exposure_end', 'global_id', 'birth_year', | ||
| 'local_id', 'sex', 'disease', | ||
| 'group', 'infection_reason', 'infection_order', | ||
| 'infected_by', 'contact_number' | ||
| ] | ||
| df = df.reindex(columns=cols_ordered) | ||
| df['confirmed_date'] = pd.to_datetime(df.confirmed_date) | ||
|
Collaborator
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. This cast can be done in two lines with: date_columns = [...]
df[date_columns] = df[date_columns].apply(pd.to_datetime)
# This was written originally as pd.to_datetime(df[columns]) which crashes.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. @ManuelAlvarezC Could you elaborate on this?
Collaborator
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. Sure thing. On the lines between 37-41(I only selected the line 37 to comment, a blunder of mine) you are casting columns to
Collaborator
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. Also, passing the date format to |
||
| df['released_date'] = pd.to_datetime(df.released_date) | ||
| df['deceased_date'] = pd.to_datetime(df.deceased_date) | ||
| df['exposure_start'] = pd.to_datetime(df.exposure_start) | ||
| df['exposure_end'] = pd.to_datetime(df.exposure_end) | ||
| return df | ||
|
|
||
|
|
||
| def south_korea_patients(*args, **kwargs): | ||
| """Data Source for south_korea_patients. | ||
|
|
||
| Arguments: | ||
| url(string): Dataset url | ||
|
|
||
| Returns: | ||
| pandas.DataFrame | ||
| """ | ||
| data = south_korea_patients_connector(*args, **kwargs) | ||
| return south_korea_patients_formatter(data) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm totally fine with you updating the
.gitignorewith required files, but adding your personal IDE files is considered a bad practice, you can see how to move this contents into a global.gitignorefile for your local installation here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.gitignorehas been updated.also,
audit.mdanddatapackage.jsonwill be added too.also, didnt notice the
PULL_REQUEST_TEMPLATE.md, so ill take a look into it! thanks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome, I didn't know you can set a global gitignore thank you @ManuelAlvarezC !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ManuelAlvarezC Could you elaborate on the
audit.mdand thedatapackage.json? just this two left.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although is not as complete as it should be, thedocumentation will help you get a good grab on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ManuelAlvarezC Thank you, ill take a look at it, finalize the edit and make the push.