Autochunking fails with zero length dimensions
Author: charles-turner-1Created Aug 1, 2026Updated Sep 7, 2026
Labelsneeds attentionneeds triage
Describe the issue:
Auto chunking fails if we have zero length dimensions, and don't specify a completely generic auto chunk, see example below. It seems totally safe to me to add a fallback or 1 to the largest_block definition, since there's only one meaningful way to chunk a zero length dimension anyway.
Minimal Complete Verifiable Example:
(I got Claude to generate this for me from https://github.com/pydata/xarray/pull/11486 by ripping off the xarray layer. I've verified it's work.)
"""MRE for ZeroDivisionError in ``auto_chunks`` when a non-auto dim has length 0.
Mirrors /Users/ct/xarray/bug_repro/bug_da.py, which does::
da = xr.DataArray(np.zeros((5, 1)), dims=("lat", "lon")).isel(lat=[])
da.chunk("auto") # fine
da.chunk({"lon": "auto"}) # raises
``da.chunk({"lon": "auto"})`` bottoms out in ``normalize_chunks((0, "auto"), ...)``:
``lat`` is pinned to its (zero) length, ``lon`` is "auto". ``auto_chunks`` then
computes ``largest_block = prod(non-auto chunks) == 0`` and divides by it.
"""
import numpy as np
import dask.array as da
from dask.array.core import normalize_chunks
# This is fine: every dim is "auto", so largest_block is the empty product, 1.
print(normalize_chunks("auto", shape=(0, 1), dtype=float))
# Case A -- no previous_chunks (what xarray's `.chunk()` on a numpy-backed
# DataArray hits, via da.from_array). Raises at core.py:3414 on main:
# size = (limit / dtype.itemsize / largest_block) ** (1 / len(autos))
print(normalize_chunks((0, "auto"), shape=(0, 1), dtype=float))
print(da.from_array(np.zeros((0, 1)), chunks=(0, "auto")).chunks)
# Case B -- with previous_chunks (rechunking an array that is already dask).
# Raises at core.py:3250, in _compute_multiplier -- same root cause
# (largest_block == 0), different division.
print(da.zeros((0, 1)).rechunk({0: -1, 1: "auto"}).chunks)Anything else we need to know?:
See https://github.com/dask/dask/pull/12536 and https://github.com/pydata/xarray/pull/11486
Environment:
- Dask version: Latest main (
git clone https://github.com/dask/dask; pixi shell) - Python version: 3.14.6
- Operating System: MacOS
- Install method (conda, pip, source):
git clone dask; pixi shell
Source: dask/dask