{"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":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/config.py","lineNumber":1537,"sourceCode":"        UnstableWarning: `qcut` 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/68506541d2de983056c9eb244e1ea05fab377dfc/py-polars/src/polars/config.py#L1519-L1555","documentation":"`pl.Config.set_expr_depth_warning(limit)` sets POLARS_MAX_EXPR_DEPTH, the expression-nesting depth allowed before polars warns about stack-overflow risk. Negative limits are rejected; note the message says 'positive' but the guard is `limit < 0`, so 0 is accepted. There is no negative value that disables the warning.","triggerScenarios":"`pl.Config.set_expr_depth_warning(-1)` hoping to silence the warning; passing a computed depth that went negative.","commonSituations":"Deeply chained expressions (long .with_columns / string op chains) triggering the warning; users trying to turn the warning off with a sentinel value.","solutions":["Pass 0 or a large positive value (e.g. 100_000) to effectively stop the warning.","Better long-term fix: refactor the deep expression into intermediate columns or several with_columns steps."],"exampleFix":"# before\npl.Config.set_expr_depth_warning(-1)  # ValueError: limit should be positive\n\n# after\npl.Config.set_expr_depth_warning(100_000)","handlingStrategy":"validation","validationCode":"def set_expr_depth(limit: int | None) -> None:\n    if limit is not None and limit < 0:\n        raise ValueError(\"expression depth limit must be >= 0\")\n    pl.Config.set_expr_depth_warning(limit if limit is not None else 100_000)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never use negative sentinels — 0 or a large positive value disables the warning in practice.","When the depth warning fires, prefer splitting the expression over raising the limit."],"tags":["config","expressions","validation","polars"],"backgroundTag":"invalid-argument-value","analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}