{"record":{"id":"dc5ab597bf25fba8","repo":"pola-rs/polars","slug":"index-positions-should-be-greater-than-or-equal-to","errorCode":null,"errorMessage":"index positions should be greater than or equal to -2^32","messagePattern":"index positions should be greater than or equal to -2\\^32","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/getitem.py","lineNumber":374,"sourceCode":"        return s\n\n    if not s.dtype.is_integer():\n        if s.dtype == Boolean:\n            _raise_on_boolean_mask()\n        else:\n            msg = f\"cannot treat Series of type {s.dtype} as indices\"\n            raise TypeError(msg)\n\n    if s.len() == 0:\n        return pl.Series(s.name, [], dtype=idx_type)\n\n    if idx_type == UInt32:\n        if s.dtype in {Int64, UInt64} and s.max() >= U32_MAX:  # type: ignore[operator]\n            msg = \"index positions should be smaller than 2^32\"\n            raise ValueError(msg)\n        if s.dtype == Int64 and s.min() < -U32_MAX:  # type: ignore[operator]\n            msg = \"index positions should be greater than or equal to -2^32\"\n            raise ValueError(msg)\n\n    if s.dtype.is_signed_integer():\n        if s.min() < 0:  # type: ignore[operator]\n            if idx_type == UInt32:\n                idxs = s.cast(Int32) if s.dtype in {Int8, Int16} else s\n            else:\n                idxs = s.cast(Int64) if s.dtype in {Int8, Int16, Int32} else s\n\n            # Update negative indexes to absolute indexes.\n            return (\n                idxs.to_frame()\n                .select(\n                    F.when(F.col(idxs.name) < 0)\n                    .then(size + F.col(idxs.name))\n                    .otherwise(F.col(idxs.name))\n                    .cast(idx_type)\n                )\n                .to_series(0)","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_utils/getitem.py#L356-L392","documentation":"Symmetric to the upper-bound check: with UInt32 indices, an Int64 index Series whose minimum is below -2^32 cannot be safely converted to the unsigned absolute-position representation, so `_convert_series_to_indices` raises ValueError.","triggerScenarios":"Indexing with a pl.Series of Int64 containing very negative values (< -4294967295), e.g. `s[pl.Series([-2**32])]`. Small negatives (-1, -2) are fine because they are treated as from-the-end positions.","commonSituations":"Computing positions with signed arithmetic that can underflow, or offsetting valid positions by large negative deltas before indexing.","solutions":["Clamp or rebase positions so they stay >= -2^32 (and ideally >= -len(s)).","Compute absolute positions yourself and clip: `idx = (idx % s.len())`.","Use `.gather()` after sanitizing the index Series."],"exampleFix":"// before\nidx = positions - 2**33\nsub = s[idx]  # ValueError\n// after\nidx = (positions - 2**33) % s.len()\nsub = s[idx]","handlingStrategy":"validation","validationCode":"if idx.dtype == pl.Int64 and idx.len() and idx.min() < -(2**32 - 1):\n    idx = idx % s.len()","typeGuard":"def negatives_in_range(idx: pl.Series, length: int) -> bool:\n    return idx.min() >= -length if idx.len() else True","tryCatchPattern":"try:\n    sub = s[idx]\nexcept ValueError as e:\n    if \"greater than or equal to -2^32\" in str(e):\n        sub = s[idx % s.len()]\n    else:\n        raise","preventionTips":["Normalize negative positions with modulo before indexing.","Avoid large negative offsets in signed position arithmetic.","Clip indices to [-len, len-1]."],"tags":["polars","indexing","valueerror","negative-index"],"backgroundTag":"value-out-of-range","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}