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

Exclude None from default_na_values list when reading csv files #1466

Merged
merged 1 commit into from
Aug 17, 2023
Merged
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
18 changes: 12 additions & 6 deletions workflow/tests/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def results(self, aggregate_column=None, aggregate_function=None, excludes=[], e
print("Warning: %s not found. Skipping..." % feature_file)
continue

base_df = pd.read_csv(base_file, index_col=0)
feature_df = pd.read_csv(feature_file, index_col=0)
base_df = read_csv(base_file, index_col=0)
feature_df = read_csv(feature_file, index_col=0)

base_df = self.intersect_rows(base_df, feature_df)
feature_df = self.intersect_rows(feature_df, base_df)
Expand Down Expand Up @@ -151,14 +151,14 @@ def visualize(self, aggregate_column=None, aggregate_function=None, display_colu
files.append(file)

if display_columns or aggregate_columns:
base_characteristics_df = pd.read_csv(
base_characteristics_df = read_csv(
os.path.join(
self.base_folder,
'results_characteristics.csv'),
index_col=0)[
display_columns +
aggregate_columns]
feature_characteristics_df = pd.read_csv(
feature_characteristics_df = read_csv(
os.path.join(
self.feature_folder,
'results_characteristics.csv'),
Expand Down Expand Up @@ -209,8 +209,8 @@ def remove_columns(cols):
print("Warning: %s not found. Skipping..." % feature_file)
continue

base_df = pd.read_csv(base_file, index_col=0)
feature_df = pd.read_csv(feature_file, index_col=0)
base_df = read_csv(base_file, index_col=0)
feature_df = read_csv(feature_file, index_col=0)

base_df = self.intersect_rows(base_df, feature_df)
feature_df = self.intersect_rows(feature_df, base_df)
Expand Down Expand Up @@ -334,6 +334,12 @@ def remove_columns(cols):
auto_open=False)


def read_csv(csv_file_path, **kwargs) -> pd.DataFrame:
default_na_values = pd._libs.parsers.STR_NA_VALUES
df = pd.read_csv(csv_file_path, na_values=list(default_na_values - {'None'}), keep_default_na=False, **kwargs)
return df


if __name__ == '__main__':

default_base_folder = 'workflow/tests/base_results'
Expand Down