{"record":{"id":"c44598656f5be26c","repo":"pola-rs/polars","slug":"limit-should-be-positive","errorCode":null,"errorMessage":"limit should be positive","messagePattern":"limit should be positive","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/config.py","lineNumber":1537,"sourceCode":"        UnstableWarning: `bin_quantiles` is considered unstable. It may be changed at any point without it being considered a breaking change.\n        \"\"\"  # noqa: W505\n        if active is None:\n            os.environ.pop(\"POLARS_WARN_UNSTABLE\", None)\n        else:\n            os.environ[\"POLARS_WARN_UNSTABLE\"] = str(int(active))\n        plr.config_reload_env_var(\"POLARS_WARN_UNSTABLE\")\n        return cls\n\n    @classmethod\n    def set_expr_depth_warning(cls, limit: int) -> type[Config]:\n        \"\"\"\n        Set the expression depth that Polars will accept without triggering a warning.\n\n        Having too deep expressions (several 1000s) can lead to overflowing the stack and might be worth a refactor.\n        \"\"\"  # noqa: W505\n        if limit < 0:\n            msg = \"limit should be positive\"\n            raise ValueError(msg)\n\n        os.environ[\"POLARS_MAX_EXPR_DEPTH\"] = str(limit)\n        plr.config_reload_env_var(\"POLARS_MAX_EXPR_DEPTH\")\n        return cls\n\n    @classmethod\n    def set_engine_affinity(cls, engine: EngineType | None = None) -> type[Config]:\n        \"\"\"\n        Set which engine to use by default.\n\n        Parameters\n        ----------\n        engine : {None, 'auto', 'in-memory', 'streaming', 'gpu'}\n            The default execution engine Polars will attempt to use\n            when calling `.collect()`. However, the query is not\n            guaranteed to execute with the specified engine.\n\n            An :class:`Engine` object may also be used to configure the default. Engine","sourceCodeStart":1519,"sourceCodeEnd":1555,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/config.py#L1519-L1555","documentation":"Config.set_expr_depth_warning sets POLARS_MAX_EXPR_DEPTH, the expression nesting depth tolerated before Polars warns about potential stack overflow. A negative limit is invalid and raises ValueError. Note the check is `limit < 0`, so 0 is technically accepted.","triggerScenarios":"Calling pl.Config.set_expr_depth_warning(-1) or any negative integer.","commonSituations":"Sign errors when deriving the limit from a delta (e.g. current_depth - margin); intending to disable the warning by passing a negative number instead of a very large one.","solutions":["Pass a non-negative integer (typically a large value like 100_000 to silence the warning).","To effectively disable the warning, set a very high limit rather than a negative one.","Clamp computed values: max(0, computed_limit)."],"exampleFix":"// before\npl.Config.set_expr_depth_warning(-1)\n// after\npl.Config.set_expr_depth_warning(100_000)","handlingStrategy":"validation","validationCode":"if limit < 0:\n    raise ValueError(\"limit must be non-negative\")\npl.Config.set_expr_depth_warning(limit)","typeGuard":"def is_valid_limit(v) -> bool:\n    return isinstance(v, int) and v >= 0","tryCatchPattern":"try:\n    pl.Config.set_expr_depth_warning(limit)\nexcept ValueError:\n    pl.Config.set_expr_depth_warning(10_000)","preventionTips":["Disable the warning with a very large limit, never a negative one.","Abs() or clamp any derived margin values.","Keep the limit constant in a shared config module."],"tags":["python","polars","config","value-out-of-range"],"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"}