假设在给定的测试数据帧中使用 pd.datetime dtype 创建列

Vik*_*tor 3 python unit-testing pandas python-hypothesis

我想测试某种方法是否可以处理 pandas 数据框中的不同日期,并将其作为参数。下面的示例应该阐明我想要什么样的设置。在该示例中,column('Date', dtype=pd.datetime)不适用于在测试数据框中创建日期列:

from hypothesis import given
from hypothesis.extra.pandas import column, data_frames
import pandas as pd
from unittest import TestCase

class TestExampleClass(TestCase):

    @given(data_frames([column('A', dtype=str), column('B', dtype=int),column('Date', dtype=pd.datetime)]))
    def test_example_test_method(self, dataframe):
        self.assertTrue(True)

Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我知道如何使用假设库创建日期时间索引的 pandas DataFrame?,但这对我的具体情况没有帮助。

Zac*_*dds 5

使用dtype="datetime64[ns]"而不是dtype=pd.datetime.


我已经打开了一个问题来更详细地研究这个问题,并在传递pd.datetimedatetime或无单位日期时间数据类型时给出有用的错误消息;这种混乱不是我们想要提供的用户体验!