when generating examples between 2 dates: hypothesis.errors.Unsatisfiable: Unable to satisfy assumptions of example_generating_inner_function #803
|
When trying to generate a column with dates between 2 dates, I get error hypothesis.errors.Unsatisfiable: Unable to satisfy assumptions of example_generating_inner_function import pandas as pd
import pandera as pa
from pandera.engines import pandas_engine
schema = pa.DataFrameSchema(
{
"eventdate": pa.Column(pandas_engine.DateTime,
checks=[
pa.Check.lt(pd.to_datetime("1/1/2019", dayfirst=True)),
pa.Check.gt(pd.to_datetime("1/1/2015", dayfirst=True)),
]
),
}
)
schema.example(50)Expected behaviordata should be dates between the 2 dates in the checks Desktop (please complete the following information):
|
Replies: 4 comments
|
hi @telferm57 this is a current limitation in the data synthesis strategies module re: check strategy chaining. The upshot is that you can use import pandas as pd
import pandera as pa
from pandera.engines import pandas_engine
schema = pa.DataFrameSchema(
{
"eventdate": pa.Column(
pandas_engine.DateTime,
checks=[
pa.Check.in_range(
pd.to_datetime("1/1/2015", dayfirst=True),
pd.to_datetime("1/1/2019", dayfirst=True)
),
]
),
}
)
print(schema.example(50))Improvements need to be made on this front... the primary gotcha is that the first check is used in concert with the datatype to generate initial candidate values per column, and subsequent checks filter out/replace invalid values... this makes long check suites subject to a high probability of raising an |
|
AH, I see - so the first check in my example generates all dates that are < 2019, but also < 2015 , so no samples are available to satisfy second check ? |
|
Yep! This is a current limitation in the strategies module, which would require something like a statistics resolver that collects statistics across all the checks per column so that this won't be so much of an issue. |
|
Hi @telferm57 do you mind marking #803 as the answer? (hopefully it actually answered your question!) Also I converted this into a discussion to make it easier to find for others |
hi @telferm57 this is a current limitation in the data synthesis strategies module re: check strategy chaining. The upshot is that you can use
in_rangechecks to achieve what you want:Improvements need to be made on this front... the primary gotcha…