Skip to content

Commit

Permalink
BUG: quick fix for pandas-dev#10989
Browse files Browse the repository at this point in the history
  • Loading branch information
jakevdp committed Sep 4, 2015
1 parent 91b6848 commit 2b04d9f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pandas/tools/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ def _add_margins(table, data, values, rows, cols, aggfunc):

grand_margin = _compute_grand_margin(data, values, aggfunc)

# categorical index or columns will fail below when 'All' is added
# here we'll convert all categorical indices to object
def convert_categorical(ind):
_convert = lambda ind: (ind.astype('object')
if ind.dtype.name == 'category' else ind)
if isinstance(ind, MultiIndex):
return ind.set_levels([_convert(lev) for lev in ind.levels])
else:
return _convert(ind)

table.index = convert_categorical(table.index)
table.columns = convert_categorical(table.columns)

if not values and isinstance(table, Series):
# If there are no values and the table is a series, then there is only
# one column in the data. Compute grand margin and return it.
Expand Down

0 comments on commit 2b04d9f

Please sign in to comment.