我正在使用假设数据框来实现一个数据框,其中 start_time 和 end_time 是两列。这是一个大块:
import hypothesis.strategies as st
import logging
import datetime
from hypothesis import given
from hypothesis.extra.pandas import column, data_frames, range_indexes
current_time = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
datetime_st = st.integers(
min_value=(current_time + datetime.timedelta(hours=4)).timestamp(),
max_value=(current_time + datetime.timedelta(hours=20)).timestamp(),
)
df_columns = {
# other fields omitted
"start_time": {"elements": datetime_st, "unique": False},
"end_time": {"elements": datetime_st, "unique": False},
}
test_dfs = data_frames(
index=range_indexes(min_size=20, max_size=100),
columns=[column(key, **value) for key, value in df_columns.items()],
)
@given(df=test_dfs)
def test_hyothesis(df):
logging.info(df)
assert 1
我无法找到一个解决方案来断言每个 start_time 应该大于其相应的 end_time 至少 delta。我已经尝试过composite
了,但我不确定如何在dataframes
.
有没有办法在初始化 start_time 和 end_time 时强制执行增量作为规则?