Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Add short-circuit return to matplotlib.artist.setp if input is length 0 #7801
Conversation
samsontmr
changed the title from
Add short-circuit return if input is length 0 to Add short-circuit return to `matplotlib.artist.setp` if input is length 0
Jan 11, 2017
samsontmr
changed the title from
Add short-circuit return to `matplotlib.artist.setp` if input is length 0 to Add short-circuit return to matplotlib.artist.setp if input is length 0
Jan 11, 2017
| @@ -1421,6 +1421,10 @@ def setp(obj, *args, **kwargs): | ||
| >>> setp(lines, 'linewidth', 2, 'color', 'r') # MATLAB style | ||
| >>> setp(lines, linewidth=2, color='r') # python style | ||
| """ | ||
| + | ||
| + if ((isinstance(obj, np.ndarray) and not obj.size) or |
anntzer
Jan 11, 2017
Contributor
Just check if not objs: instead (objs is a list defined immediately below).
samsontmr
Jan 11, 2017
Contributor
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?
tacaswell
Jan 11, 2017
Owner
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.
tacaswell
added this to the
2.0.1 (next bug fix release)
milestone
Jan 11, 2017
|
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 |
codecov-io
commented
Jan 12, 2017
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 |
NelleV
changed the title from
Add short-circuit return to matplotlib.artist.setp if input is length 0 to [MRG+1] Add short-circuit return to matplotlib.artist.setp if input is length 0
Jan 13, 2017
|
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. |
tacaswell
merged commit 9edcb03
into matplotlib:master
Jan 13, 2017
5 checks passed
|
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. |
QuLogic
added the
Needs backport
label
Feb 26, 2017
dstansby
added a commit
to dstansby/matplotlib
that referenced
this pull request
Mar 26, 2017
|
|
tacaswell + dstansby |
ce89a36
|
|
@QuLogic Lets drop the backport on this. |
|
Works for me. |
samsontmr commentedJan 11, 2017
•
edited by NelleV
Fixes #7784
Before this patch, an IndexError is raised in matplotlib.artist.setp if argument is an empty list,