{"record":{"id":"e199d1ab7e2924f1","repo":"pola-rs/polars","slug":"activate-dtype-i128-feature","errorCode":null,"errorMessage":"activate dtype-i128 feature","messagePattern":"activate dtype-i128 feature","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-plan/src/plans/lit.rs","lineNumber":173,"sourceCode":"            DataType::Array(_, size) => AnyValue::Array(s, *size),\n            _ => unreachable!(),\n        };\n\n        Ok(Scalar::new(dtype.clone(), value))\n    }\n}\n\nimpl DynLiteralValue {\n    pub fn try_materialize_to_dtype(\n        self,\n        dtype: &DataType,\n        options: CastOptions,\n    ) -> PolarsResult<Scalar> {\n        match self {\n            DynLiteralValue::Str(s) => Ok(Scalar::from(s).cast_with_options(dtype, options)?),\n            DynLiteralValue::Int(i) => {\n                #[cfg(not(feature = \"dtype-i128\"))]\n                let i: i64 = i.try_into().expect(\"activate dtype-i128 feature\");\n\n                Ok(Scalar::from(i).cast_with_options(dtype, options)?)\n            },\n            DynLiteralValue::Float(f) => Ok(Scalar::from(f).cast_with_options(dtype, options)?),\n            DynLiteralValue::List(dyn_list_value) => {\n                dyn_list_value.try_materialize_to_dtype(dtype, options)\n            },\n        }\n    }\n}\n\nimpl RangeLiteralValue {\n    pub fn try_materialize_to_series(self, dtype: &DataType) -> PolarsResult<Series> {\n        fn handle_range_oob(range: &RangeLiteralValue, to_dtype: &DataType) -> PolarsResult<()> {\n            polars_bail!(\n                InvalidOperation:\n                \"conversion from `{}` to `{to_dtype}` failed for range({}, {})\",\n                range.dtype, range.low, range.high,","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/crates/polars-plan/src/plans/lit.rs#L155-L191","documentation":"DynLiteralValue::Int stores the integer literal as i128. In builds without the dtype-i128 feature, try_materialize_to_dtype narrows it to i64 via try_into(); when the literal falls outside i64 range the conversion fails and this expect panics, telling you to build with dtype-i128 enabled.","triggerScenarios":"Passing a Python int literal beyond ±2^63 (e.g. pl.lit(2**70), or a huge constant in a lazy expression) in a polars build compiled without the dtype-i128 feature; triggers when the literal is materialized to a dtype during plan conversion/execution.","commonSituations":"Default pip wheels that do not enable dtype-i128; code ported from Python's arbitrary-precision ints (UUIDs as ints, snowflake IDs beyond 63 bits, cryptographic values); upgrading polars where large ints previously errored differently.","solutions":["Keep integer literals within i64 range (−9223372036854775808..=9223372036854775807)","Pass the value as a float or a string plus an explicit cast if precision permits","Use a polars build with the dtype-i128 feature enabled (custom Rust build with features = [\"dtype-i128\"])","Materialize large values into a Series of a wide dtype instead of a literal expression"],"exampleFix":"# before\nlf.filter(pl.col(\"id\") == pl.lit(2**70))  # panic: activate dtype-i128 feature\n\n# after (no i128 build): compare as float or string-cast\nlf.filter(pl.col(\"id\").cast(pl.Float64) == float(2**70))\n# or build polars with features = [\"dtype-i128\"] and keep pl.lit(2**70)","handlingStrategy":"validation","validationCode":"# Python: guard literal range before building expressions\nI64_MIN, I64_MAX = -(2**63), 2**63 - 1\ndef safe_lit(v: int):\n    assert I64_MIN <= v <= I64_MAX or float(v) == v, f\"literal {v} exceeds i64; enable dtype-i128 or cast\"\n    return pl.lit(v)","typeGuard":"def fits_i64(v: int) -> bool:\n    return -(2**63) <= v <= 2**63 - 1","tryCatchPattern":null,"preventionTips":["Bound user-supplied ints before pl.lit","Build with features=[\"dtype-i128\"] if >63-bit ints are required","Store oversized ids as strings or UInt128/Decimal columns, not literals"],"tags":["literals","feature-flag","i128","integer-overflow","panic","python"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}