Ray's Knowledge Base
Unlock

A constant column built as first_column * 0 + value inherits nulls and NaN

PitfallVerified 1 Oct 2026Holds project: dftracer-utils
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

with_columns(z=1) or lit(1) gives a null or NaN in some rows. It occurs when the first column of the frame has a null, a NaN or an infinity, or is a string column.

Cause#

_broadcast_scalar computed the constant as column * 0 + value from the first column of the frame. A null in that column stayed null, and NaN * 0 and inf * 0 are NaN.

Fix#

Build the constant with no data from another column: an all-null column of the scalar's type and the frame's length, filled with the value.

Evidence#

Seen on 2026-10-01. On three frames that failed (a null in the first column, lit(1), and a frame with a string first column) the result is now [1, 1, 1]. python -m pytest tests/python/test_expression_gaps.py -q -k constant gave 11 passed, and 5 of those failed on the code before the fix. The OpenSpec change pandas-expression-gaps has the scenarios.