Skip to content

Commit

Permalink
More flexible handling of stacking/unstacking dose
Browse files Browse the repository at this point in the history
* Doses dataframe unstacking is now idempotent
* Stacking will now preserve 'dataset' column if present
  • Loading branch information
alubbock committed Jul 30, 2019
1 parent 00a4b70 commit 4f7d7a4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion thunor/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ def __repr__(self):

def doses_unstacked(self):
""" Split multiple drugs/doses into separate columns """
# If already unstacked, just return
if 'drug1' in self.doses.index.names:
return self.doses

doses = self.doses.reset_index()

n_drugs = doses['drug'].apply(len).max()
Expand Down Expand Up @@ -923,7 +927,10 @@ def _stack_doses(df_doses, inplace=True):

df_doses.drop(list(df_doses.filter(regex='^(dose|drug)[0-9]+$')),
axis=1, inplace=True)
df_doses.set_index(['drug', 'cell_line', 'dose'], inplace=True)
index_cols = ['drug', 'cell_line', 'dose']
if 'dataset' in df_doses.columns:
index_cols = ['dataset'] + index_cols
df_doses.set_index(index_cols, inplace=True)

if not inplace:
return df_doses
Expand Down

0 comments on commit 4f7d7a4

Please sign in to comment.