[英]FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive ndarray with 'datetime64[ns]' dtype
我從 Pandas 0.20.3 升級到 Pandas 0.24.1。 在運行命令ts.sort_index(inplace=True)
,我在測試輸出中收到FutureWarning
,如下所示。 我可以更改方法調用以抑制以下警告嗎? 我很高興保持舊的行為。
/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 之前,我的索引如下所示:
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)
我在此處重寫了您的問題,以包含 MCVE。 過了一段時間沒有回應后,我發布了一個針對 Pandas 的問題。
這是我的解決方法:
with warnings.catch_warnings():
# Bug in Pandas emits useless warning when sorting tz-aware index
warnings.simplefilter("ignore")
ds = df.sort_index()
如果我是你,我會使用 pip 並設置以前的版本進行降級。 這是更懶惰的答案。 但是如果你真的想保持它的升級,那么在pandas數據框中有一個參數調用已棄用警告。 只需根據您的需要進行相應調整。 您可以使用 pandas 的文檔進行檢查。 有一個美好的夜晚
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.