Skip to content

Rank Mixes np.nan with np.inf values #19538

Closed
@WillAyd

Description

@WillAyd

Code Sample, a copy-pastable example if possible

In []: df = pd.DataFrame([1, np.nan, np.inf, -np.inf, 25])
In []: df.rank()
Out []:
     0
0  2.0
1  NaN
2  NaN
3  1.0
4  3.0

In []: df.rank(ascending=False)
Out []:
     0
0  3.0
1  NaN
2  1.0
3  NaN
4  2.0

Problem description

np.inf or -np.inf gets grouped with np.nan in the rank operation, depending on which direction the ranking occurs in. Ideally, np.inf would be entirely separate from np.nan.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions