BUG: Fix UnboundLocalError in contour labelling #10710
Merged
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.
This fixes hitting the following traceback with 2.2.0 (problem also exists on master):
That traces back to this block:
matplotlib/lib/matplotlib/contour.py
Lines 433 to 444 in d2f7bb1
The code was trying to protect the access of xy1 and xy2 to valid cases, using
np.all()
. Unfortunately, in this caseI
is a list, soI != -1
doesn't do element-by-element orreturn an error--it just always returns
True
. That caused the if to not actually guard anything. Replaced withall
and a generator expression.I tried making a test, but I couldn't find any sensible set of data to reproduce. We hit this in an example of ours that was using cartopy incorrectly (fixing that problem makes the error disappear). It appears to only trigger when you have a really tiny contour (in display coords) that can't be properly interpolated to create a spot for the contour label.
cc @anntzer since you introduced this code according to git.