Skip to content

Commit

Permalink
PERF: categorical rank GH#15498
Browse files Browse the repository at this point in the history
no need to rename categories where they are already ordered
  • Loading branch information
jeet63 committed Mar 1, 2017
1 parent a67cd85 commit 1ebdb56
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,9 @@ def _get_data_algo(values, func_map):

f = None

if is_categorical_dtype(values):
values = values._values_for_rank()

if is_float_dtype(values):
f = func_map['float64']
values = _ensure_float64(values)
Expand All @@ -990,10 +993,6 @@ def _get_data_algo(values, func_map):
f = func_map['uint64']
values = _ensure_uint64(values)

elif is_categorical_dtype(values):
f = func_map['float64']
values = values._values_for_rank()

else:
values = _ensure_object(values)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,8 +1420,8 @@ def _values_for_rank(self):
if self.ordered:
values = self.codes
mask = values == -1
values = values.astype('float64')
if mask.any():
values = values.astype('float64')
values[mask] = np.nan
elif self.categories.is_numeric():
values = np.array(self)
Expand Down

0 comments on commit 1ebdb56

Please sign in to comment.