iris.save(..., compute=False) returns a tuple, not the documented Delayed

Aperta
#7,291 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
api, documentation

Direzione di ricerca

Start with lib/iris/fileformats/netcdf/saver.py, lib/iris/AGENTS.md, and the existing integration test in lib/iris/tests/integration/netcdf/test_delayed_save.py. Compare delayed_completion and save() with the user-manual example in docs/src/user_manual/explanation/real_and_lazy_data.rst. Done means the chosen return-value contract is covered by a test and the affected annotations, docstrings, and manual instructions agree with it.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Agentic Type: Documentation

Summary

iris.save(..., compute=False) no longer returns a dask.delayed.Delayed. It
returns a tuple of dask.array.Array, so the documented
result.compute() idiom raises AttributeError.

The code change was deliberate and correct — #6451 adapted Iris to
dask/dask#11844 for Dask 2025.4
compatibility. What was missed is that the return value of a public API
changed shape at the same time, and several docstrings plus a user manual page
still describe the old contract.

Reproducer

import dask.array as da, iris
from iris.cube import Cube

cube = Cube(da.ones((4, 4), chunks=(2, 2), dtype="f4"), var_name="x")
result = iris.save([cube], "out.nc", compute=False)

type(result)        # <class 'tuple'>  -- documented as dask.delayed.Delayed
result.compute()    # AttributeError: 'tuple' object has no attribute 'compute'

import dask
dask.compute(result)   # works

Verified against dask 2026.7.1. da.store(sources, targets, compute=False)
returns a Delayed only when sources is a single array; for a sequence — which
is what Saver.delayed_completion always passes — it returns a tuple.

What is stale

Location Says
lib/iris/fileformats/netcdf/saver.py:2658 def delayed_completion(self) -> Delayed: — the annotation is now wrong
lib/iris/fileformats/netcdf/saver.py:2661,2666 docstring and Returns promise a Delayed
lib/iris/fileformats/netcdf/saver.py:2855,2870-2872 save() docstring and Returns promise a Delayed
docs/src/user_manual/explanation/real_and_lazy_data.rst:270 "the :meth:~iris.save call returns a result which is a :class:~dask.delayed.Delayed object"
docs/src/user_manual/explanation/real_and_lazy_data.rst:272 "the save can be completed later by calling result.compute()" — this instruction is the one that actually fails

The What's New example in docs/src/whatsnew/3.6.rst is fine: it uses
dask.compute(*delayeds), which works with either shape.

Why it was not caught

#6451 also relaxed the assertion in
lib/iris/tests/integration/netcdf/test_delayed_save.py, replacing
assert isinstance(result, Delayed) with a helper that accepts either a dask
collection or a sequence of them:

def are_dask_collections(obj):
    result = dask.is_dask_collection(obj)
    if not result and hasattr(obj, "__len__"):
        result = all([dask.is_dask_collection(item) for item in obj])
    return result

That was a reasonable way to unblock the Dask upgrade, but it means no test
pins the return type, and no test exercises result.compute() — every internal
caller, including Saver.complete, uses dask.compute().

Suggested resolution

Two options, and I'd suggest the first:

  1. Restore the documented contract. Wrap the da.store result so
    delayed_completion returns a real Delayed again. Both result.compute()
    and dask.compute(result) then work, the annotation becomes true, no
    documentation changes, and iris.save keeps returning one documented type
    (per lib/iris/AGENTS.md, "Return one documented type"). A tuple of
    dask.array.Array is also a leaked implementation detail of da.store
    rather than an intended public return value.

  2. Accept the new shape and fix the docs, describing the result as a dask
    collection or sequence of them, completed with dask.compute(result). This
    is less work but leaves a silently-changed public return type, and the
    user manual's result.compute() step has to go.

Either way the test should pin the choice, and real_and_lazy_data.rst needs
updating.

Context

Found while specifying native Zarr I/O (#6961), where the saver's deferred-write
machinery is being generalised and would otherwise inherit the same shape. That
work does not fix this — the relocation is deliberately behaviour-preserving —
so it is raised separately here.


Investigated and written by Claude (Anthropic), working with @bjlittle.

Lingua principale
Python
Stelle
730
Fork
323
Merge medio
3g 21h
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di SciTools/iris

Tutte le issue di SciTools/iris

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.