Skip to content

rank() makes unexpected inplace changes #18521

Closed
@naure

Description

@naure

Code Sample

import pandas as pd

dt = pd.Series([pd.Timestamp('2017-01-05 10:20:27.569000'), pd.NaT])
print("\nBefore")
print(dt)

# Should not modify the object
ranks = dt.rank()

print("\nAfter")
print(dt)
Before
0   2017-01-05 10:20:27.569
1                       NaT
dtype: datetime64[ns]

After
0   2017-01-05 10:20:27.569000000
1   2262-04-11 23:47:16.854775807
dtype: datetime64[ns]

Problem description

The rank() method replaces NaT with a concrete date value in the object.

Expected Output

No change in the object.

Output of pd.show_versions()

/Users/naure/Library/Python/3.6/lib/python/site-packages/xarray/core/formatting.py:16: FutureWarning: The pandas.tslib module is deprecated and will be removed in a future version.
from pandas.tslib import OutOfBoundsDatetime

INSTALLED VERSIONS

commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Darwin
OS-release: 15.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.20.1
pytest: None
pip: 9.0.1
setuptools: 36.0.1
Cython: None
numpy: 1.13.1
scipy: 0.19.0
xarray: 0.9.5
IPython: 6.1.0
sphinx: None
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.0
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDatetimeDatetime data dtypeMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions