Pvlib-Python 日期时间错误 'Is not convertible to datetime'

Pvlib-Python Datetime Error 'Is not convertible to datetime'

我正在尝试使用 PVLib-Python 命令 model.get_data(longitude, latitude, start, end)model.get_processed_data(latitude, longitude, start, end)(其中 model = GFS())访问预测数据,但我收到此错误:TypeError :<class 'cftime._cftime.DatetimeGregorian'> is not convertible to datetime

我已经使用了很多版本的 PVLib-Python,但都没有用。此外,我检查了官方文档,但它们在 te 文档中出现了相同的错误(此处为论文的第 121 至 124 页 https://readthedocs.org/projects/cwhanse-pvlib-python/downloads/pdf/latest/)。

下面是一些基本代码:

import pandas as pd
import datetime
from pvlib.forecast import GFS, HRRR_ESRL, NAM, NDFD, HRRR, RAP 

latitude = 32.2
longitude = -110.9 
tz = 'America/Phoenix'

start = pd.Timestamp(datetime.date.today(), tz=tz) # today's date
end = start + pd.Timedelta(days=7) # 7 days from today

model = GFS()

data = model.get_data(latitude, longitude, start, end)

data.plot(figsize=(12,12), subplots=True)

错误发生在日期时间 class,它在 cftime 包中。当我使用 cftime 1.1.1.2 版本时出现错误,而当我使用 1.0.3.4 版本时没有出现错误。

最简单的解决方案是降低 cftime 包的等级。如果您使用的是 Anaconda,那么 运行 在 Anaconad 提示符下执行以下命令即可:

conda install -c conda-forge cftime=1.0.3.4

cftime 的项目网站上有一些关于该主题的讨论:https://pypi.org/project/cftime/

更新:该错误已在新的 pvlib 版本 pvlib-0.7.2 中修复。该错误在此处进一步描述:https://github.com/pvlib/pvlib-python/issues/895