-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Comments
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. |
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. |
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. |
* 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
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. |
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']
The text was updated successfully, but these errors were encountered: