Skip to content

Commit

Permalink
Ensure empty last line isnt printed when writing TSV (#559)
Browse files Browse the repository at this point in the history
when printing df.to_csv(sep=sep, index=False), a line break is added
automatically;

print(x) is also adding a line break, so when the dataframe string is
printed, two line breaks are printed, leading to an empty line.

I also refactored the `lines` part a bit moving it inside the
conditional, as they are only needed there.
  • Loading branch information
matentzn authored Nov 7, 2024
1 parent f15975a commit 4cad7d6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/sssom/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def write_table(
meta[CURIE_MAP] = msdf.converter.bimap
if sort:
msdf.df = sort_df_rows_columns(msdf.df)
lines = yaml.safe_dump(meta).split("\n")
lines = [f"# {line}" for line in lines if line != ""]
s = msdf.df.to_csv(sep=sep, index=False)

if embedded_mode:
lines = yaml.safe_dump(meta).split("\n")
lines = [f"# {line}" for line in lines if line != ""]
s = msdf.df.to_csv(sep=sep, index=False).rstrip("\n")
lines = lines + [s]
for line in lines:
print(line, file=file)
Expand Down

0 comments on commit 4cad7d6

Please sign in to comment.