pola-rs/polars · error · ValueError

reinterpret requires exactly one of `signed` or `dtype` to b

Error message

reinterpret requires exactly one of `signed` or `dtype` to be specified

What it means

Expr.reinterpret requires exactly one of `signed` or `dtype`: it either flips signedness via signed=True/False or reinterprets the raw bits into a target dtype. Passing both (or neither) fails the (signed is None) == (dtype is None) check with ValueError. This is a bitwise re interpretation — no value conversion — so the argument must fully determine the output type.

Source

Thrown at py-polars/src/polars/expr/expr.py:7115

        ...     [
        ...         pl.col("a").reinterpret(dtype=pl.Int64).alias("reinterpreted"),
        ...         pl.col("a").alias("original"),
        ...     ]
        ... )
        shape: (3, 2)
        ┌───────────────┬──────────┐
        │ reinterpreted ┆ original │
        │ ---           ┆ ---      │
        │ i64           ┆ u64      │
        ╞═══════════════╪══════════╡
        │ 1             ┆ 1        │
        │ 1             ┆ 1        │
        │ 2             ┆ 2        │
        └───────────────┴──────────┘
        """
        if (signed is None) == (dtype is None):
            msg = "reinterpret requires exactly one of `signed` or `dtype` to be specified"
            raise ValueError(msg)

        return wrap_expr(self._pyexpr.reinterpret(signed, dtype))

    def inspect(self, fmt: str_ = "{}") -> Expr:
        """
        Print the value that this expression evaluates to and pass on the value.

        .. engine-support:: in-memory, streaming, distributed

        Examples
        --------
        >>> df = pl.DataFrame({"foo": [1, 1, 2]})
        >>> df.select(pl.col("foo").cum_sum().inspect("value is: {}").alias("bar"))
        value is: shape: (3,)
        Series: 'foo' [i64]
        [
            1
            2

View on GitHub (pinned to df599052da)

Solutions

  1. For a sign flip: pl.col('a').reinterpret(signed=True).
  2. For a target type: pl.col('a').reinterpret(dtype=pl.Int32).
  3. If you actually want value conversion (e.g. Int64 to Float64), use .cast() instead of reinterpret.

Example fix

# before
pl.col('a').reinterpret(signed=True, dtype=pl.Int32)

# after
pl.col('a').reinterpret(dtype=pl.Int32)
# or
pl.col('a').reinterpret(signed=True)
Defensive patterns

Strategy: validation

Validate before calling

assert (signed is None) != (dtype is None), 'reinterpret: pass exactly one of signed / dtype'

Prevention

When it happens

Trigger: pl.col('a').reinterpret() with no arguments, or reinterpret(signed=True, dtype=pl.Int32); also reinterpret(dtype=None) reached via an unset variable.

Common situations: Wrapping reinterpret behind a generic API where both parameters are optional; forgetting that dtype, not signed, is the way to target a specific type; copying examples that use only one form into code that passes both.

Related errors


AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16). Data as JSON: /api/errors/8ed398248a1f77cb. Report an issue: GitHub.