Add short-circuit return to matplotlib.artist.setp if input is length 0#7801
Add short-circuit return to matplotlib.artist.setp if input is length 0#7801tacaswell merged 2 commits intomatplotlib:masterfrom
Conversation
matplotlib.artist.setp if input is length 0
matplotlib.artist.setp if input is length 0
lib/matplotlib/artist.py
Outdated
| >>> setp(lines, linewidth=2, color='r') # python style | ||
| """ | ||
|
|
||
| if ((isinstance(obj, np.ndarray) and not obj.size) or |
There was a problem hiding this comment.
Just check if not objs: instead (objs is a list defined immediately below).
There was a problem hiding this comment.
Wouldn't if not objs return false if objs is a list of empty lists? Or do you mean to check for if not obj?
There was a problem hiding this comment.
Agree using if not objs: would be better. I would also move this down to L1453 (right above the line with objs[0]) after we have normalized the input to a list.
There was a problem hiding this comment.
Oh I see! The if else statements guarantee a list, right?
|
Commits squashed |
|
Looks good! Could you also add a test to |
|
Apologies if I'm missing something obvious here, but couldn't this be at the very top of the function? e.g., if not objs:
return
elif not cbook.iterable(obj):
objs = [obj]
else:
objs = list(cbook.flatten(obj)) |
|
@phobson users will find pathological cases 😉 In [62]: bool([[]])
Out[62]:
True |
|
@tacaswell wow. great catch with that. |
|
@phobson |
Current coverage is 62.10% (diff: 100%)@@ master #7801 diff @@
==========================================
Files 174 174
Lines 56028 56052 +24
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 34803 34809 +6
- Misses 21225 21243 +18
Partials 0 0
|
|
@tacaswell Tests added |
|
I've edited your comment to explain what it fixes. It saves us reviewers a lot of time not to have to identify what the original problem was. |
|
This should be backported after 2.0 @samsontmr Thank! |
|
This doesn't backport that easily, or at least, I'm not familiar enough with that section of the code to do it. |
FIX: Add short-circuit return to matplotlib.artist.setp if input is length 0
|
@QuLogic Lets drop the backport on this. |
|
Works for me. |
Fixes #7784
Before this patch, an IndexError is raised in matplotlib.artist.setp if argument is an empty list,