Skip to content
Open
Show file tree
Hide file tree
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
100 changes: 100 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,103 @@ ENV/

notebooks/data/
docs/notebooks

Created by https://www.gitignore.io/api/pycharm
# Edit at https://www.gitignore.io/?templates=pycharm

### PyCharm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
Comment on lines +115 to +117

Copy link
Copy Markdown
Collaborator

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 .gitignore with required files, but adding your personal IDE files is considered a bad practice, you can see how to move this contents into a global .gitignore file for your local installation here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

.gitignore has been updated.
also, audit.md and datapackage.json will be added too.
also, didnt notice the PULL_REQUEST_TEMPLATE.md, so ill take a look into it! thanks.

Copy link
Copy Markdown
Author

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 !

Copy link
Copy Markdown

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.md and the datapackage.json? just this two left.

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown

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.


# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### PyCharm Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/**/sonarlint/

# SonarQube Plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator/

/.idea/.gitignore
/.idea/misc.xml
/.idea/modules.xml
/.idea/inspectionProfiles/profiles_settings.xml
/.idea/rSettings.xml
/.idea/task-geo.iml
/.idea/vcs.xml
# End of https://www.gitignore.io/api/pycharm
3 changes: 3 additions & 0 deletions task_geo/data_sources/covid/south_korea/__init__.py
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']

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rename your data source to south_korea, or even better, the ISO code, something like kr_covid

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Done

25 changes: 25 additions & 0 deletions task_geo/data_sources/covid/south_korea/__main__.py
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()
55 changes: 55 additions & 0 deletions task_geo/data_sources/covid/south_korea/south_korea_patients.py
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):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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.
Also, this argument is a url, does this data source work with any url? I think this connector should take no arguments. Can you please update the signature for both connector and data source?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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)

@ManuelAlvarezC ManuelAlvarezC Apr 7, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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.

@KrSuma KrSuma Apr 9, 2020

Copy link
Copy Markdown

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 this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 datetime and reassigning them multiple times. This approach has two drawbacks:

  1. More lines of code to read and write, making it easier to miss details and introduce errors.
  2. It's in fact much faster making the casting and assigning of all the columns at once. This is what is called vectorization and pandas ( and numpy too) are designed to have vectorized operations run much faster than regular iteration in python.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also, passing the date format to to_datetime will further improve its performance.

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)