Skip to content

Commit 21b6d90

Browse files
Copy data.values when ranking
1 parent 2db1cc0 commit 21b6d90

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

doc/source/whatsnew/v0.22.0.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -329,5 +329,7 @@ Categorical
329329
Other
330330
^^^^^
331331

332-
- Improved error message when attempting to use a Python keyword as an identifier in a ``numexpr`` backed query (:issue:`18221`)
333-
-
332+
- Improved error message when attempting to use a Python keyword as an identifier in a numexpr query (:issue:`18221`)
333+
- Fixed a bug where creating a Series from an array that contains both tz-naive and tz-aware values will result in a Series whose dtype is tz-aware instead of object (:issue:`16406`)
334+
- Adding a ``Period`` object to a ``datetime`` or ``Timestamp`` object will now correctly raise a ``TypeError`` (:issue:`17983`)
335+
- Bug in :func:`Series.rank` where ``Series`` containing ``NaT`` modifies the ``Series`` inplace (:issue:`18521`)

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5937,7 +5937,7 @@ def rank(self, axis=0, method='average', numeric_only=None,
59375937
raise NotImplementedError(msg)
59385938

59395939
def ranker(data):
5940-
ranks = algos.rank(data.values, axis=axis, method=method,
5940+
ranks = algos.rank(data.values.copy(), axis=axis, method=method,
59415941
ascending=ascending, na_option=na_option,
59425942
pct=pct)
59435943
ranks = self._constructor(ranks, **data._construct_axes_dict())

pandas/tests/series/test_rank.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
from pandas import compat
2+
from pandas import compat, Timestamp
33

44
import pytest
55

@@ -368,3 +368,11 @@ def test_rank_object_bug(self):
368368
# smoke tests
369369
Series([np.nan] * 32).astype(object).rank(ascending=True)
370370
Series([np.nan] * 32).astype(object).rank(ascending=False)
371+
372+
def test_rank_modify_inplace(self):
373+
# GH 18521
374+
df = Series([Timestamp('2017-01-05 10:20:27.569000'), NaT])
375+
pre_rank_df = df.copy()
376+
377+
df.rank()
378+
assert_series_equal(df, pre_rank_df)

0 commit comments

Comments
 (0)