Skip to content

ConstraintEngine

ydata.constraints.engine.ConstraintEngine

add_constraint(constraint)

Add a single constraint to the engine.

Parameters:

Name Type Description Default
constraint Constraint

A constraint

required

add_constraints(constraints)

Add some constraint to the engine.

Parameters:

Name Type Description Default
constraints List[Constraint]

List of constraints

required

explain_constraints()

Explain the constraints in the engine using the constraint representation.

Returns:

Type Description
dict[str, str]

dict[str, str]: constraint explanation

filter(dataset)

Return a new Dataset with only the rows that pass all row constraints.

Filtering is based on row constraints only; column constraints are still reported in summary() but do not remove rows.

Parameters:

Name Type Description Default
dataset Dataset

Dataset to filter. Will be validated if the engine has not been validated yet.

required

Returns:

Name Type Description
Dataset Dataset

New Dataset containing only rows that satisfy every row constraint. If there are no row constraints, returns the dataset unchanged.

summary(include_rows=False)

Return the constraint summary for a validated constraint engine instance.

Parameters:

Name Type Description Default
include_rows bool

If True, includes the violated rows mask

False

Returns:

Name Type Description
dict dict

violated rows summary

validate(dataset)

Validate the engine against a dataset.

Parameters:

Name Type Description Default
dataset Dataset

Dataset against which to validate the constraints

required

violated_columns(constraint)

Return the violated columns report for a particular constraint.

Parameters:

Name Type Description Default
constraint Union[Constraint, str]

Constraint

required

Returns:

Name Type Description
dict dict

violated columns report

violated_rows(constraint)

Return the violated rows report for a particular constraint, including the violated rows mask.

Parameters:

Name Type Description Default
constraint Union[Constraint, str]

Constraint

required

Returns:

Name Type Description
dict dict

violated rows report