Polars literal-comparison length errors: verify the row-mask contract
Equivalent comparisons can take different scalar and row-wise paths. Check the boundary where the mask must be materialized.
Equivalent values do not establish equivalent result length
Distinguish a scalar expression from a row-wise filter-mask length contract. A condition being equal for every row does not authorize supplying one element where row-wise output was required. Specify where broadcasting is intended so failure handling stays consistent. [1, 2, 3]
A report involving a left-hand literal
Polars issue 30518 demonstrates differing output lengths when comparing a literal-derived column depending on the literal's position. It includes controls using a list-derived column with the same values and the streaming path. The source explains that data-dependent branches can let one batch succeed while another fails. [1]
Do not cover the error by copying the first decision
Run left- and right-literal controls and record mask and input lengths. Do not arbitrarily apply the first decision to all rows to avoid an error. After selecting a supported expression, verify both the meaning of each original row's decision and the required length. [1, 3]
When a materialized mask must have 3 rows
For illustrative input with 3 rows and a row-mask boundary, expected length is 3. A materialized mask of 3 rows supplies a decision for each input row. A length of 1 does not provide the row-wise result required at this boundary. This does not forbid another path explicitly supporting scalar broadcasting. If execution raises, do not record a successful mask; hand over the failure state too. [1, 3]
Connect Truthound to the length audit table
Truthound Core's ExpressionValidator can use filter_expr to specify the relationship between input_rows and mask_rows. Extract them from the actual mask and execution record, keeping input row count separate from the row count of a one-row audit table. The validator does not recover failed expression execution. Correct the path to a supported row-materializing expression and compare again. [1, 2, 3]
Application conditions
Record input_rows and actual materialized mask_rows as audit values for the same expression_form execution, defining the row-wise-mask contract first.
Alternatives
Use a supported expression that constructs an explicit row-wise mask.
Limitations
This check does not declare legitimate scalar broadcasting an error. Execution failure cannot be replaced by a data-quality pass.
Evidence
- Event checked
- Subject checked
- Modified
