{{ message }}
BUG: Fix UnboundLocalError in contour labelling - #10710
Merged
Merged
Conversation
The code was trying to protect the access of xy1 and xy2 to valid cases, but unfortunately, for a list, l != -1 doesn't do element-by-element or return an error--it just always returns True. Therefore it wasn't actually guarding.
jklymak
approved these changes
Mar 7, 2018
Contributor
Author
jklymak
added a commit
that referenced
this pull request
Mar 8, 2018
Backport PR #10710 on branch v2.2.x
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.

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 caseIis a list, soI != -1doesn't do element-by-element orreturn an error--it just always returns
True. That caused the if to not actually guard anything. Replaced withalland 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.