Skip to content

Commit 178f4e3

Browse files
committed
dataframe level transpose
1 parent 5124513 commit 178f4e3

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

pandas/core/generic.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9286,14 +9286,24 @@ def ranker(blk_values):
92869286
pct=pct,
92879287
)
92889288
else:
9289-
ranks = algos.rank(
9290-
blk_values.T,
9291-
axis=axis_int,
9292-
method=method,
9293-
ascending=ascending,
9294-
na_option=na_option,
9295-
pct=pct,
9296-
).T
9289+
if blk_values.ndim > 1 and axis_int == 0:
9290+
ranks = algos.rank(
9291+
blk_values.T,
9292+
axis=axis_int,
9293+
method=method,
9294+
ascending=ascending,
9295+
na_option=na_option,
9296+
pct=pct,
9297+
).T
9298+
else:
9299+
ranks = algos.rank(
9300+
blk_values,
9301+
axis=axis_int,
9302+
method=method,
9303+
ascending=ascending,
9304+
na_option=na_option,
9305+
pct=pct,
9306+
)
92979307
return ranks
92989308

92999309
if numeric_only:
@@ -9307,10 +9317,16 @@ def ranker(blk_values):
93079317
else:
93089318
data = self
93099319

9310-
result = data._mgr.apply(ranker)
9311-
return self._constructor_from_mgr(result, axes=result.axes).__finalize__(
9312-
self, method="rank"
9313-
)
9320+
should_transpose = data.ndim > 1 and axis_int == 1
9321+
9322+
if should_transpose:
9323+
data = data.T
9324+
applied = data._mgr.apply(ranker)
9325+
result = self._constructor_from_mgr(applied, axes=applied.axes)
9326+
if should_transpose:
9327+
result = result.T
9328+
9329+
return result.__finalize__(self, method="rank")
93149330

93159331
@doc(_shared_docs["compare"], klass=_shared_doc_kwargs["klass"])
93169332
def compare(

0 commit comments

Comments
 (0)