Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/pandas-dev/pandas into feat…
Browse files Browse the repository at this point in the history
…ure/44764_perf_issue_new
  • Loading branch information
Sylvain MARIE committed Mar 8, 2024
2 parents a519427 + 95ab36d commit c58d5eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ Bug fixes
- Fixed bug in :meth:`DataFrame.to_string` that raised ``StopIteration`` with nested DataFrames. (:issue:`16098`)
- Fixed bug in :meth:`DataFrame.update` bool dtype being converted to object (:issue:`55509`)
- Fixed bug in :meth:`Series.diff` allowing non-integer values for the ``periods`` argument. (:issue:`56607`)
- Fixed bug in :meth:`Series.rank` that doesn't preserve missing values for nullable integers when ``na_option='keep'``. (:issue:`56976`)

Categorical
^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,7 @@ def _rank(
raise NotImplementedError

return rank(
self._values_for_argsort(),
self,
axis=axis,
method=method,
na_option=na_option,
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/series/methods/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ def test_rank_categorical(self):
tm.assert_series_equal(na_ser.rank(na_option="bottom", pct=True), exp_bot)
tm.assert_series_equal(na_ser.rank(na_option="keep", pct=True), exp_keep)

def test_rank_nullable_integer(self):
# GH 56976
exp = Series([np.nan, 2, np.nan, 3, 3, 2, 3, 1])
exp = exp.astype("Int64")
result = exp.rank(na_option="keep")

expected = Series([np.nan, 2.5, np.nan, 5.0, 5.0, 2.5, 5.0, 1.0])

tm.assert_series_equal(result, expected)

def test_rank_signature(self):
s = Series([0, 1])
s.rank(method="average")
Expand Down

0 comments on commit c58d5eb

Please sign in to comment.