Skip to content

Commit

Permalink
Fix categorical_order
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Mar 13, 2015
1 parent 6df5458 commit 037bf80
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions seaborn/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,16 +419,32 @@ def axes_ticklabels_overlap(ax):
def categorical_order(values, order=None):
"""Return a list of unique data values.
Determine an ordered list of levels in ``values``.
Parameters
----------
values : list, array, Categorical, or Series
Vector of "categorical" values
order : list-like, optional
Desired order of category levels to override the order determined
from the ``values`` object.
Returns
-------
order : list
Ordered list of category levels
"""
if order is None:
if hasattr(values, "cat"):
order = values.cat.categories
elif hasattr(values, "categories"):
if hasattr(values, "categories"):
order = values.categories
else:
try:
order = values.unique()
except AttributeError:
order = pd.unique(values)
order = values.cat.categories
except (TypeError, AttributeError):
try:
order = values.unique()
except AttributeError:
order = pd.unique(values)

return list(order)

0 comments on commit 037bf80

Please sign in to comment.