-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
BUG: DataFrame.rank does not return EA types when original type was an EADtype #62189
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
base: main
Are you sure you want to change the base?
Changes from all commits
98a70df
af9f3de
00ef2ea
f78ffa5
5124513
178f4e3
3a94c7f
94893f0
7ee79ef
601dc39
2e7ca27
011c293
15922e8
fce155a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1091,7 +1091,6 @@ def rank( | |
) | ||
else: | ||
raise TypeError("Array with ndim > 2 are not supported.") | ||
|
||
return ranks | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9276,16 +9276,11 @@ def rank( | |
msg = "na_option must be one of 'keep', 'top', or 'bottom'" | ||
raise ValueError(msg) | ||
|
||
def ranker(data): | ||
if data.ndim == 2: | ||
# i.e. DataFrame, we cast to ndarray | ||
values = data.values | ||
else: | ||
# i.e. Series, can dispatch to EA | ||
values = data._values | ||
|
||
if isinstance(values, ExtensionArray): | ||
ranks = values._rank( | ||
def ranker(blk_values): | ||
if axis_int == 0: | ||
blk_values = blk_values.T | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we can avoid transposing at the block level and only transpose at the dataframe level (L9317). then pass axis=blk_values.ndim-1 (which will require updating the EA method) |
||
if isinstance(blk_values, ExtensionArray): | ||
ranks = blk_values._rank( | ||
axis=axis_int, | ||
method=method, | ||
ascending=ascending, | ||
|
@@ -9294,16 +9289,16 @@ def ranker(data): | |
) | ||
else: | ||
ranks = algos.rank( | ||
values, | ||
blk_values, | ||
axis=axis_int, | ||
method=method, | ||
ascending=ascending, | ||
na_option=na_option, | ||
pct=pct, | ||
) | ||
|
||
ranks_obj = self._constructor(ranks, **data._construct_axes_dict()) | ||
return ranks_obj.__finalize__(self, method="rank") | ||
if axis_int == 0: | ||
ranks = ranks.T | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this transpose should also be avoidable |
||
return ranks | ||
|
||
if numeric_only: | ||
if self.ndim == 1 and not is_numeric_dtype(self.dtype): | ||
|
@@ -9316,7 +9311,16 @@ def ranker(data): | |
else: | ||
data = self | ||
|
||
return ranker(data) | ||
should_transpose = axis_int == 1 | ||
|
||
if should_transpose: | ||
data = data.T | ||
applied = data._mgr.apply(ranker) | ||
result = self._constructor_from_mgr(applied, axes=applied.axes) | ||
if should_transpose: | ||
result = result.T | ||
|
||
return result.__finalize__(self, method="rank") | ||
|
||
@doc(_shared_docs["compare"], klass=_shared_doc_kwargs["klass"]) | ||
def compare( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have cases that get here?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the two 2d array tests I just added ,
test_rank2()
raises that Not Implemented Error when that line is there=============================================== short test summary info ================================================
FAILED pandas/tests/frame/methods/test_rank.py::TestRank::test_rank2 - NotImplementedError
FAILED pandas/tests/frame/methods/test_rank.py::TestRank::test_2d_extension_array_datetime - NotImplementedError
FAILED pandas/tests/frame/methods/test_rank.py::TestRank::test_2d_extension_array_timedelta - NotImplementedError
============================================ 3 failed, 131 passed in 5.58s =============================================
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the third "sub test" in
test_rank2
: