Repository: holoviz/holoviews

Issue:
Always get warnings.warn("All-NaN slice encountered", RuntimeWarning) for Overlay
I always get this error when creating an `hv.Overlay`:

``` python
x = np.linspace(0, 1)
hv.Path((x,x)) + hv.Path((x,x))
```

```
/home/bnijholt/anaconda3/lib/python3.5/site-packages/numpy/lib/nanfunctions.py:326: RuntimeWarning: All-NaN slice encountered
  warnings.warn("All-NaN slice encountered", RuntimeWarning)
```

if run with:

```
import warnings
warnings.simplefilter('error')
```

it generates this traceback:

```
RuntimeWarningTraceback (most recent call last)
/home/bnijholt/anaconda3/lib/python3.5/site-packages/IPython/core/formatters.py in __call__(self, obj)
    337                 pass
    338             else:
--> 339                 return printer(obj)
    340             # Finally look for special method names
    341             method = _safe_get_formatter_method(obj, self.print_method)

/home/bnijholt/anaconda3/lib/python3.5/site-packages/holoviews/ipython/display_hooks.py in pprint_display(obj)
    214     if not ip.display_formatter.formatters['text/plain'].pprint:
    215         return None
--> 216     return display(obj, raw=True)
    217 
    218 

/home/bnijholt/anaconda3/lib/python3.5/site-packages/holoviews/ipython/display_hooks.py in display(obj, raw, **kwargs)
    198         html = element_display(obj)
    199     elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
--> 200         html = layout_display(obj)
    201     elif isinstance(obj, (HoloMap, DynamicMap)):
    202         html = map_display(obj)

/home/bnijholt/anaconda3/lib/python3.5/site-packages/holoviews/ipython/display_hooks.py in wrapped(element)
    101             html = fn(element,
    102                       max_frames=OutputMagic.options['max_frames'],
--> 103                       max_branches = OutputMagic.options['max_branches'])
    104 
    105             # Only want to add to the archive for one display hook...

/home/bnijholt/anaconda3/lib/python3.5/site-packages/holoviews/ipython/display_hooks.py in layout_display(layout, max_frames, max_branches)
    172                 return '<tt>'+ sanitize_HTML(layout) + '</tt>'
    173 
--> 174     return render(layout)
    175 
    176 

/home/bnijholt/anaconda3/lib/python3.5/site-packages/holoviews/ipython/display_hooks.py in render(obj, **kwargs)
     49 
     50     backend = Store.current_backend
---> 51     return Store.renderers[backend].html(obj, **kwargs)
     52 
     53 

/home/bnijholt/anaconda3/lib/python3.5/site-packages/holoviews/plotting/renderer.py in html(self, obj, fmt, css)
    247         Renders plot or data structure and wraps the output in HTML.
    248         """
--> 249         plot, fmt =  self._validate(obj, fmt)
    250         figdata, _ = self(plot, fmt)
    251         if css is None: css = self.css

/home/bnijholt/anaconda3/lib/python3.5/site-packages/holoviews/plotting/renderer.py in _validate(self, obj, fmt)
    187         if isinstance(obj, tuple(self.widgets.values())):
    188             return obj, 'html'
--> 189         plot = self.get_plot(obj)
    190 
    191         fig_formats = self.mode_formats['fig'][self.mode]

/home/bnijholt/anaconda3/lib/python3.5/site-packages/holoviews/plotting/renderer.py in get_plot(self_or_cls, obj)
    173             obj = Layout.from_values(obj) if isinstance(obj, AdjointLayout) else obj
    174             plot_opts = self_or_cls.plot_options(obj, self_or_cls.size)
--> 175             plot = self_or_cls.plotting_class(obj)(obj, **plot_opts)
    176             plot.update(0)
    177         else:

/home/bnijholt/anaconda3/lib/python3.5/site-packages/holoviews/plotting/mpl/plot.py in __init__(self, layout, **params)
    715     def __init__(self, layout, **params):
    716         super(LayoutPlot, self).__init__(layout=layout, **params)
--> 717         self.subplots, self.subaxes, self.layout = self._compute_gridspec(layout)
    718 
    719 

/home/bnijholt/anaconda3/lib/python3.5/site-packages/holoviews/plotting/mpl/plot.py in _compute_gridspec(self, layout)
    804                            for ratios in col[1] for r in ratios])/4
    805 
--> 806         wr_unnormalized = compute_ratios(col_widthratios, False)
    807         hr_list = compute_ratios(row_heightratios)
    808         wr_list = compute_ratios(col_widthratios)

/home/bnijholt/anaconda3/lib/python3.5/site-packages/holoviews/plotting/mpl/util.py in compute_ratios(ratios, normalized)
     48         unpacked = normalize_ratios(unpacked)
     49     sorted_ratios = sorted(unpacked.items())
---> 50     return np.nanmax(np.vstack([v for _, v in sorted_ratios]), axis=0)

/home/bnijholt/anaconda3/lib/python3.5/site-packages/numpy/lib/nanfunctions.py in nanmax(a, axis, out, keepdims)
    324         res = np.fmax.reduce(a, axis=axis, out=out, keepdims=keepdims)
    325         if np.isnan(res).any():
--> 326             warnings.warn("All-NaN slice encountered", RuntimeWarning)
    327     else:
    328         # Slow, but safe for subclasses of ndarray

RuntimeWarning: All-NaN slice encountered
```



Discussion:
Can't seem to reproduce it, but I'll investigate.


Resolving patch:
diff --git a/holoviews/plotting/mpl/util.py b/holoviews/plotting/mpl/util.py
--- a/holoviews/plotting/mpl/util.py
+++ b/holoviews/plotting/mpl/util.py
@@ -1,5 +1,6 @@
 import re
 import inspect
+import warnings
 
 import numpy as np
 from matplotlib import ticker
@@ -54,4 +55,6 @@ def compute_ratios(ratios, normalized=True):
     if normalized:
         unpacked = normalize_ratios(unpacked)
     sorted_ratios = sorted(unpacked.items())
-    return np.nanmax(np.vstack([v for _, v in sorted_ratios]), axis=0)
+    with warnings.catch_warnings():
+        warnings.filterwarnings('ignore', r'All-NaN (slice|axis) encountered')
+        return np.nanmax(np.vstack([v for _, v in sorted_ratios]), axis=0)


Test patch: