Holoviews plotting issues

Open
#128 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
pandas, python

Research direction

Start in streamz/dataframe/holoviews.py, especially Series.plot and the converter entry point shown in the trace. Reproduce both grouped-series and grouped-dataframe bar plots from the issue, then inspect the plotting paths involved. Done means both examples produce working bar plots without the reported AttributeError or ambiguous DataFrame truth-value error.

Written by the indexing model from the issue text.

Description

Given this setup

import pandas as pd
from streamz.dataframe import DataFrame, Random
import streamz.dataframe.holoviews

df = pd.DataFrame({'x': [1, 2, 3], 'y': [4.5, 5, 6.5]},
                  pd.DatetimeIndex([1, 2, 3]))
sdf = DataFrame(example=df)

This fails because Series.plot doesn't support bar.

sdf.groupby('x').y.mean().plot.bar()
AttributeError                            Traceback (most recent call last)
<ipython-input-11-1265e5d0fb4f> in <module>()
----> 1 sdf.groupby('x').y.mean().plot.bar()

/home/mrocklin/workspace/streamz/streamz/dataframe/holoviews.py in bar(self, **kwds)
    298         axes : matplotlib.AxesSubplot or np.array of them
    299         """
--> 300         return self(kind='bar', **kwds)
    301 
    302     def barh(self, **kwds):

/home/mrocklin/workspace/streamz/streamz/dataframe/holoviews.py in __call__(self, kind, width, height, backlog, use_index, title, grid, legend, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, **kwds)
    256             xticks=xticks, yticks=yticks, xlim=xlim, ylim=ylim, rot=rot,
    257             fontsize=fontsize, colormap=colormap, yerr=yerr, xerr=xerr, **kwds)
--> 258         return converter(kind)
    259 
    260     def line(self, **kwds):

/home/mrocklin/workspace/streamz/streamz/dataframe/holoviews.py in __call__(self, kind)
    177 
    178     def __call__(self, kind):
--> 179         return getattr(self, kind)()
    180 
    181     def chart(self, chart):

AttributeError: 'HoloViewsSeriesConverter' object has no attribute 'bar'

When we do the same thing with a dataframe we get a different error:

sdf.groupby('x').mean().plot.bar()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/home/mrocklin/Software/anaconda/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
    305                 pass
    306             else:
--> 307                 return printer(obj)
    308             # Finally look for special method names
    309             method = get_real_method(obj, self.print_method)

/home/mrocklin/workspace/holoviews/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 

/home/mrocklin/workspace/holoviews/holoviews/ipython/display_hooks.py in display(obj, raw, **kwargs)
    243     elif isinstance(obj, (HoloMap, DynamicMap)):
    244         with option_state(obj):
--> 245             html = map_display(obj)
    246     else:
    247         return repr(obj) if raw else IPython.display.display(obj, **kwargs)

/home/mrocklin/workspace/holoviews/holoviews/ipython/display_hooks.py in wrapped(element)
    130         try:
    131             html = fn(element,
--> 132                       max_frames=OutputSettings.options['max_frames'])
    133 
    134             # Only want to add to the archive for one display hook...

/home/mrocklin/workspace/holoviews/holoviews/ipython/display_hooks.py in map_display(vmap, max_frames)
    198         return None
    199 
--> 200     return render(vmap)
    201 
    202 

/home/mrocklin/workspace/holoviews/holoviews/ipython/display_hooks.py in render(obj, **kwargs)
     60     if renderer.fig == 'pdf':
     61         renderer = renderer.instance(fig='png')
---> 62     return renderer.html(obj, **kwargs)
     63 
     64 

/home/mrocklin/workspace/holoviews/holoviews/plotting/renderer.py in html(self, obj, fmt, css, comm, **kwargs)
    256         code to initialize a Comm, if the plot supplies one.
    257         """
--> 258         plot, fmt =  self._validate(obj, fmt)
    259         figdata, _ = self(plot, fmt, **kwargs)
    260         if css is None: css = self.css

/home/mrocklin/workspace/holoviews/holoviews/plotting/renderer.py in _validate(self, obj, fmt)
    192         if isinstance(obj, tuple(self.widgets.values())):
    193             return obj, 'html'
--> 194         plot = self.get_plot(obj, renderer=self)
    195 
    196         fig_formats = self.mode_formats['fig'][self.mode]

/home/mrocklin/workspace/holoviews/holoviews/plotting/bokeh/renderer.py in get_plot(self_or_cls, obj, doc, renderer)
    115         combining the bokeh model with another plot.
    116         """
--> 117         plot = super(BokehRenderer, self_or_cls).get_plot(obj, renderer)
    118         if self_or_cls.mode == 'server' and doc is None:
    119             doc = curdoc()

/home/mrocklin/workspace/holoviews/holoviews/plotting/renderer.py in get_plot(self_or_cls, obj, renderer)
    164         """
    165         # Initialize DynamicMaps with first data item
--> 166         initialize_dynamic(obj)
    167         backend = self_or_cls.backend
    168 

/home/mrocklin/workspace/holoviews/holoviews/plotting/util.py in initialize_dynamic(obj)
    179             continue
    180         if not len(dmap):
--> 181             dmap[dmap._initial_key()]
    182 
    183 

/home/mrocklin/workspace/holoviews/holoviews/core/spaces.py in __getitem__(self, key)
   1024         # Not a cross product and nothing cached so compute element.
   1025         if cache is not None: return cache
-> 1026         val = self._execute_callback(*tuple_key)
   1027         if data_slice:
   1028             val = self._dataslice(val, data_slice)

/home/mrocklin/workspace/holoviews/holoviews/core/spaces.py in _execute_callback(self, *args)
    840         kdims = [kdim.name for kdim in self.kdims]
    841         kwarg_items = [s.contents.items() for s in self.streams]
--> 842         hash_items = tuple(tuple(sorted(s.hashkey.items())) for s in self.streams)+args
    843         flattened = [(k,v) for kws in kwarg_items for (k,v) in kws
    844                      if k not in kdims]

/home/mrocklin/workspace/holoviews/holoviews/core/spaces.py in <genexpr>(.0)
    840         kdims = [kdim.name for kdim in self.kdims]
    841         kwarg_items = [s.contents.items() for s in self.streams]
--> 842         hash_items = tuple(tuple(sorted(s.hashkey.items())) for s in self.streams)+args
    843         flattened = [(k,v) for kws in kwarg_items for (k,v) in kws
    844                      if k not in kdims]

/home/mrocklin/workspace/holoviews/holoviews/streams.py in hashkey(self)
    388     @property
    389     def hashkey(self):
--> 390         if self._memoize:
    391             return self.contents
    392         return {'hash': uuid.uuid4().hex}

/home/mrocklin/Software/anaconda/lib/python3.6/site-packages/pandas/core/generic.py in __nonzero__(self)
   1119         raise ValueError("The truth value of a {0} is ambiguous. "
   1120                          "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1121                          .format(self.__class__.__name__))
   1122 
   1123     __bool__ = __nonzero__

ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Out[15]:
:DynamicMap   []
In [12]:

I'm on my plot-holoviews branch. cc @philippjfr

Dominant language
Python
Stars
1.3k
Forks
149
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-streamz/streamz

All issues in python-streamz/streamz

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.