Skip to content

Document that .item() is not implemented for lazy arrays (#7916) - #11659

Merged
dcherian merged 3 commits into
pydata:mainfrom
Emam2006:item-dask-docs-gh7916
Oct 24, 2026
Merged

dcherian merged 3 commits into
pydata:mainfrom
Emam2006:item-dask-docs-gh7916

Conversation

@Emam2006

@Emam2006 Emam2006 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

.item() on a lazy (dask-backed) DataArray/Variable currently raises a
generic NotImplementedError with no hint about how to proceed (#7916).

Per the discussion in #7916, the agreed resolution is not to implicitly
compute, but to document the limitation and make the error actionable. This PR:

  • improves the NotImplementedError raised for methods that don't work on dask
    arrays (fail_on_dask_array_input) to suggest loading the data into memory
    first, e.g. with .compute() or .load();
  • adds a note to the DataArray.item / Variable.item docstring pointing to
    .compute().item() / .as_numpy().item() (as suggested by @dcherian and
    @slevang in the thread);
  • adds a whats-new.rst entry.

No behaviour change — eager .item() works exactly as before; only the error
message text and docstring change.

Checklist

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
      Tools: Claude Code (Claude Opus 4.8). Prompt: implement the maintainer-agreed
      resolution of .item() breaks on dataarray if dask arrays are (implicitely) used #7916 — document that .item() is not implemented for lazy
      (dask) arrays and make the raised error message suggest loading into memory
      first; keep it docs/message-only with no behaviour change.

Improve the NotImplementedError raised for methods that do not work on
dask arrays (e.g. .item()) to suggest loading the data into memory
first, and add a note to the DataArray.item / Variable.item docstring
pointing to .compute().item() / .as_numpy().item().

Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the topic-arrays related to flexible array support label Oct 2, 2026

@headtr1ck headtr1ck left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://xray--11659.org.readthedocs.build/en/11659/generated/xarray.DataArray.item.html#xarray.DataArray.item

There is already a "Notes" section. I guess we should move the extra note into there?

@dcherian
dcherian enabled auto-merge (squash) October 24, 2026 15:10
@dcherian
dcherian merged commit b2acc77 into pydata:main Oct 24, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic-arrays related to flexible array support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.item() breaks on dataarray if dask arrays are (implicitely) used

3 participants