简体   繁体   English

FutureWarning:使用“datetime64[ns]”dtype 将时区感知的 DatetimeArray 转换为时区天真的 ndarray

[英]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.

相关问题 使用时区感知和时区天真日期时间列处理 CSV - Handling CSV with timezone-aware and timezone-naive datetime column Python-给定一个时区感知的datetime对象,如何获取未时区的UTC datetime对象? - Python - given a timezone-aware datetime object how do I get a timezone-naive UTC datetime object? 使用SQLAlchemy将时区Aware datetime64 [ns]插入MySQL - Insert Timezone Aware datetime64[ns] into MySQL with SQLAlchemy 在 Python 中将时区感知日期时间转换为本地时间 - Converting timezone-aware datetime to local time in Python 将datetime obj转换为可识别时区的datetime - Convert datetime obj to timezone-aware datetime 将大系列从 datetime64[ns] 转换为带时区的 ISO 格式(存储为对象类型) - Converting large series from datetime64[ns] to ISO format with timezone (store as object type) 将熊猫时区感知 DateTimeIndex 转换为朴素的时间戳,但在某些时区 - Convert pandas timezone-aware DateTimeIndex to naive timestamp, but in certain timezone Django:如何以时区感知方式检索日期时间 - Django: How to retrieve datetime as timezone-aware 将时区感知日期时间保存为字符串,然后将其恢复为日期时间 - Save a timezone-aware datetime to a string, then restore it back to a datetime later 我可以有一个时区感知的datetime.date对象吗? - Can I have a timezone-aware datetime.date object?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM