New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rank() makes unexpected inplace changes #18521

Closed
naure opened this Issue Nov 27, 2017 · 1 comment

Comments

Projects
None yet
3 participants
@naure

naure commented Nov 27, 2017

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

@gfyoung

This comment has been minimized.

Member

gfyoung commented Nov 27, 2017

Yikes! I dislike surprises like these as much as the next developer. Patch for this behavior is most welcome!

@jreback jreback added this to the 0.22.0 milestone Nov 30, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment