`clip` with a length-1 input and full-length bounds silently truncates to length 1 instead of broadcasting
Checks
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of Polars.
Reproducible example
import polars as pl
s = pl.Series([5])
bounds = pl.Series([1, 2, 3, 4])
print(s.clip(upper_bound=bounds)) # [1], expected [1, 2, 3, 4]
print(s.clip(bounds, bounds + 10)) # [5], expected [5, 5, 5, 5]
# Same thing at the expression level, and the two engines disagree:
lf = pl.LazyFrame({"a": [1.0, 2.0, None, 3.0]})
q = lf.select(x=pl.lit(5).clip(pl.col("a") + 3, pl.col("a") + 10), y="a")
print(q.collect(engine="streaming")) # x = [5, 5, 5, 6], height 4
print(q.collect(engine="in-memory")) # ShapeError: Series x, length 1 doesn't match the DataFrame height of 4Log output
[1]
[5]
shape: (4, 2)
┌─────┬──────┐
│ x ┆ y │
│ --- ┆ --- │
│ i32 ┆ f64 │
╞═════╪══════╡
│ 5 ┆ 1.0 │
│ 5 ┆ 2.0 │
│ 5 ┆ null │
│ 6 ┆ 3.0 │
└─────┴──────┘
polars.exceptions.ShapeError: Series x, length 1 doesn't match the DataFrame height of 4Issue description
When the input to clip has length 1 and at least one bound is full length, the in-memory engine returns a length-1 result. It does not broadcast the input. The value it returns is computed against the first element of the bound only. With select(x=...) alone this gives a wrong, silently truncated result. Next to any other column it raises a ShapeError.
Other elementwise operations with a scalar receiver broadcast as expected (e.g. pl.lit(...).{is_between, fill_null}).
The streaming engine also broadcasts correctly.
Related, but not the same: #27086 / #27087 fixed the mixed scalar/Series bounds path in the same helpers.
Found while working on https://github.com/narwhals-dev/narwhals/issues/3964.
Expected behavior
pl.Series([5]).clip(upper_bound=pl.Series([1, 2, 3, 4])) returns [1, 2, 3, 4]. pl.lit(5).clip(pl.col("a"), ...) broadcasts to the frame height in the in-memory engine, the same way it already does in the streaming engine and for is_between / fill_null.
Installed versions
--------Version info---------
Polars: 1.44.2
Index type: UInt32
Platform: macOS-26.7-arm64-arm-64bit
Python: 3.12.13 (main, Apr 14 2026, 14:33:40) [Clang 22.1.3 ]
Runtime: rt32Source: pola-rs/polars