Check whether a table has a certain number of rows.
USAGE
has_rows(count=None, *, min=None, max=None)
The has_rows() function returns a callable that, when given a table, checks whether the row count satisfies a specified condition. It is designed for use with the active= parameter of validation methods so that a validation step can be conditionally skipped when the target table is too small, too large, or empty.
The callable supports several modes:
exact count: has_rows(count=N) returns True only if the table has exactly N rows.
minimum: has_rows(min=N) returns True if the table has at least N rows.
maximum: has_rows(max=N) returns True if the table has at most N rows.
range: has_rows(min=A, max=B) returns True if the row count falls within [A, B].
non-empty: has_rows() (no arguments) returns True if the table has at least one row.
A note is attached to any skipped step in the validation report explaining the row count condition that was not met.
The callable is evaluated against the original table before any pre= processing is applied. This means the column check is performed on the raw input data, not on a pre-processed version of it.
Parameters
count:int | None=None
The exact number of rows the table should have. Cannot be used together with min= or max=.
min:int | None=None
The minimum number of rows (inclusive) the table should have. Can be used alone or with max=.
max:int | None=None
The maximum number of rows (inclusive) the table should have. Can be used alone or with min=.
Returns
Callable[[Any], bool]
A callable that accepts a table and returns True if the row count satisfies the specified condition, False otherwise. When the callable returns False, it stores diagnostic information that is used to generate a descriptive note in the validation report.
How It Works
When interrogate() is called, each validation step whose active= parameter is a callable will have that callable evaluated with the target table. If the callable returns False, the step is deactivated and an explanatory note is added to the validation report. The note is locale-aware: if the Validate object was created with a non-English locale=, the note will be translated accordingly.
The first two steps ran because the table has exactly 3 rows (matching count=3) and falls within the range [2, 10]. The third step was skipped because 3 does not equal 100.