Skip to content

rank() makes unexpected inplace changes #18521

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

Closed
naure opened this issue Nov 27, 2017 · 1 comment · Fixed by #18576
Closed

rank() makes unexpected inplace changes #18521

naure opened this issue Nov 27, 2017 · 1 comment · Fixed by #18576
Labels
Bug Datetime Datetime data dtype Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@naure
Copy link

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 gfyoung added Bug Numeric Operations Arithmetic, Comparison, and Logical operations Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Datetime Datetime data dtype and removed Numeric Operations Arithmetic, Comparison, and Logical operations labels Nov 27, 2017
@gfyoung
Copy link
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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants