Row Constraints API
NotNull
ydata.constraints.rows.constraint.NotNull
Bases: RowConstraint
Check that values in the specified columns are not null.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
str | list[str]
|
Column(s) that must not contain null / NaN values. |
required |
name
|
str | None
|
Human-readable label shown in engine summaries. |
None
|
validate(dataset)
Validate the constraint against a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
Dataset to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
pdDataFrame |
DataFrame
|
Boolean mask with one row per dataset row and one column
per constrained column, |
Unique
ydata.constraints.rows.constraint.Unique
Bases: RowConstraint
Check that values in the specified columns contain no duplicates.
A row is flagged as violating when its value appears more than once in that column. This is the standard uniqueness / primary-key check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
str | list[str]
|
Column(s) whose values must be unique. |
required |
name
|
str | None
|
Human-readable label shown in engine summaries. |
None
|
validate(dataset)
Validate the constraint against a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
Dataset to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
pdDataFrame |
DataFrame
|
Boolean mask with one row per dataset row and one column
per constrained column, |
GreaterThan
ydata.constraints.rows.constraint.GreaterThan
Bases: RowConstraint
Check that values in one or more columns are greater than a value or another column.
Against a number the comparison is strict (>). Against another
column it is inclusive (>=), and only one column can be constrained.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
str | list[str]
|
Column(s) to check. |
required |
value
|
float | str
|
A number, or the name of the column to compare against. |
required |
Example
GreaterThan(columns="end_date", value="start_date")
validate(dataset)
Validate the constraint against a dataset.
Args: dataset (Dataset): Dataset to test
Returns:
| Name | Type | Description |
|---|---|---|
pdDataFrame |
DataFrame
|
constraint mask |
LowerThan
ydata.constraints.rows.constraint.LowerThan
Bases: RowConstraint
Check that values in one or more columns are lower than a value or another column.
Against a number the comparison is strict (<). Against another
column it is inclusive (<=), and only one column can be constrained.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
str | list[str]
|
Column(s) to check. |
required |
value
|
float | str
|
A number, or the name of the column to compare against. |
required |
Example
LowerThan(columns="discount", value=100)
validate(dataset)
Validate the constraint against a dataset.
Args: dataset (Dataset): Dataset to test
Returns:
| Name | Type | Description |
|---|---|---|
pdDataFrame |
DataFrame
|
constraint mask |
Between
ydata.constraints.rows.constraint.Between
Bases: RowConstraint
Check that values in one or more columns lie in [lower_bound, upper_bound].
Both bounds are inclusive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
str | list[str]
|
Column(s) to check. |
required |
lower_bound
|
int | float
|
Minimum allowed value. |
required |
upper_bound
|
int | float
|
Maximum allowed value. |
required |
Example
Between(columns="age", lower_bound=18, upper_bound=99)
validate(dataset)
Validate the constraint against a dataset.
Args: dataset (Dataset): Dataset to test
Returns:
| Name | Type | Description |
|---|---|---|
pdDataFrame |
DataFrame
|
constraint mask |
Positive
ydata.constraints.rows.constraint.Positive
Bases: GreaterThan
Check that values in one or more columns are strictly greater than 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
str | list[str]
|
Column(s) to check. |
required |
NotIncludedIn
ydata.constraints.rows.constraint.NotIncludedIn
Bases: RowConstraint
Check that values in a column are NOT in a specified blocklist.
This is the complement of :class:IncludedIn — rows containing any of
the forbidden values are flagged as violations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
str
|
Column on which the constraint is applied. |
required |
values
|
list[Any] | Any
|
Single value or list of values that are not allowed. |
required |
name
|
str | None
|
Human-readable label shown in engine summaries. |
None
|
validate(dataset)
Validate the constraint against a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
Dataset to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
pdDataFrame |
DataFrame
|
Boolean mask with one row per dataset row and one column
per constrained column, |
IncludedIn
ydata.constraints.rows.constraint.IncludedIn
Bases: RowConstraint
Check that values in a column belong to an allowed set.
Null values are violations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
str
|
Column to check. |
required |
values
|
list[Any] | Any
|
Allowed value, or list of allowed values. |
required |
Example
IncludedIn(column="status", values=["open", "closed"])
validate(dataset)
Validate the constraint against a dataset.
Args: dataset (Dataset): Dataset to test
Returns:
| Name | Type | Description |
|---|---|---|
pdDataFrame |
DataFrame
|
constraint mask |
StringLength
ydata.constraints.rows.constraint.StringLength
Bases: RowConstraint
Check that string values in the specified columns have an acceptable length.
Length is measured in characters after coercing to str. Both bounds
are inclusive. Omit max_length to only enforce a minimum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
str | list[str]
|
Column(s) to check. |
required |
min_length
|
int
|
Minimum allowed string length (inclusive). Defaults to 0. |
0
|
max_length
|
int | None
|
Maximum allowed string length (inclusive). |
None
|
name
|
str | None
|
Human-readable label shown in engine summaries. |
None
|
validate(dataset)
Validate the constraint against a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
Dataset to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
pdDataFrame |
DataFrame
|
Boolean mask with one row per dataset row and one column
per constrained column, |
Monotonic
ydata.constraints.rows.constraint.Monotonic
Bases: RowConstraint
Check that values in a column are monotonically ordered.
Row i is flagged as violating when it breaks the ordering relative to
row i-1. The first row always passes (no predecessor to compare to).
Works with numeric and datetime columns. For strictly increasing/decreasing sequences, equal consecutive values are treated as violations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
str | list[str]
|
Column(s) to check. |
required |
increasing
|
bool
|
If |
True
|
strict
|
bool
|
If |
False
|
name
|
str | None
|
Human-readable label shown in engine summaries. |
None
|
validate(dataset)
Validate the constraint against a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
Dataset to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
pdDataFrame |
DataFrame
|
Boolean mask with one row per dataset row and one column
per constrained column, |
Regex
ydata.constraints.rows.constraint.Regex
Bases: RowConstraint
Check that values in a column fully match a regular expression.
Values are converted to str before matching; the whole value must
match (re.fullmatch).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
str
|
Column to check. |
required |
regex
|
str
|
Regular expression pattern. |
required |
Example
Regex(column="zip_code", regex=r"\d{5}")
validate(dataset)
Validate the constraint against a dataset.
Args: dataset (Dataset): Dataset to test
Returns:
| Name | Type | Description |
|---|---|---|
pdDataFrame |
DataFrame
|
constraint mask |
BetweenDates
ydata.constraints.rows.constraint.BetweenDates
Bases: RowConstraint
Check that a date column is within a window of days relative to another date column.
A row passes when reference + lower_bound days <= constrained <=
reference + upper_bound days (both bounds inclusive).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constrained_column
|
str
|
Date column being checked. |
required |
reference_column
|
str
|
Date column the window is anchored to. |
required |
lower_bound
|
int
|
Start of the window, in days from the reference. |
required |
upper_bound
|
int
|
End of the window, in days from the reference. |
required |
Example
BetweenDates(constrained_column="ship_date", reference_column="order_date", ... lower_bound=0, upper_bound=7)
validate(dataset)
Validate the constraint against a dataset.
Args: dataset (Dataset): Dataset to test
Returns:
| Name | Type | Description |
|---|---|---|
pdDataFrame |
DataFrame
|
constraint mask |
RelationConstraint
ydata.constraints.rows.constraint.RelationConstraint
Bases: RowConstraint
Check that each row's key and values match an allowed combination in a reference table.
A row passes when its key (key_columns) exists in the reference and
each value column holds one of the values allowed for that key. In the
reference, a value cell can be a scalar or a list of allowed values.
Rows with a null key or value are violations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
DataFrame
|
DataFrame with the allowed combinations. |
required |
key_columns
|
list[str]
|
Columns that form the lookup key. Must hold scalars in the reference. |
required |
value_columns
|
list[str]
|
Columns whose allowed values depend on the key. |
required |
Example
ref = pd.DataFrame({"country": ["PT", "US"], "currency": ["EUR", "USD"]}) RelationConstraint(reference=ref, key_columns=["country"], value_columns=["currency"])
CombineConstraints
ydata.constraints.rows.constraint.CombineConstraints
Bases: RowConstraint
Combine several row constraints into one.
Each constraint is first reduced to one boolean per row (a row passes when all its constrained columns pass). The results are then combined:
Operation.MERGE: the row passes when every constraint passes (AND).Operation.XNOR(default): the row passes when either all constraints pass or none do.Operation.CHAINis an alias kept for backwards compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraints
|
list[RowConstraint]
|
Row constraints to combine. |
required |
operation
|
Operation
|
How to combine them. Defaults to |
XNOR
|
validate(dataset)
Validate the constraint against a dataset.
Args: dataset (Dataset): Dataset to test
Returns:
| Name | Type | Description |
|---|---|---|
pdDataFrame |
DataFrame
|
constraint mask |
RowCustomConstraint
ydata.constraints.rows.constraint.RowCustomConstraint
Bases: RowConstraint
Check a user-defined condition row by row.
With axis="column" (default), check receives the dataset as a
pandas.DataFrame (or each entity group) and returns a boolean
DataFrame or Series. With axis="rows", check is applied to each
row and returns a boolean.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
check
|
Callable
|
Callable returning the boolean mask (or a boolean per row). |
required |
columns
|
str | list[str] | None
|
Column(s) the result is reported on. When omitted, every
column returned by |
None
|
name
|
str | None
|
Human-readable label shown in engine summaries. |
None
|
axis
|
Axis
|
|
'column'
|
available_columns
|
list[str] | None
|
Extra columns the check reads but which are not reported on. |
None
|
entity
|
str | None
|
Column that identifies an entity (e.g. a customer id). When
set, |
None
|
Example
RowCustomConstraint(check=lambda df: df["end"] >= df["start"], columns="end")