Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply_ufunc should include variable names in error messages #2078

Open
shoyer opened this issue Apr 24, 2018 · 4 comments
Open

apply_ufunc should include variable names in error messages #2078

shoyer opened this issue Apr 24, 2018 · 4 comments

Comments

@shoyer
Copy link
Member

shoyer commented Apr 24, 2018

This would make it easier to debug issues with dimensions.

For example, in this example from StackOverflow, the error message was ValueError: operand to apply_ufunc has required core dimensions ['time', 'lat', 'lon'], but some of these are missing on the input variable: ['lat', 'lon'].

A better error message would be: ValueError: operand to apply_ufunc has required core dimensions ['time', 'lat', 'lon'], but some of these are missing on input variable 'status': ['lat', 'lon']

@rdrussotto
Copy link
Contributor

I am working on this. The error listed here is thrown by the "broadcast_compat_data" function, which is called by "apply_variable_ufunc", which is in turn called by "apply_ufunc". There are other similar error messages that can happen where a variable name would also be helpful.

@rdrussotto
Copy link
Contributor

rdrussotto commented Jul 13, 2019

This is much harder than I thought. The function that throws this error doesn't have access to the variable name data, since it takes Variable objects as input which don't contain name information. apply_ufunc and its dependent functions are designed to take in a Dataset, DataArray, Variable, GroupBy or other object that might contain one or many variables, strip out the individual variable objects and run the computation on each of them. Including the variable name in the error message would require separately specifying the variable name as an input argument to "broadcast_compat_data" and "apply_variable_ufunc" and refactoring the code that calls these functions, which seems like adding too much complexity just for an error message. For now I think I'm going to change "the input variable" to "an input variable", which is at least a more accurate.

rdrussotto added a commit to rdrussotto/xarray that referenced this issue Jul 13, 2019
@shoyer
Copy link
Member Author

shoyer commented Jul 14, 2019

Including the variable name in the error message would require separately specifying the variable name as an input argument to "broadcast_compat_data" and "apply_variable_ufunc" and refactoring the code that calls these functions, which seems like adding too much complexity just for an error message.

I agree that this is more complex, but it still might be worth doing. Good error messages are important!

We do internally in a few other places already.

dcherian pushed a commit that referenced this issue Aug 23, 2019
* Clarify error message (#2078)

* Update whats-new

* Add issue number to whats-new

* Update xarray/core/computation.py

Co-Authored-By: Deepak Cherian <[email protected]>

* black computation.py for formatting conventions
@rdrussotto
Copy link
Contributor

The clarification I mentioned has now been committed, with other edits to the error message suggested by @dcherian. Obviously it doesn't make sense to close the issue yet, in case someone wants to take on the tougher task of adding the variable name to the message.

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

No branches or pull requests

3 participants