Skip to content

Name the data variable in apply_ufunc errors on Datasets - #11832

Merged
dcherian merged 2 commits into
pydata:mainfrom
A2ELAOUDI:apply-ufunc-variable-name-note
Oct 31, 2026
Merged

dcherian merged 2 commits into
pydata:mainfrom
A2ELAOUDI:apply-ufunc-variable-name-note

Conversation

@A2ELAOUDI

Copy link
Copy Markdown
Contributor

Description

When apply_ufunc fails on a Dataset, the error comes from code that only sees a Variable, so it can't say which data variable broke. As discussed in #2078, threading the name through broadcast_compat_data and apply_variable_ufunc would add a lot of plumbing for an error message. Instead, apply_dict_of_variables_vfunc adds a note to the exception, the same pattern already used in conventions.py and backends/common.py:

ValueError: operand to apply_ufunc encountered unexpected dimensions ['y'] on an input variable: these are core dimensions on other input or output variables
Raised while applying function to variable 'status'

The exception type and message are unchanged, so existing except/match= code keeps working. Errors raised by the user's function get the same note.

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 5.5)

[This is Claude Code on behalf of Abderrahmane El Aoudi]

Closes pydata#2078

Co-authored-by: Claude <noreply@anthropic.com>
…e-name-note

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@dcherian
dcherian enabled auto-merge (squash) October 31, 2026 19:00
@dcherian
dcherian merged commit 2846938 into pydata:main Oct 31, 2026
50 checks passed
@welcome

welcome Bot commented Oct 31, 2026

Copy link
Copy Markdown

Congratulations on completing your first pull request! Welcome to Xarray! We are proud of you, and hope to see you again! celebration gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apply_ufunc should include variable names in error messages

3 participants