def test_non_nullable_column_constraint(): test_dataframe = DataFrame({'foo': ['baz']}) assert NonNullableColumnConstraint().validate(test_dataframe, 'foo') is None bad_test_dataframe = DataFrame({'foo': ['baz', None]}) with pytest.raises(ConstraintViolationException): NonNullableColumnConstraint().validate(bad_test_dataframe, 'foo')
def test_non_nullable_column_constraint(): test_dataframe = DataFrame({"foo": ["baz"]}) assert NonNullableColumnConstraint().validate(test_dataframe, "foo") is None bad_test_dataframe = DataFrame({"foo": ["baz", None]}) with pytest.raises(ConstraintViolationException): NonNullableColumnConstraint().validate(bad_test_dataframe, "foo")
def _construct_keyword_constraints(non_nullable, unique): non_nullable = check.bool_param(non_nullable, 'exists') unique = check.bool_param(unique, 'unique') constraints = [] if non_nullable: constraints.append(NonNullableColumnConstraint()) if unique: constraints.append(UniqueColumnConstraint()) return constraints
def _construct_keyword_constraints(non_nullable, unique, ignore_missing_vals): non_nullable = check.bool_param(non_nullable, "exists") unique = check.bool_param(unique, "unique") ignore_missing_vals = check.bool_param(ignore_missing_vals, "ignore_missing_vals") if non_nullable and ignore_missing_vals: raise DagsterInvariantViolationError( "PandasColumn cannot have a non-null constraint while also ignore missing values" ) constraints = [] if non_nullable: constraints.append(NonNullableColumnConstraint()) if unique: constraints.append(UniqueColumnConstraint(ignore_missing_vals=ignore_missing_vals)) return constraints
def test_dataframe_description_generation_multi_constraints(): TestDataFrame = create_dagster_pandas_dataframe_type( name="TestDataFrame", columns=[ PandasColumn( name="foo", constraints=[ ColumnDTypeInSetConstraint({"int64"}), InRangeColumnConstraint(0, 100, ignore_missing_vals=False), NonNullableColumnConstraint(), ], ), ], ) assert ( TestDataFrame.description == "\n### Columns\n**foo**: `int64`\n+ 0 < values < 100\n+ No Null values allowed.\n\n" )
def test_dataframe_description_generation_multi_constraints(): TestDataFrame = create_dagster_pandas_dataframe_type( name='TestDataFrame', columns=[ PandasColumn( name='foo', constraints=[ ColumnTypeConstraint('int64'), InRangeColumnConstraint(0, 100), NonNullableColumnConstraint(), ], ), ], ) assert ( TestDataFrame.description == "\n### Columns\n**foo**: `int64`\n+ 0 < values < 100\n+ No Null values allowed.\n\n" )