{"record":{"id":"ce07129da93d5bfe","repo":"pola-rs/polars","slug":"number-of-rows-per-chunk-must-be-1","errorCode":null,"errorMessage":"number of rows per chunk must be >= 1","messagePattern":"number of rows per chunk must be >= 1","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/config.py","lineNumber":960,"sourceCode":"        Overwrite chunk size used in `streaming` engine.\n\n        By default, the chunk size is determined by the schema\n        and size of the thread pool. For some datasets (esp.\n        when you have large string elements) this can be too\n        optimistic and lead to Out of Memory errors.\n\n        Parameters\n        ----------\n        size\n            Number of rows per chunk. Every thread will process chunks\n            of this size.\n        \"\"\"\n        if size is None:\n            os.environ.pop(\"POLARS_IDEAL_MORSEL_SIZE\", None)\n        else:\n            if size < 1:\n                msg = \"number of rows per chunk must be >= 1\"\n                raise ValueError(msg)\n\n            os.environ[\"POLARS_IDEAL_MORSEL_SIZE\"] = str(size)\n        plr.config_reload_env_var(\"POLARS_IDEAL_MORSEL_SIZE\")\n        return cls\n\n    @classmethod\n    def set_tbl_cell_alignment(cls, format: Alignment | None) -> type[Config]:\n        \"\"\"\n        Set table cell alignment.\n\n        Parameters\n        ----------\n        format : str\n            * \"LEFT\": left aligned\n            * \"CENTER\": center aligned\n            * \"RIGHT\": right aligned\n\n        Examples","sourceCodeStart":942,"sourceCodeEnd":978,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/config.py#L942-L978","documentation":"Config.set_streaming_chunk_size validates the morsel size used by the streaming engine before writing the POLARS_IDEAL_MORSEL_SIZE environment variable. Passing a size smaller than 1 is meaningless (a chunk cannot hold zero or negative rows), so a ValueError is raised. Setting it to None removes the env var and is allowed.","triggerScenarios":"Calling pl.Config.set_streaming_chunk_size(0), a negative integer, or any value < 1.","commonSituations":"Computing the chunk size dynamically (e.g. rows // num_workers) where the divisor exceeds the row count, yielding 0; copy-pasting tuning snippets with a placeholder value.","solutions":["Pass an integer >= 1, e.g. pl.Config.set_streaming_chunk_size(100_000).","Pass None to reset to the default instead of 0.","Guard dynamic computations: max(1, total_rows // workers)."],"exampleFix":"// before\npl.Config.set_streaming_chunk_size(len(df) // 32)  # 0 when df is small\n// after\npl.Config.set_streaming_chunk_size(max(1, len(df) // 32))","handlingStrategy":"validation","validationCode":"if chunk_size is not None and chunk_size < 1:\n    raise ValueError(\"chunk_size must be >= 1\")\npl.Config.set_streaming_chunk_size(chunk_size)","typeGuard":"def is_valid_chunk_size(v) -> bool:\n    return v is None or (isinstance(v, int) and v >= 1)","tryCatchPattern":"try:\n    pl.Config.set_streaming_chunk_size(n)\nexcept ValueError:\n    pl.Config.set_streaming_chunk_size(None)  # fall back to default","preventionTips":["Clamp computed sizes with max(1, value).","Use None (not 0) to reset the setting.","Validate config values loaded from files before applying them."],"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"}