{"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":"validation","errorClass":"ValueError","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/68506541d2de983056c9eb244e1ea05fab377dfc/py-polars/src/polars/config.py#L942-L978","documentation":"`pl.Config.set_streaming_chunk_size(size)` sets POLARS_STREAMING_CHUNK_SIZE, the number of rows each thread processes per chunk in the streaming engine. Values must be >= 1 (or None to let polars auto-tune); 0 and negatives raise ValueError.","triggerScenarios":"`pl.Config.set_streaming_chunk_size(0)`; passing a size computed from data, e.g. `len(df) // n_threads`, which evaluates to 0 for small inputs.","commonSituations":"Tuning streaming memory footprint in benchmarks/ETL; deriving chunk size from a row count that can legitimately be 0.","solutions":["Pass a positive integer such as 10_000, or None to use polars' automatic chunk size.","Guard computed sizes: `size = max(1, computed)`.","Prefer not setting it at all unless profiling showed a benefit."],"exampleFix":"# before\npl.Config.set_streaming_chunk_size(len(batch) // n_threads)  # 0 for small batches\n\n# after\npl.Config.set_streaming_chunk_size(max(1, len(batch) // n_threads))","handlingStrategy":"validation","validationCode":"def set_chunk_size(size: int | None) -> None:\n    if size is not None and size < 1:\n        raise ValueError(\"streaming chunk size must be >= 1 (or None for auto)\")\n    pl.Config.set_streaming_chunk_size(size)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp computed chunk sizes: max(1, computed).","Profile before tuning; None (auto) is usually the right choice."],"tags":["config","streaming","performance","validation","polars"],"backgroundTag":"invalid-argument-value","analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-09-10T10:08:55.499Z","contentChangedAt":"2026-09-10T10:08:55.499Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}