Best Python code snippet using pandera_python
test_typing.py
Source:test_typing.py
...65class SchemaINT64(pa.SchemaModel):66 col: Series[pa.typing.INT64]67class SchemaUINT64(pa.SchemaModel):68 col: Series[pa.typing.UINT64]69def _test_literal_pandas_dtype(70 model: Type[pa.SchemaModel], pandas_dtype: DataType71):72 schema = model.to_schema()73 expected = pa.Column(pandas_dtype, name="col").dtype74 assert schema.columns["col"].dtype == expected75@pytest.mark.parametrize(76 "model, pandas_dtype",77 [78 (SchemaBool, pa.Bool),79 (SchemaDateTime, pa.DateTime),80 (SchemaCategory, pa.Category),81 (SchemaFloat, pa.Float),82 (SchemaFloat16, pa.Float16),83 (SchemaFloat32, pa.Float32),84 (SchemaFloat64, pa.Float64),85 (SchemaInt, pa.Int),86 (SchemaInt8, pa.Int8),87 (SchemaInt16, pa.Int16),88 (SchemaInt32, pa.Int32),89 (SchemaInt64, pa.Int64),90 (SchemaUInt8, pa.UInt8),91 (SchemaUInt16, pa.UInt16),92 (SchemaUInt32, pa.UInt32),93 (SchemaUInt64, pa.UInt64),94 (SchemaObject, pa.Object),95 (SchemaString, pa.String),96 (SchemaTimedelta, pa.Timedelta),97 ],98)99def test_literal_legacy_pandas_dtype(100 model: Type[pa.SchemaModel], pandas_dtype: DataType101):102 """Test literal annotations with the legacy pandas dtypes."""103 _test_literal_pandas_dtype(model, pandas_dtype)104@pytest.mark.parametrize(105 "model, pandas_dtype",106 [107 (SchemaUINT8, pa.UINT8),108 (SchemaUINT16, pa.UINT16),109 (SchemaUINT32, pa.UINT32),110 (SchemaUINT64, pa.UINT64),111 (SchemaUINT8, pa.UINT8),112 (SchemaUINT16, pa.UINT16),113 (SchemaUINT32, pa.UINT32),114 (SchemaUINT64, pa.UINT64),115 ],116)117def test_literal_new_pandas_dtype(118 model: Type[pa.SchemaModel], pandas_dtype: DataType119):120 """Test literal annotations with the new nullable pandas dtypes."""121 _test_literal_pandas_dtype(model, pandas_dtype)122class SchemaFieldCategoricalDtype(pa.SchemaModel):123 col: Series[pd.CategoricalDtype] = pa.Field(124 dtype_kwargs={"categories": ["b", "a"], "ordered": True}125 )126def _test_annotated_dtype(127 model: Type[pa.SchemaModel],128 dtype: Type,129 dtype_kwargs: Optional[Dict[str, Any]] = None,130):131 dtype_kwargs = dtype_kwargs or {}132 schema = model.to_schema()133 actual = schema.columns["col"].dtype134 expected = pa.Column(dtype(**dtype_kwargs), name="col").dtype135 assert actual == expected...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!