Skip to content

FutureWarning when sorting tz-aware datetimeindex #25439

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
dsjstc opened this issue Feb 25, 2019 · 3 comments · Fixed by #26854
Closed

FutureWarning when sorting tz-aware datetimeindex #25439

dsjstc opened this issue Feb 25, 2019 · 3 comments · Fixed by #26854
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Datetime Datetime data dtype ExtensionArray Extending pandas with custom dtypes or arrays.
Milestone

Comments

@dsjstc
Copy link

dsjstc commented Feb 25, 2019

Problem

As reported here, sorting a tz-aware DatetimeIndex issues warning:

FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive ndarray with 'datetime64[ns]' dtype

MCVE here:

import pandas as pd
idx = pd.DatetimeIndex(['2017-07-05 07:00:00', '2018-07-05 07:15:00','2017-07-05 07:30:00'])
df = pd.DataFrame({'C1':['a','b','c']},index=idx)
df = df.tz_localize('UTC')
df.sort_index()

Stack

The stack (Pandas 0.24.1) is:

__array__, datetimes.py:358
asanyarray, numeric.py:544
nargsort, sorting.py:257
sort_index, frame.py:4795

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.7.final.0 python-bits: 64 OS: Linux OS-release: 4.18.9-acso machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_CA.UTF-8 LOCALE: en_CA.UTF-8

pandas: 0.24.1
pytest: None
pip: 19.0.2
setuptools: 40.7.2
Cython: 0.28.4
numpy: 1.16.1
scipy: None
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2018.9
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.2
openpyxl: 2.6.0
xlrd: 1.2.0
xlwt: None
xlsxwriter: None
lxml.etree: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@TomAugspurger
Copy link
Contributor

nargsort will need to be updated, preferably to handle all extension arrays.

In the meantime, you can silence the warning with a warnings filter.

@TomAugspurger TomAugspurger added this to the 0.24.2 milestone Feb 25, 2019
@TomAugspurger TomAugspurger added Datetime Datetime data dtype Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff ExtensionArray Extending pandas with custom dtypes or arrays. labels Feb 25, 2019
@jorisvandenbossche
Copy link
Member

For 0.24.2, could we do the warning filtering in sort_index ? (awaiting a proper fix in nargsort)

@TomAugspurger
Copy link
Contributor

Not sure, but I'm slightly against filtering within pandas itself...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Datetime Datetime data dtype ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
3 participants