Fixed Error: local variable 'xdata' referenced before assignment" in legend_handler.py#8478
Conversation
lib/matplotlib/legend_handler.py
Outdated
| numpoints = self.get_numpoints(legend) | ||
|
|
||
| if numpoints > 1: | ||
| if ((numpoints < 1) or not (isinstance(numpoints, int) or numpoints.is_integer())): |
There was a problem hiding this comment.
What's the difference between these two?
isinstance(numpoints, int) or numpoints.is_integer()
There was a problem hiding this comment.
ahh they do the same thing. Which style do you prefer?
Edit: Decided to stick to numpoints.is_integer()
lib/matplotlib/legend_handler.py
Outdated
| numpoints = self.get_numpoints(legend) | ||
|
|
||
| if numpoints > 1: | ||
| if ((numpoints < 1) or not (numpoints.is_integer())): |
There was a problem hiding this comment.
You should check for integralness first, I think. Also, most of these parentheses are unnecessary.
lib/matplotlib/legend_handler.py
Outdated
| if ((numpoints < 1) or not (numpoints.is_integer())): | ||
| raise ValueError("numpoints must be a whole number and greater" + | ||
| " than or equal to 1; it was", numpoints) | ||
| elif (numpoints == 1): |
|
I would just have a check |
|
@anntzer I was just fixing it up. |
|
@kalagau This looks like you have mixed tabs and spaces! Can you replace them all with 4 spaces (most editors will have a tool for this (ex |
tacaswell
left a comment
There was a problem hiding this comment.
Adding a test
def test_silly_numpoints():
fig, ax = plt.subplots()
ax.plot(range(5), label='test')
ax.legend(numpoints=0.5)would not be bad, but I do not think is essential.
|
Ill add it in later today |
|
I think this should be good now! all tests are passing! |
|
@kalagau Are you comfortable squashing this down to 1 commit? |
Fix Error: local variable 'xdata' referenced before assignment" in legend_handler.py
477a129 to
f3b82c1
Compare
|
Sure @phobson, just did it. |
|
thanks @kalagau ! |
This is the PR for #6921