def test_dataframe_schema_update_column(column, column_to_update, update, assertion_fn): """Test that DataFrameSchema columns create updated copies.""" schema = DataFrameSchema({"col": column}) if assertion_fn is ValueError: with pytest.raises(ValueError): schema.update_column(column_to_update, **update) return new_schema = schema.update_column(column_to_update, **update) assertion_fn(schema, new_schema)
def test_dataframe_coerce_regex(): """Test dataframe pandas dtype coercion for regex columns""" schema = DataFrameSchema( columns={"column_": Column(float, regex=True, required=False)}, pandas_dtype=int, coerce=True, ) no_match_df = pd.DataFrame({"foo": [1, 2, 3]}) match_valid_df = pd.DataFrame({ "column_1": [1, 2, 3], "column_2": ["1", "2", "3"], }) schema(no_match_df) schema(match_valid_df) # if the regex column is required, no matches should raise an error schema_required = schema.update_column("column_", required=True) with pytest.raises(errors.SchemaError, match="Column regex name='column_' did not match"): schema_required(no_match_df)