I want to test whether a certain method can handle different dates in a pandas dataframe, which it takes as an argument. The following example should clarify what kind of setup I want. In the example column('Date', dtype=pd.datetime)
does not work for creating a date column in the test dataframe:
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)
Any ideas? I am aware of How to create a datetime indexed pandas DataFrame with hypothesis library?, but it did not help for my specific case.
Use dtype="datetime64[ns]"
instead of dtype=pd.datetime
.
I've opened an issue to look into this in more detail and give helpful error messages when passed pd.datetime
, datetime
, or a unitless datetime dtype; this kind of confusion isn't the user experience we want to offer!