Skip to content

Commit

Permalink
[AlexsLemonade#229] comparative rnaseq - utils bugfix
Browse files Browse the repository at this point in the history
utils.py - write_rds accidentally modified its input dataframe; now makes
a copy before changing it. oops.
  • Loading branch information
e-t-k committed Feb 5, 2020
1 parent d0d7ff1 commit 1104b61
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions analyses/comparative-RNASeq-analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import pandas as pd
import pyreadr



def read_rds(filepath):
"""Read an RDS-format matrix into a Pandas dataframe.
Location can be data, scratch, or results.
Expand All @@ -22,8 +20,9 @@ def write_rds(df, filepath):
"""Write a pandas dataframe to RDS file in the dir specified.
Valid locations are scratch or results.
Index is stored as first column since pyreadr.write_rds drops it otherwise"""
df.insert(0, df.index.name, df.index, allow_duplicates=True)
pyreadr.write_rds(filepath, df)
indexed_df = df.copy()
indexed_df.insert(0, indexed_df.index.name, indexed_df.index, allow_duplicates=True)
pyreadr.write_rds(filepath, indexed_df)
# Pyreadr.write_rds fails silently when permissions prevent file write,
# so trigger an error if our file isn't actually there
with open(filepath, "rb"):
Expand Down

0 comments on commit 1104b61

Please sign in to comment.