Skip to content

Commit

Permalink
Changed file opens to binary mode for to_csv calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
ptth222 committed Mar 7, 2024
1 parent 0f9214f commit 3d2f060
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion isatools/isatab/dump/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def dump(isa_obj, output_path,
raise NameError('Investigation file must match pattern i_*.txt, got {}'.format(i_file_name))

if path.exists(output_path):
fp = open(path.join(output_path, i_file_name), 'w', encoding='utf-8')
fp = open(path.join(output_path, i_file_name), 'wb', encoding='utf-8')
else:
log.debug('output_path=', i_file_name)
raise FileNotFoundError("Can't find " + output_path)
Expand Down
4 changes: 2 additions & 2 deletions isatools/isatab/dump/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def flatten(current_list):
DF = DF.replace('', nan)
DF = DF.dropna(axis=1, how='all')

with open(path.join(output_dir, study_obj.filename), 'w') as out_fp:
with open(path.join(output_dir, study_obj.filename), 'wb') as out_fp:
DF.to_csv(
path_or_buf=out_fp, index=False, sep='\t', encoding='utf-8')

Expand Down Expand Up @@ -480,7 +480,7 @@ def pbar(x):
DF = DF.dropna(axis=1, how='all')

with open(path.join(
output_dir, assay_obj.filename), 'w') as out_fp:
output_dir, assay_obj.filename), 'wb') as out_fp:
DF.to_csv(path_or_buf=out_fp, index=False, sep='\t',
encoding='utf-8')

Expand Down
2 changes: 1 addition & 1 deletion isatools/isatab/load/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def merge_study_with_assay_tables(study_file_path, assay_file_path, target_file_
log.info("Merging DataFrames...")
merged_DF = merge(study_DF, assay_DF, on='Sample Name')
log.info("Writing merged DataFrame to file %s", target_file_path)
with open(target_file_path, 'w', encoding='utf-8') as fp:
with open(target_file_path, 'wb', encoding='utf-8') as fp:
merged_DF.to_csv(fp, sep='\t', index=False, header=study_DF.isatab_header + assay_DF.isatab_header[1:])


Expand Down
2 changes: 1 addition & 1 deletion isatools/magetab.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def write_idf_file(inv_obj, output_path):
idf_df = idf_df.replace('', np.nan)
with open(os.path.join(output_path, "{}.idf.txt".format(
investigation.identifier if investigation.identifier != ""
else investigation.filename[2:-3])), "w",
else investigation.filename[2:-3])), "wb",
encoding='utf-8') as idf_fp:
idf_df.to_csv(
path_or_buf=idf_fp,
Expand Down
4 changes: 2 additions & 2 deletions isatools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ def replace_factor_with_source_characteristic(self, factor_name):
table_file_df.columns = self.clean_isatab_field_names(
field_names_modified)

with open(self.path, 'w') as out_fp:
with open(self.path, 'wb') as out_fp:
table_file_df.to_csv(path_or_buf=out_fp, index=False, sep='\t',
encoding='utf-8')

Expand Down Expand Up @@ -856,7 +856,7 @@ def replace_factor_with_protocol_parameter_value(

with open(os.path.join(
os.path.dirname(self.path), '{s_filename}.fix'.format(
s_filename=os.path.basename(self.path))), 'w') as out_fp:
s_filename=os.path.basename(self.path))), 'wb') as out_fp:
table_file_df.to_csv(path_or_buf=out_fp, index=False, sep='\t',
encoding='utf-8')

Expand Down

0 comments on commit 3d2f060

Please sign in to comment.