FutureWarning:使用'datetime64 [ns]'dtype将时区感知的DatetimeArray转换为时区未使用的ndarray [英] FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive ndarray with 'datetime64[ns]' dtype

查看:168
本文介绍了FutureWarning:使用'datetime64 [ns]'dtype将时区感知的DatetimeArray转换为时区未使用的ndarray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从熊猫0.20.3升级到了熊猫0.24.1.运行命令ts.sort_index(inplace=True)时,我在测试输出中得到一个FutureWarning,如下所示.我可以更改方法调用以禁止出现以下警告吗?我很乐意保留以前的行为.

I upgraded from pandas 0.20.3 to pandas 0.24.1. While running the command ts.sort_index(inplace=True), I am getting a FutureWarning in my test output, which is shown below. Can I change the method call to suppress the following warning? I am happy to keep the old behavior.

/lib/python3.6/site-packages/pandas/core/sorting.py:257: FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive ndarray with 'datetime64[ns]' dtype. In the future, this will return an ndarray with 'object' dtype where each element is a 'pandas.Timestamp' with the correct 'tz'.
    To accept the future behavior, pass 'dtype=object'.
    To keep the old behavior, pass 'dtype="datetime64[ns]"'.
  items = np.asanyarray(items)

在运行sort_index之前,我的索引如下所示:

My index looks like the following prior to running the sort_index:

ts.index                                                                                                                                                                               
DatetimeIndex(['2017-07-05 07:00:00+00:00', '2017-07-05 07:15:00+00:00',
               '2017-07-05 07:30:00+00:00', '2017-07-05 07:45:00+00:00',
               ...
               '2017-07-05 08:00:00+00:00'],
              dtype='datetime64[ns, UTC]', name='start', freq=None)

推荐答案

我重写了您的问题

I rewrote your question here, to include an MCVE. After it went a while with no responses, I posted an issue against Pandas.

这是我的解决方法:

with warnings.catch_warnings():
    # Bug in Pandas emits useless warning when sorting tz-aware index
    warnings.simplefilter("ignore")
    ds = df.sort_index()

这篇关于FutureWarning:使用'datetime64 [ns]'dtype将时区感知的DatetimeArray转换为时区未使用的ndarray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆