pola-rs/polars · error · ValueError
`n_chunks` must be a multiple of the number of chunks of…
Error message
`n_chunks` must be a multiple of the number of chunks of this column ({total_n_chunks}) What it means
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.
Solutions
- Choose n_chunks that evenly divides the column's number of chunks, or call .rechunk() first so the column has a single chunk.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at py-polars/src/polars/interchange/column.py:137 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of pola-rs/polars@9b5d73fd00 (2026-08-19).
Data as JSON: /api/errors/66c5f85b234a8f3f.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/interchange/column.py:137
-----
When `n_chunks` is higher than the number of chunks in the column, a slice
must be performed that is not on the chunk boundary. This will trigger some
compute if the column contains null values or if the column is of data type
boolean.
"""
total_n_chunks = self.num_chunks()
chunks = self._col.get_chunks()
if (n_chunks is None) or (n_chunks == total_n_chunks):
for chunk in chunks:
yield PolarsColumn(chunk, allow_copy=self._allow_copy)
elif (n_chunks <= 0) or (n_chunks % total_n_chunks != 0):
msg = (
"`n_chunks` must be a multiple of the number of chunks of this column"
f" ({total_n_chunks})"
)
raise ValueError(msg)
else:
subchunks_per_chunk = n_chunks // total_n_chunks
for chunk in chunks:
size = len(chunk)
step = size // subchunks_per_chunk
if size % subchunks_per_chunk != 0:
step += 1
for start in range(0, step * subchunks_per_chunk, step):
yield PolarsColumn(
chunk[start : start + step], allow_copy=self._allow_copy
)
def get_buffers(self) -> ColumnBuffers:
"""Return a dictionary containing the underlying buffers."""
dtype = self._col.dtype
if dtype == String and not self._allow_copy:View on GitHub (pinned to 9b5d73fd00)