# Buggy code
def max_cycles(self, num):
    """
    Truncates all contained Cycle objects to a maximum number
    of Cycles and returns a new Options object with the
    truncated or resampled Cycles.
    """
    kwargs = {
        kw: (arg[num] if isinstance(arg, Cycle) else arg)
        for kw, arg in self.kwargs.items()
    }
    return self(**kwargs)


# Traceback (ZeroDivisionError)
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
/local_data/anaconda3/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
330                 pass
331             else:
--> 332                 return printer(obj)
333             # Finally look for special method names
334             method = get_real_method(obj, self.print_method)

/local_data/anaconda3/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in pprint_display(obj)
257     if not ip.display_formatter.formatters['text/plain'].pprint:
258         return None
--> 259     return display(obj, raw=True)
260
261

/local_data/anaconda3/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in display(obj, raw, **kwargs)
237     elif isinstance(obj, (CompositeOverlay, ViewableElement)):
238         with option_state(obj):
--> 239             html = element_display(obj)
240     elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
241         with option_state(obj):

/local_data/anaconda3/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in wrapped(element)
129         try:
130             html = fn(element,
--> 131                       max_frames=OutputSettings.options['max_frames'])
132
133             # Only want to add to the archive for one display hook...

/local_data/anaconda3/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in element_display(element, max_frames)
176     if renderer.fig == 'pdf':
177         renderer = renderer.instance(fig='png')
--> 178     return renderer.html(element, fmt=renderer.fig)
179
180

/local_data/anaconda3/lib/python3.6/site-packages/holoviews/plotting/renderer.py in html(self, obj, fmt, css, comm, **kwargs)
253         code to initialize a Comm, if the plot supplies one.
254         """
--> 255         plot, fmt =  self._validate(obj, fmt)
256         figdata, _ = self(plot, fmt, **kwargs)
257         if css is None: css = self.css

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

/local_data/anaconda3/lib/python3.6/site-packages/holoviews/plotting/bokeh/renderer.py in get_plot(self_or_cls, obj, doc, renderer)
110         combining the bokeh model with another plot.
111         """
--> 112         plot = super(BokehRenderer, self_or_cls).get_plot(obj, renderer)
113         if self_or_cls.mode == 'server' and doc is None:
114             doc = curdoc()

/local_data/anaconda3/lib/python3.6/site-packages/holoviews/plotting/renderer.py in get_plot(self_or_cls, obj, renderer)
176             plot = self_or_cls.plotting_class(obj)(obj, renderer=renderer,
177                                                    **plot_opts)
--> 178             plot.update(0)
179         else:
180             plot = obj

/local_data/anaconda3/lib/python3.6/site-packages/holoviews/plotting/plot.py in update(self, key)
483     def update(self, key):
484         if len(self) == 1 and key == 0 and not self.drawn:
--> 485             return self.initialize_plot()
486         item = self.__getitem__(key)
487         self.traverse(lambda x: setattr(x, '_updated', True))

/local_data/anaconda3/lib/python3.6/site-packages/holoviews/plotting/bokeh/element.py in initialize_plot(self, ranges, plot, plots)
1414             frame = None
1415             if self.tabs: subplot.overlaid = False
-> 1416             child = subplot.initialize_plot(ranges, plot, plots)
1417             if isinstance(element, CompositeOverlay):
1418                 frame = element.get(key, None)

/local_data/anaconda3/lib/python3.6/site-packages/holoviews/plotting/bokeh/element.py in initialize_plot(self, ranges, plot, plots, source)
781         self.handles['plot'] = plot
782
--> 783         self._init_glyphs(plot, element, ranges, source)
784         if not self.overlaid:
785             self._update_plot(key, plot, style_element)

/local_data/anaconda3/lib/python3.6/site-packages/holoviews/plotting/bokeh/element.py in _init_glyphs(self, plot, element, ranges, source)
739         self.handles['source'] = source
740
--> 741         properties = self._glyph_properties(plot, style_element, source, ranges)
742         with abbreviated_exception():
743             renderer, glyph = self._init_glyph(plot, mapping, properties)

/local_data/anaconda3/lib/python3.6/site-packages/holoviews/plotting/bokeh/element.py in _glyph_properties(self, plot, element, source, ranges)
648
649     def _glyph_properties(self, plot, element, source, ranges):
--> 650         properties = self.style[self.cyclic_index]
651
652         if self.show_legend:

/local_data/anaconda3/lib/python3.6/site-packages/holoviews/core/options.py in __getitem__(self, index)
483         looping over the set of defined Cycle objects.
484         """
--> 485         return dict(self._options[index % len(self._options)])
486
487

ZeroDivisionError: integer division or modulo by zero

:Overlay
.Dataset_Group.Ds1 :Curve   [y]   (x)
.Dataset_Group.Ds2 :Curve   [y]   (x)
.Dataset_Group.Ds3 :Curve   [y]   (x)

# Fixed code
def max_cycles(self, num):
    """
    Truncates all contained Palette objects to a maximum number
    of samples and returns a new Options object containing the
    truncated or resampled Palettes.
    """
    kwargs = {
        kw: (arg[num] if isinstance(arg, Palette) else arg)
        for kw, arg in self.kwargs.items()
    }
    return self(max_cycles=num, **kwargs)