{"record":{"id":"66c5f85b234a8f3f","repo":"pola-rs/polars","slug":"n-chunks-must-be-a-multiple-of-the-number-of-chu","errorCode":null,"errorMessage":"`n_chunks` must be a multiple of the number of chunks of this column ({total_n_chunks})","messagePattern":"`n_chunks` must be a multiple of the number of chunks of this column \\((.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/interchange/column.py","lineNumber":137,"sourceCode":"        -----\n        When `n_chunks` is higher than the number of chunks in the column, a slice\n        must be performed that is not on the chunk boundary. This will trigger some\n        compute if the column contains null values or if the column is of data type\n        boolean.\n        \"\"\"\n        total_n_chunks = self.num_chunks()\n        chunks = self._col.get_chunks()\n\n        if (n_chunks is None) or (n_chunks == total_n_chunks):\n            for chunk in chunks:\n                yield PolarsColumn(chunk, allow_copy=self._allow_copy)\n\n        elif (n_chunks <= 0) or (n_chunks % total_n_chunks != 0):\n            msg = (\n                \"`n_chunks` must be a multiple of the number of chunks of this column\"\n                f\" ({total_n_chunks})\"\n            )\n            raise ValueError(msg)\n\n        else:\n            subchunks_per_chunk = n_chunks // total_n_chunks\n            for chunk in chunks:\n                size = len(chunk)\n                step = size // subchunks_per_chunk\n                if size % subchunks_per_chunk != 0:\n                    step += 1\n                for start in range(0, step * subchunks_per_chunk, step):\n                    yield PolarsColumn(\n                        chunk[start : start + step], allow_copy=self._allow_copy\n                    )\n\n    def get_buffers(self) -> ColumnBuffers:\n        \"\"\"Return a dictionary containing the underlying buffers.\"\"\"\n        dtype = self._col.dtype\n\n        if dtype == String and not self._allow_copy:","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/py-polars/src/polars/interchange/column.py#L119-L155","documentation":"The requested `n_chunks` for iterating a column's chunks is not zero/negative-compatible or not a whole multiple of the column's actual chunk count, so chunks cannot be split evenly without an off-boundary slice.","triggerScenarios":"Thrown at py-polars/src/polars/interchange/column.py:137 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Choose n_chunks that evenly divides the column's number of chunks, or call .rechunk() first so the column has a single chunk."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}