相关疑难解决方法(0)

如何使用假设库创建日期时间索引的 Pandas DataFrame?

我正在尝试使用以下代码创建一个用于代码测试目的pandas DataFramehypothesis库:

from hypothesis.extra.pandas import columns, data_frames
from hypothesis.extra.numpy import datetime64_dtypes

@given(data_frames(index=datetime64_dtypes(max_period='Y', min_period='s'),
                   columns=columns("A B C".split(), dtype=int)))
Run Code Online (Sandbox Code Playgroud)

我收到的错误如下:

E           TypeError: 'numpy.dtype' object is not iterable
Run Code Online (Sandbox Code Playgroud)

我怀疑这是因为当我构造DataFramefor时,index=我只传递一个datetime元素,而不是一个ps.Series带有类型的all datetime。即使是这种情况(我不确定),我仍然不确定如何使用hypothesis库来实现我的目标。

谁能告诉我代码有什么问题以及解决方案是什么?

python pytest pandas python-hypothesis

5
推荐指数
1
解决办法
561
查看次数

标签 统计

pandas ×1

pytest ×1

python ×1

python-hypothesis ×1