Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: rank_2d raising with mixed dtypes #38932

Merged
merged 8 commits into from
Jan 5, 2021

Conversation

mzeitlin11
Copy link
Member

  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

try:
_as = values.argsort(1)
except TypeError:
values = in_arr
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the source of the bug - if axis=0, values is supposed to be transposed (as done earlier in the function) - setting equal to in_arr makes values the wrong shape since in_arr was not transposed

pct=pct
)
if axis == 0:
return ranks.T
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole try/except is not necessary because the except clause will always raise a TypeError anyway since if values.argsort(1) raises a TypeError, at least one column in values must not be sortable, so that same column will cause another TypeError to be raised when trying to fallback to rank_1d

@mzeitlin11 mzeitlin11 closed this Jan 3, 2021
@mzeitlin11 mzeitlin11 reopened this Jan 3, 2021
@jreback jreback added Dtype Conversions Unexpected or buggy dtype conversions Numeric Operations Arithmetic, Comparison, and Logical operations labels Jan 4, 2021
@jreback jreback added this to the 1.3 milestone Jan 4, 2021
@@ -217,6 +217,8 @@ Numeric
- Bug in :meth:`DataFrame.select_dtypes` with ``include=np.number`` now retains numeric ``ExtensionDtype`` columns (:issue:`35340`)
- Bug in :meth:`DataFrame.mode` and :meth:`Series.mode` not keeping consistent integer :class:`Index` for empty input (:issue:`33321`)
- Bug in :meth:`DataFrame.rank` with ``np.inf`` and mixture of ``np.nan`` and ``np.inf`` (:issue:`32593`)
- Bug in :meth:`DataFrame.rank` with ``axis=0`` and columns holding incomparable types raising ``IndexError``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is not issue (its fine don't create one), but add this PR number as the issue number.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for committing that, yep no issue

@jreback jreback merged commit 581bf70 into pandas-dev:master Jan 5, 2021
@jreback
Copy link
Contributor

jreback commented Jan 5, 2021

thanks @mzeitlin11 keep em coming!

@mzeitlin11 mzeitlin11 deleted the bug/rank_2d_mixed branch January 5, 2021 01:30
luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants