Name the calling function in the unit-mismatch warning (#2782)#3036
Merged
Conversation
aspect() already calls warn_if_unit_mismatch on its planar branch (added in #2839), but the shared warning text was hard-coded to say "before calling `slope`". An aspect() caller was told to fix a slope call they never made. Add an optional func_name argument to warn_if_unit_mismatch so the message names the operation the user actually invoked, and have aspect pass func_name='aspect'. The default stays 'slope', so slope's message is unchanged. The text now also notes the anisotropy effect from the issue: away from the equator the degree-to-meter ratio differs between the x and y axes, which skews aspect. Tests check the message names slope by default and aspect when called from aspect, at both the helper level and through aspect().
brendancol
commented
Jun 8, 2026
brendancol
left a comment
Contributor
Author
There was a problem hiding this comment.
PR Review: Name the calling function in the unit-mismatch warning (#2782)
Blockers (must fix before merge)
None.
Suggestions (should fix, not blocking)
None.
Nits (optional improvements)
- utils.py:1005-1006: the message still opens with "Slope/aspect operations expect...", and with
func_name='aspect'it then closes with "before callingaspect", so the reader sees both "Slope/aspect" and "aspect" in one warning. It reads fine and is arguably more informative, so leaving it is reasonable. Dropping the "/aspect" and leaning onfunc_namewould tighten it, but that is cosmetic.
What looks good
- Default
func_name='slope'keeps slope's existing message byte-for-byte, so no current behavior changes. - The added anisotropy sentence matches the issue rationale: the x/y degree-to-meter ratio diverges away from the equator.
- Tests cover the helper default, the helper override, and the aspect() integration path. The "appears to have coordinates in degrees" stem is unchanged, so pre-existing match-based tests keep passing.
- The warning fires in the shared planar dispatch before backend selection, so all four backends behave identically. No dispatch change needed.
Checklist
- Algorithm matches reference: n/a (warning-text change)
- Backends consistent: yes, warning is pre-dispatch
- NaN handling: unchanged
- Edge cases covered by tests: yes for the warning path
- Dask chunk boundaries: unchanged
- No premature materialization: n/a
- Benchmark: not needed
- README feature matrix: not needed (private helper, no API change)
- Docstrings present and accurate: yes, Parameters added for func_name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2782.
The decision the issue asked for (whether
aspect()should callwarn_if_unit_mismatchon its planar branch) was already made in #2839: aspect's planar path calls the helper. The leftover footgun is that the shared warning text was hard-coded to say "before callingslope", so anaspect()caller was told to fix a slope call they never made.func_nameargument towarn_if_unit_mismatchso the message names the operation the user actually called. Default staysslope, so slope's wording is unchanged.aspect()passfunc_name='aspect'.This is a warning-message change in a private helper. No public API, no new function, and no backend support change, so it applies to all backends equally (the warning fires in the shared planar dispatch before backend selection).
Test plan:
warn_if_unit_mismatchnamesslopeby default andaspectwhen passedfunc_name='aspect'(test_utils.py)aspect()planar path emits a warning that namesaspect(test_aspect.py)