Skip to content

Commit 9c8b2b8

Browse files
committed
using if/else construct to pick sorting function for categoricals
1 parent d282e86 commit 9c8b2b8

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

pandas/core/algorithms.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,11 @@ def _get_data_algo(values, func_map):
989989
f = func_map['uint64']
990990
values = _ensure_uint64(values)
991991
elif is_categorical_dtype(values):
992-
f = values._funcs_for_rank()
993992
values = values._values_for_rank()
993+
if is_float_dtype(values):
994+
f = func_map['float64']
995+
else:
996+
f = func_map['object']
994997
else:
995998
values = _ensure_object(values)
996999

pandas/core/categorical.py

-19
Original file line numberDiff line numberDiff line change
@@ -1404,25 +1404,6 @@ def sort_values(self, inplace=False, ascending=True, na_position='last'):
14041404
return self._constructor(values=codes, categories=self.categories,
14051405
ordered=self.ordered, fastpath=True)
14061406

1407-
def _funcs_for_rank(self):
1408-
"""
1409-
For correctly ranking ordered categorical data. See GH#15420
1410-
1411-
Ordered categorical data should be ranked on the basis of
1412-
codes with -1 translated to NaN, as floats, and unordered
1413-
as objects
1414-
1415-
Returns
1416-
-------
1417-
numpy array
1418-
1419-
"""
1420-
if self._ordered:
1421-
f = _algos.rank_1d_float64
1422-
else:
1423-
f = _algos.rank_1d_object
1424-
return f
1425-
14261407
def _values_for_rank(self):
14271408
"""
14281409
For correctly ranking ordered categorical data. See GH#15420

0 commit comments

Comments
 (0)