You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
00:06 $ ipython
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:53:06)
Type "copyright", "credits" or "license" for more information.
IPython 5.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import matplotlib.pyplot as plt
In [2]: plt.ion()
In [3]: plt.contour( [[1]], [[1]], [[1]])
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-3-b799b0b3bd2d> in <module>()
----> 1 plt.contour( [[1]], [[1]], [[1]])
/home/tcaswell/src/p/matplotlib/lib/matplotlib/pyplot.py in contour(*args, **kwargs)
2777 ax.hold(hold)
2778 try:
-> 2779 ret = ax.contour(*args, **kwargs)
2780 finally:
2781 ax.hold(washold)
/home/tcaswell/src/p/matplotlib/lib/matplotlib/__init__.py in inner(ax, *args, **kwargs)
1878 warnings.warn(msg % (label_namer, func.__name__),
1879 RuntimeWarning, stacklevel=2)
-> 1880 return func(ax, *args, **kwargs)
1881 pre_doc = inner.__doc__
1882 if pre_doc is None:
/home/tcaswell/src/p/matplotlib/lib/matplotlib/axes/_axes.py in contour(self, *args, **kwargs)
5810 self.cla()
5811 kwargs['filled'] = False
-> 5812 contours = mcontour.QuadContourSet(self, *args, **kwargs)
5813 self.autoscale_view()
5814 return contours
/home/tcaswell/src/p/matplotlib/lib/matplotlib/contour.py in __init__(self, ax, *args, **kwargs)
1419 are described in QuadContourSet.contour_doc.
1420 """
-> 1421 ContourSet.__init__(self, ax, *args, **kwargs)
1422
1423 def _process_args(self, *args, **kwargs):
/home/tcaswell/src/p/matplotlib/lib/matplotlib/contour.py in __init__(self, ax, *args, **kwargs)
862
863 self._process_args(*args, **kwargs)
--> 864 self._process_levels()
865
866 if self.colors is not None:
/home/tcaswell/src/p/matplotlib/lib/matplotlib/contour.py in _process_levels(self)
1202 # The following attributes are no longer needed, and
1203 # should be deprecated and removed to reduce confusion.
-> 1204 self.vmin = np.amin(self.levels)
1205 self.vmax = np.amax(self.levels)
1206
/home/tcaswell/mc3/envs/dd35/lib/python3.5/site-packages/numpy/core/fromnumeric.py in amin(a, axis, out, keepdims)
2395 else:
2396 return _methods._amin(a, axis=axis,
-> 2397 out=out, **kwargs)
2398
2399
/home/tcaswell/mc3/envs/dd35/lib/python3.5/site-packages/numpy/core/_methods.py in _amin(a, axis, out, keepdims)
27
28 def _amin(a, axis=None, out=None, keepdims=False):
---> 29 return umr_minimum(a, axis, None, out, keepdims)
30
31 def _sum(a, axis=None, dtype=None, out=None, keepdims=False):
ValueError: zero-size array to reduction operation minimum which has no identity
In [4]: %debug
> /home/tcaswell/mc3/envs/dd35/lib/python3.5/site-packages/numpy/core/_methods.py(29)_amin()
27
28 def _amin(a, axis=None, out=None, keepdims=False):
---> 29 return umr_minimum(a, axis, None, out, keepdims)
30
31 def _sum(a, axis=None, dtype=None, out=None, keepdims=False):
ipdb> u
> /home/tcaswell/mc3/envs/dd35/lib/python3.5/site-packages/numpy/core/fromnumeric.py(2397)amin()
2395 else:
2396 return _methods._amin(a, axis=axis,
-> 2397 out=out, **kwargs)
2398
2399
ipdb> u
> /home/tcaswell/src/p/matplotlib/lib/matplotlib/contour.py(1204)_process_levels()
1202 # The following attributes are no longer needed, and
1203 # should be deprecated and removed to reduce confusion.
-> 1204 self.vmin = np.amin(self.levels)
1205 self.vmax = np.amax(self.levels)
1206
ipdb> self.levels
array([], dtype=float64)
ipdb>
I do not get it to kill python, but get the above exception (with numpy 1.11, might be different from OP).
The issues here seems to be that when we try to find the levels we prune them to levels inside of the data range via
# For line contours, drop levels outside the data range.returnlev[(lev>zmin) & (lev<zmax)]
in mpl.contour.CountourSet._autolev
which if the data is singular results in no levels and hence the issue.
The specific work here is to:
adapt _autolev to do something 'sensible' in the singular case. Probably we should return 2 levels using our standard expand_non_singular method?
This is a very limited change (so new-contributor friendly), but might require careful thought about what it should do in the singular case, hence medium difficulty.
@tacaswell, I don't see any point in making levels--contouring is fundamentally impossible without a single cell, which requires at least a 2x2. I think the thing to do raise a ValueError early on if any input array has a dimension less than 2.
This may be numpy-specific. I think we ran into a similar error recently in
plot_surface() when trying to broadcast empty arrays, or something like
that. I agree that a ValueError should be raised if the resulting X/Y
domain shape is less than 2x2.
@tacaswellhttps://github.com/tacaswell, I don't see any point in
making levels--contouring is fundamentally impossible without a single
cell, which requires at least a 2x2. I think the thing to do raise a
ValueError early on if any input array has a dimension less than 2.
I'm using numpy 1.11.2+mkl from Gohlke, and I start script from Windows cmd (if it helps),
and plt.contour([[1]]) is also enough to kill Python on my computer.
@tacaswell yes I have the same traceback ... ValueError: zero-size array to reduction operation minimum which has no identity
I'll submit a PR to deal with the i % _chunk_size undefined when _chunk_size == 0 in the C++ code. But isn't this a separate problem to that reported by OP?
@cgohlke Discussions between @tacaswell, @efiring and @WeatherGod are all about contouring with zero levels, showing stack traces in the python code before any of the C++ is called. Hence there are two separate issues.
Activity
tacaswell commentedon Nov 20, 2016
I do not get it to kill python, but get the above exception (with numpy 1.11, might be different from OP).
The issues here seems to be that when we try to find the levels we prune them to levels inside of the data range via
in
mpl.contour.CountourSet._autolevwhich if the data is singular results in no levels and hence the issue.
The specific work here is to:
_autolevto do something 'sensible' in the singular case. Probably we should return 2 levels using our standard expand_non_singular method?This is a very limited change (so new-contributor friendly), but might require careful thought about what it should do in the singular case, hence medium difficulty.
tacaswell commentedon Nov 20, 2016
@godaygo Thanks for reporting this!
efiring commentedon Nov 20, 2016
@tacaswell, I don't see any point in making levels--contouring is fundamentally impossible without a single cell, which requires at least a 2x2. I think the thing to do raise a ValueError early on if any input array has a dimension less than 2.
WeatherGod commentedon Nov 20, 2016
This may be numpy-specific. I think we ran into a similar error recently in
plot_surface() when trying to broadcast empty arrays, or something like
that. I agree that a ValueError should be raised if the resulting X/Y
domain shape is less than 2x2.
On Sun, Nov 20, 2016 at 1:30 AM, Eric Firing notifications@github.com
wrote:
tacaswell commentedon Nov 20, 2016
You get the same exception with a uniform field
Erroring on non-sensible sized arrays in a different issue
godaygo commentedon Nov 20, 2016
I'm using numpy 1.11.2+mkl from Gohlke, and I start script from Windows cmd (if it helps),

and
plt.contour([[1]])is also enough to kill Python on my computer.@tacaswell yes I have the same traceback
... ValueError: zero-size array to reduction operation minimum which has no identitycgohlke commentedon May 3, 2017
For sake of completeness: the segfault on Windows is at _contour.cpp#L1225. The modulo operation
i % _chunk_sizeis undefined when_chunk_size == 0.Call Stack:
Locals:
ianthomas23 commentedon May 3, 2017
I'll submit a PR to deal with the
i % _chunk_sizeundefined when_chunk_size == 0in the C++ code. But isn't this a separate problem to that reported by OP?cgohlke commentedon May 3, 2017
Modulo by zero is the immediate cause of the crash reported by OP.
ianthomas23 commentedon May 3, 2017
@cgohlke Discussions between @tacaswell, @efiring and @WeatherGod are all about contouring with zero levels, showing stack traces in the python code before any of the C++ is called. Hence there are two separate issues.
BUG: handle empty levels array in contour, closes matplotlib#7486
tacaswell commentedon Jun 11, 2017
@ianthomas23 Is there a PR for the
_chunk_size ==0issues?ianthomas23 commentedon Jun 12, 2017
@tacaswell No, not yet. I hope to write one soon.
Merge pull request #8719 from efiring/contour_validation
ianthomas23 commentedon Jul 14, 2017
@tacaswell It turns out that the
_chunk_size == 0issue was fixed in March by PR #8227.