Skip to content

Commit e82b128

Browse files
Copy data.values when ranking
1 parent d2fd22e commit e82b128

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

doc/source/whatsnew/v0.22.0.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,5 +335,7 @@ Categorical
335335
Other
336336
^^^^^
337337

338-
- Improved error message when attempting to use a Python keyword as an identifier in a ``numexpr`` backed query (:issue:`18221`)
339-
-
338+
- Improved error message when attempting to use a Python keyword as an identifier in a numexpr query (:issue:`18221`)
339+
- 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`)
340+
- Adding a ``Period`` object to a ``datetime`` or ``Timestamp`` object will now correctly raise a ``TypeError`` (:issue:`17983`)
341+
- Bug in :func:`Series.rank` where ``Series`` containing ``NaT`` modifies the ``Series`` inplace (:issue:`18521`)

pandas/core/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5940,7 +5940,7 @@ def rank(self, axis=0, method='average', numeric_only=None,
59405940
raise NotImplementedError(msg)
59415941

59425942
def ranker(data):
5943-
ranks = algos.rank(data.values, axis=axis, method=method,
5943+
ranks = algos.rank(data.values.copy(), axis=axis, method=method,
59445944
ascending=ascending, na_option=na_option,
59455945
pct=pct)
59465946
ranks = self._constructor(ranks, **data._construct_axes_dict())

pandas/tests/series/test_rank.py

Lines changed: 9 additions & 1 deletion
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)