Skip to content

Columns and DataType Not Explicitly Set on line 122 of github.py  #117

@CodeSmileBot

Description

@CodeSmileBot

Hello!

I found an AI-Specific Code smell in your project.
The smell is called: Columns and DataType Not Explicitly Set

You can find more information about it in this paper: https://dl.acm.org/doi/abs/10.1145/3522664.3528620.

According to the paper, the smell is described as follows:

Problem If the columns are not selected explicitly, it is not easy for developers to know what to expect in the downstream data schema. If the datatype is not set explicitly, it may silently continue the next step even though the input is unexpected, which may cause errors later. The same applies to other data importing scenarios.
Solution It is recommended to set the columns and DataType explicitly in data processing.
Impact Readability

Example:

### Pandas Column Selection
import pandas as pd
df = pd.read_csv('data.csv')
+ df = df[['col1', 'col2', 'col3']]

### Pandas Set DataType
import pandas as pd
- df = pd.read_csv('data.csv')
+ df = pd.read_csv('data.csv', dtype={'col1': 'str', 'col2': 'int', 'col3': 'float'})

You can find the code related to this smell in this link:

def get_data(cleaned_sheets):
all_csv = []
# Import all CSV's
for f in tqdm(sorted(cleaned_sheets), desc='... loading data: '):
if 'csv' in f:
try:
tmp_df = pd.read_csv(os.path.join(DATA, f), index_col=None,header=0, parse_dates=['Last Update'])
except:
# Temporary fix for JHU's bullshit data management
tmp_df = pd.read_csv(os.path.join(DATA, f), index_col=None,header=0, parse_dates=['Last_Update'])
tmp_df = clean_data(tmp_df)
tmp_df['date'] = tmp_df['datetime'].apply(get_date) # remove time to get date
tmp_df['file_date'] = get_csv_date(f) #Get date of csv from file name
tmp_df = tmp_df[KEEP_COLS]
tmp_df['province'].fillna(tmp_df['country'], inplace=True) #If no region given, fill it with country
all_csv.append(tmp_df)
df_raw = pd.concat(all_csv, axis=0, ignore_index=True, sort=True) # concatenate all csv's into one df
df_raw = fix_country_names(df_raw) # Fix mispelled country names
.

I also found instances of this smell in other files, such as:

File: https://github.com/AaronWard/covidify/blob/master/src/covidify/data_prep.py#L180-L190 Line: 185
File: https://github.com/AaronWard/covidify/blob/master/src/covidify/forecast.py#L95-L105 Line: 100
.

I hope this information is helpful!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions