[英]FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive ndarray with 'datetime64[ns]' dtype
I upgraded from pandas 0.20.3 to pandas 0.24.1.我从 Pandas 0.20.3 升级到 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.在运行命令ts.sort_index(inplace=True)
,我在测试输出中收到FutureWarning
,如下所示。 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)
My index looks like the following prior to running the sort_index:在运行 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.我在此处重写了您的问题,以包含 MCVE。 After it went a while with no responses, I posted an issue against Pandas.过了一段时间没有回应后,我发布了一个针对 Pandas 的问题。
Here's my workaround:这是我的解决方法:
with warnings.catch_warnings():
# Bug in Pandas emits useless warning when sorting tz-aware index
warnings.simplefilter("ignore")
ds = df.sort_index()
If I were you, I would do a downgrade using pip and setting the previous version.如果我是你,我会使用 pip 并设置以前的版本进行降级。 It's the lazier answer.这是更懒惰的答案。 But if you really want to keep it upgraded, then there is a parameter call deprecated warning inside pandas data frame.但是如果你真的想保持它的升级,那么在pandas数据框中有一个参数调用已弃用警告。 Just adjust it accordingly what you need.只需根据您的需要进行相应调整。 You can check it using the documentation of pandas.您可以使用 pandas 的文档进行检查。 Have a nice night有一个美好的夜晚
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.