How to use transform_derived method in pandera

Best Python code snippet using pandera_python

test_decorators.py

Source:test_decorators.py Github

copy

Full Screen

...443def test_check_types_error_output() -> None:444 """Test that check_types raises an error when the output is not correct."""445 df = pd.DataFrame({"a": [1]}, index=["1"])446 @check_types447 def transform_derived(448 df: DataFrame[InSchema],449 ) -> DataFrame[DerivedOutSchema]:450 return df451 with pytest.raises(452 errors.SchemaError, match="column 'b' not in dataframe"453 ):454 transform_derived(df)455 try:456 transform_derived(df)457 except errors.SchemaError as exc:458 assert exc.schema == DerivedOutSchema.to_schema()459 assert exc.data.equals(df)460 df = pd.DataFrame({"a": [1]}, index=["1"])461 @check_types462 def transform(df: DataFrame[InSchema]) -> DataFrame[OutSchema]:463 return df464 with pytest.raises(465 errors.SchemaError, match="column 'b' not in dataframe"466 ):467 transform(df)468 try:469 transform(df)470 except errors.SchemaError as exc:471 assert exc.schema == OutSchema.to_schema()472 assert exc.data.equals(df)473def test_check_types_optional_out() -> None:474 """Test the check_types behaviour when the output schema is Optional."""475 @check_types476 def optional_derived_out(477 df: DataFrame[InSchema], # pylint: disable=unused-argument478 ) -> typing.Optional[DataFrame[DerivedOutSchema]]:479 return None480 df = pd.DataFrame({"a": [1]}, index=["1"])481 assert optional_derived_out(df) is None482 @check_types483 def optional_out(484 df: DataFrame[InSchema], # pylint: disable=unused-argument485 ) -> typing.Optional[DataFrame[OutSchema]]:486 return None487 df = pd.DataFrame({"a": [1]}, index=["1"])488 assert optional_out(df) is None489def test_check_types_optional_in() -> None:490 """Test the check_types behaviour when the input schema is Optional."""491 @check_types492 def optional_in(493 # pylint: disable=unused-argument494 df: typing.Optional[DataFrame[InSchema]],495 ) -> None:496 return None497 assert optional_in(None) is None498def test_check_types_optional_in_out() -> None:499 """500 Test the check_types behaviour when both input and outputs schemas are501 Optional.502 """503 @check_types504 def transform_derived(505 # pylint: disable=unused-argument506 df: typing.Optional[DataFrame[InSchema]],507 ) -> typing.Optional[DataFrame[DerivedOutSchema]]:508 return None509 assert transform_derived(None) is None510 @check_types511 def transform(512 # pylint: disable=unused-argument513 df: typing.Optional[DataFrame[InSchema]],514 ) -> typing.Optional[DataFrame[OutSchema]]:515 return None516 assert transform(None) is None517def test_check_types_coerce() -> None:518 """Test that check_types return the result of validate."""519 @check_types()520 def transform_in(df: DataFrame[InSchema]):521 return df522 df = transform_in(pd.DataFrame({"a": ["1"]}, index=["1"]))523 expected = InSchema.to_schema().columns["a"].dtype...

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