Skip to content

Commit 4cad7d6

Browse files
authored
Ensure empty last line isnt printed when writing TSV (#559)
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.
1 parent f15975a commit 4cad7d6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/sssom/writers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ def write_table(
6262
meta[CURIE_MAP] = msdf.converter.bimap
6363
if sort:
6464
msdf.df = sort_df_rows_columns(msdf.df)
65-
lines = yaml.safe_dump(meta).split("\n")
66-
lines = [f"# {line}" for line in lines if line != ""]
67-
s = msdf.df.to_csv(sep=sep, index=False)
6865

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

0 commit comments

Comments
 (0)