Skip to content

Commit f8ec019

Browse files
committed
ask Categorical for ranking function
1 parent 40d88c1 commit f8ec019

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/core/categorical.py

+19
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,25 @@ 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+
14071426
def _values_for_rank(self):
14081427
"""
14091428
For correctly ranking ordered categorical data. See GH#15420

0 commit comments

Comments
 (0)