Skip to content

Commit

Permalink
Merge pull request #184 from kayak/fix_fillna_in_pandas_sortdataframe
Browse files Browse the repository at this point in the history
Fix fillna in pandas sortdataframe
  • Loading branch information
twheys committed Sep 11, 2018
2 parents 607c659 + d45ae54 commit 3e3fcc2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions fireant/slicer/widgets/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ def pivot_data_frame(self, data_frame, pivot=(), transpose=False):
data_frame.name = data_frame.columns.levels[0][0] # capture the name of the metrics column
data_frame.columns = data_frame.columns.droplevel(0) # drop the metrics level

data_frame.fillna('', inplace=True)

return self.sort_data_frame(data_frame)
return self.sort_data_frame(data_frame) \
.fillna(value='')

def sort_data_frame(self, data_frame):
if not self.sort:
Expand All @@ -142,6 +141,13 @@ def sort_data_frame(self, data_frame):
if not sort_columns:
return data_frame

# pandas refuses a single item list for these arguments if the data frame has a single level index
if not isinstance(unsorted.index, pd.MultiIndex):
if isinstance(sort_columns, list):
sort_columns = sort_columns[0]
if isinstance(ascending, list):
ascending = ascending[0]

return unsorted \
.sort_values(sort_columns, ascending=ascending) \
.set_index(index_names)
Expand Down

0 comments on commit 3e3fcc2

Please sign in to comment.