How to use invalid_input_dataframe method in pandera

Best Python code snippet using pandera_python

test_from_to_format_conversions.py

Source:test_from_to_format_conversions.py Github

copy

Full Screen

...51 to_format = "pickle"52def mock_dataframe() -> pd.DataFrame:53 """Create a valid mock dataframe."""54 return pd.DataFrame({"str_col": ["a"], "int_col": [1]})55def invalid_input_dataframe() -> pd.DataFrame:56 """Invalid data under the InSchema* models defined above."""57 return pd.DataFrame({"str_col": ["a"]})58@pytest.mark.parametrize(59 "schema,to_fn,buf_cls",60 [61 [InSchemaCsv, lambda df, x: df.to_csv(x, index=None), io.StringIO],62 [InSchemaDict, lambda df: df.to_dict(orient="records"), None],63 [64 InSchemaJson,65 lambda df, x: df.to_json(x, orient="records"),66 io.StringIO,67 ],68 [InSchemaJson, lambda df: df.to_json(orient="records"), None],69 [InSchemaFeather, lambda df, x: df.to_feather(x), io.BytesIO],70 [InSchemaParquet, lambda df, x: df.to_parquet(x), io.BytesIO],71 [InSchemaPickle, lambda df, x: df.to_pickle(x), io.BytesIO],72 ],73)74def test_from_format(schema, to_fn, buf_cls):75 """76 Test that check_types-guarded function reads data from source serialization77 format.78 """79 @pa.check_types80 def fn(df: pa.typing.DataFrame[schema]):81 return df82 for df, invalid in [83 (mock_dataframe(), False),84 (invalid_input_dataframe(), True),85 ]:86 buf = None if buf_cls is None else buf_cls()87 arg = to_fn(df, *([buf] if buf else []))88 if buf:89 if buf.closed:90 pytest.skip(91 "skip test for older pandas versions where to_pickle "92 "closes user-provided buffers: "93 "https://github.com/pandas-dev/pandas/issues/35679"94 )95 buf.seek(0)96 arg = buf97 if invalid:98 with pytest.raises(pa.errors.SchemaError):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful