Fix #5572: Allow passing empty range to broken_barh #5600

Merged
merged 3 commits into from Dec 28, 2015

Conversation

Projects
None yet
3 participants
Owner

mdboom commented Dec 1, 2015

No description provided.

mdboom added this to the Critical bugfix release (1.5.1) milestone Dec 1, 2015

mdboom added the needs_review label Dec 1, 2015

@tacaswell tacaswell commented on an outdated diff Dec 1, 2015

lib/matplotlib/axes/_axes.py
@@ -2333,8 +2333,16 @@ def broken_barh(self, xranges, yrange, **kwargs):
.. plot:: mpl_examples/pylab_examples/broken_barh.py
"""
# process the unit information
- self._process_unit_info(xdata=xranges[0],
- ydata=yrange[0],
+ if len(xranges):
+ xdata = xranges[0]
@tacaswell

tacaswell Dec 1, 2015

Owner

Probably safer to do xdata = next(iter(xrange)) in a try...except block. pandas Series slice on index rather than position

try:
    xdata = next(iter(xranges))
except (StopIteration, TypeError):
    xdata = None

@tacaswell tacaswell commented on an outdated diff Dec 3, 2015

lib/matplotlib/axes/_axes.py
@@ -2333,8 +2333,16 @@ def broken_barh(self, xranges, yrange, **kwargs):
.. plot:: mpl_examples/pylab_examples/broken_barh.py
"""
# process the unit information
- self._process_unit_info(xdata=xranges[0],
- ydata=yrange[0],
+ if len(xranges):
+ xdata = six.next(iter(xranges))
+ else:
+ xdata = None
+ if len(yrange):
+ ydata = six.next(iter(yranges))
@tacaswell

tacaswell Dec 3, 2015

Owner

plural typo, should be yrange

Owner

efiring commented Dec 3, 2015

I dimly recall seeing this sort of pre-processing prior to _process_unit_info elsewhere; does it need to be factored out? E.g., could it be added to _process_unit_info itself, perhaps activated with a kwarg? Is there also a Pandas conversion stage that we are stuck having to use now, so that we don't end up sprinkling things like six.next(iter(xxx)) all over the place?

mdboom added some commits Dec 1, 2015

@mdboom mdboom Fix #5572: Allow passing empty range to broken_barh f255c33
@mdboom mdboom Use iterator rather than index
76d681b
@mdboom mdboom Fix typo
115fca7
Owner

mdboom commented Dec 22, 2015

This is now ready to merge.

@tacaswell tacaswell commented on the diff Dec 22, 2015

lib/matplotlib/axes/_axes.py
@@ -2339,8 +2339,16 @@ def broken_barh(self, xranges, yrange, **kwargs):
.. plot:: mpl_examples/pylab_examples/broken_barh.py
"""
# process the unit information
- self._process_unit_info(xdata=xranges[0],
- ydata=yrange[0],
+ if len(xranges):
+ xdata = six.next(iter(xranges))
@tacaswell

tacaswell Dec 22, 2015

Owner

I think we can just use next here https://docs.python.org/2/library/functions.html#next I think six provides it to support back to 2.4 or something like that.

@efiring efiring added a commit that referenced this pull request Dec 28, 2015

@efiring efiring Merge pull request #5600 from mdboom/empty-ranges
Fix #5572: Allow passing empty range to broken_barh
e7c51dc

@efiring efiring merged commit e7c51dc into matplotlib:master Dec 28, 2015

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.03%) to 68.344%
Details

efiring removed the needs_review label Dec 28, 2015

@efiring efiring added a commit that referenced this pull request Dec 28, 2015

@efiring @tacaswell efiring + tacaswell Merge pull request #5600 from mdboom/empty-ranges
Fix #5572: Allow passing empty range to broken_barh
8228dbd
Owner

tacaswell commented Dec 28, 2015

backported as 8228dbd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment