{"record":{"id":"8ed398248a1f77cb","repo":"pola-rs/polars","slug":"reinterpret-requires-exactly-one-of-signed-or-d","errorCode":null,"errorMessage":"reinterpret requires exactly one of `signed` or `dtype` to be specified","messagePattern":"reinterpret requires exactly one of `signed` or `dtype` to be specified","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/expr/expr.py","lineNumber":7115,"sourceCode":"        ...     [\n        ...         pl.col(\"a\").reinterpret(dtype=pl.Int64).alias(\"reinterpreted\"),\n        ...         pl.col(\"a\").alias(\"original\"),\n        ...     ]\n        ... )\n        shape: (3, 2)\n        ┌───────────────┬──────────┐\n        │ reinterpreted ┆ original │\n        │ ---           ┆ ---      │\n        │ i64           ┆ u64      │\n        ╞═══════════════╪══════════╡\n        │ 1             ┆ 1        │\n        │ 1             ┆ 1        │\n        │ 2             ┆ 2        │\n        └───────────────┴──────────┘\n        \"\"\"\n        if (signed is None) == (dtype is None):\n            msg = \"reinterpret requires exactly one of `signed` or `dtype` to be specified\"\n            raise ValueError(msg)\n\n        return wrap_expr(self._pyexpr.reinterpret(signed, dtype))\n\n    def inspect(self, fmt: str_ = \"{}\") -> Expr:\n        \"\"\"\n        Print the value that this expression evaluates to and pass on the value.\n\n        .. engine-support:: in-memory, streaming, distributed\n\n        Examples\n        --------\n        >>> df = pl.DataFrame({\"foo\": [1, 1, 2]})\n        >>> df.select(pl.col(\"foo\").cum_sum().inspect(\"value is: {}\").alias(\"bar\"))\n        value is: shape: (3,)\n        Series: 'foo' [i64]\n        [\n            1\n            2","sourceCodeStart":7097,"sourceCodeEnd":7133,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/expr/expr.py#L7097-L7133","documentation":"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.","triggerScenarios":"pl.col('a').reinterpret() with no arguments, or reinterpret(signed=True, dtype=pl.Int32); also reinterpret(dtype=None) reached via an unset variable.","commonSituations":"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.","solutions":["For a sign flip: pl.col('a').reinterpret(signed=True).","For a target type: pl.col('a').reinterpret(dtype=pl.Int32).","If you actually want value conversion (e.g. Int64 to Float64), use .cast() instead of reinterpret."],"exampleFix":"# before\npl.col('a').reinterpret(signed=True, dtype=pl.Int32)\n\n# after\npl.col('a').reinterpret(dtype=pl.Int32)\n# or\npl.col('a').reinterpret(signed=True)","handlingStrategy":"validation","validationCode":"assert (signed is None) != (dtype is None), 'reinterpret: pass exactly one of signed / dtype'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the XOR rule in mind: exactly one argument, never both, never neither.","Use .cast() for conversions; reserve reinterpret for raw bit reinterpretation."],"tags":["validation","polars","expression","dtype","bit-manipulation"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}