You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to temporarily disable Panderas validation for something like a test?
Hi there, I've been enjoying using Pandera a lot and it's great in production and when working with larger complex codes. However, I am noticing I have a problem when testing.
My scenario is this: I have a large function that needs to take in a large validated data frame, with say ~15 columns. My function then calls sub-functions that need approx ~1-5 of the columns of the data frame. When I want to test these sub-functions, I would like to not have to create my whole validated data frame in the tests. Thus, I'd like to be able to turn off validation, during runtime temporarily. Is this possible? If not, it would be great it there was some kind of method like with pandera.no_validation():
I know about using PANDERA_VALIDATION_ENABLED=False but the problem is that this is then global for all functions. I would like to at runtime turn it off temporarily and not globally at import. Below an example of what the problem is
importpandasaspdimportpanderaaspafrompanderaimportColumn, DataFrameSchemaclassValidatedDf:
df: pd.DataFrame_schema=DataFrameSchema(
coerce=True,
columns={
"col1": Column(pa.String, unique=True),
"col2": Column(pa.Int, pa.Check.greater_than(0)),
"col3": Column(pa.Float, nullable=True),
},
)
def__init__(self, df: pd.DataFrame):
object.__setattr__(self, "df", self.__class__._schema(df, lazy=True))
defsub_function(validated_df: ValidatedDf):
returnvalidated_df.df["col2"].sum()
defbig_function(validated_df: ValidatedDf):
important_number=sub_function(validated_df)
deftest_sub_function():
df=pd.DataFrame(
{
"col1": ["a", "b", "c"],
"col2": [1, 2, 3],
}
)
# This will errorvalidated_df=ValidatedDf(df)
# And we can't actually check the real stuffassertsub_function(validated_df) ==6test_sub_function()
Is it possible to temporarily disable Panderas validation for something like a test?
Hi there, I've been enjoying using Pandera a lot and it's great in production and when working with larger complex codes. However, I am noticing I have a problem when testing.
My scenario is this: I have a large function that needs to take in a large validated data frame, with say ~15 columns. My function then calls sub-functions that need approx ~1-5 of the columns of the data frame. When I want to test these sub-functions, I would like to not have to create my whole validated data frame in the tests. Thus, I'd like to be able to turn off validation, during runtime temporarily. Is this possible? If not, it would be great it there was some kind of method like
with pandera.no_validation():
I know about using
PANDERA_VALIDATION_ENABLED=False
but the problem is that this is then global for all functions. I would like to at runtime turn it off temporarily and not globally at import. Below an example of what the problem isIt would be great if the end could work like:
If something like this exists, please point me in the right direction!
The text was updated successfully, but these errors were encountered: