Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError with {+framewise} #1681

Closed
wjaskowski opened this issue Jul 5, 2017 · 7 comments
Closed

ValueError with {+framewise} #1681

wjaskowski opened this issue Jul 5, 2017 · 7 comments
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@wjaskowski
Copy link

%%opts Curve {+framewise}
import numpy
from numpy import nan
import pandas as pd
d = {'episode': {0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9, 9: 10, 41038: 1}, 'env': {0: 'PlayCar-sparse-PO-v0', 1: 'PlayCar-sparse-PO-v0', 2: 'PlayCar-sparse-PO-v0', 3: 'PlayCar-sparse-PO-v0', 4: 'PlayCar-sparse-PO-v0', 5: 'PlayCar-sparse-PO-v0', 6: 'PlayCar-sparse-PO-v0', 7: 'PlayCar-sparse-PO-v0', 8: 'PlayCar-sparse-PO-v0', 9: 'PlayCar-sparse-PO-v0', 41038: 'PlayCar-sparse-FO-v0'}, 'score_median': {0: -0.39221233057876648, 1: -0.64874784472492342, 2: -0.80498630364717672, 3: -0.34529109248654644, 4: -0.34852065726350029, 5: -0.38275313445209669, 6: -0.35748195898593138, 7: -0.33843932089407558, 8: -0.3793503433564655, 9: -0.31926233659041581, 41038: -0.39221233057876648}, 'eval_score_median': {0: nan, 1: nan, 2: nan, 3: nan, 4: -0.42274388187290413, 5: nan, 6: nan, 7: nan, 8: nan, 9: -0.40752829288059794, 41038: nan}}
df = pd.DataFrame(d)

ds = hv.Dataset(df, kdims=kdims, vdims=vdims)
ds2 = hv.Dataset(df.dropna(), kdims=kdims, vdims=['eval_score_median'])

score = ds.to(hv.Curve, kdims='episode', vdims='score_median')
    
eval_score = ds2.to(hv.Curve, kdims='episode', vdims='eval_score_median')

(score + eval_score).cols(1)

works fine without {+framewise} but produces the following error with it:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/miniconda3/envs/rlzoo/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)

~/miniconda3/envs/rlzoo/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 

~/miniconda3/envs/rlzoo/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in display(obj, raw, **kwargs)
    240     elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
    241         with option_state(obj):
--> 242             html = layout_display(obj)
    243     elif isinstance(obj, (HoloMap, DynamicMap)):
    244         with option_state(obj):

~/miniconda3/envs/rlzoo/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...

~/miniconda3/envs/rlzoo/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in layout_display(layout, max_frames)
    211         return None
    212 
--> 213     return render(layout)
    214 
    215 

~/miniconda3/envs/rlzoo/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in render(obj, **kwargs)
     59     if renderer.fig == 'pdf':
     60         renderer = renderer.instance(fig='png')
---> 61     return renderer.html(obj, **kwargs)
     62 
     63 

~/miniconda3/envs/rlzoo/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

~/miniconda3/envs/rlzoo/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]

~/miniconda3/envs/rlzoo/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 doc is not None:
    114             plot.document = doc

~/miniconda3/envs/rlzoo/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

~/miniconda3/envs/rlzoo/lib/python3.6/site-packages/holoviews/plotting/plot.py in 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))
    488         return item

~/miniconda3/envs/rlzoo/lib/python3.6/site-packages/holoviews/plotting/plot.py in __getitem__(self, frame)
    222         if not isinstance(frame, tuple):
    223             frame = self.keys[frame]
--> 224         self.update_frame(frame)
    225         return self.state
    226 

~/miniconda3/envs/rlzoo/lib/python3.6/site-packages/holoviews/plotting/bokeh/util.py in wrapper(self, *args, **kwargs)
    646             source.data.clear()
    647 
--> 648         ret = f(self, *args, **kwargs)
    649 
    650         for source in shared_sources:

~/miniconda3/envs/rlzoo/lib/python3.6/site-packages/holoviews/plotting/bokeh/plot.py in update_frame(self, key, ranges)
    721         state.
    722         """
--> 723         ranges = self.compute_ranges(self.layout, key, ranges)
    724         for r, c in self.coords:
    725             subplot = self.subplots.get((r, c), None)

~/miniconda3/envs/rlzoo/lib/python3.6/site-packages/holoviews/plotting/plot.py in compute_ranges(self, obj, key, ranges)
    344                 elements = obj.traverse(return_fn, [group])
    345             elif key is not None: # Traverse to get elements for each frame
--> 346                 frame = self._get_frame(key)
    347                 elements = [] if frame is None else frame.traverse(return_fn, [group])
    348             # Only compute ranges if not axiswise on a composite plot

~/miniconda3/envs/rlzoo/lib/python3.6/site-packages/holoviews/plotting/plot.py in _get_frame(self, key)
    989         for path, item in self.layout.items():
    990             frame = item.map(lambda x: get_plot_frame(x, key_map, cached=cached),
--> 991                              ['DynamicMap', 'HoloMap'])
    992             if frame is not None:
    993                 layout_frame[path] = frame

~/miniconda3/envs/rlzoo/lib/python3.6/site-packages/holoviews/core/dimension.py in map(self, map_fn, specs, clone)
    638             deep_mapped = self.clone(shared_data=False) if clone else self
    639             for k, v in self.items():
--> 640                 deep_mapped[k] = v.map(map_fn, specs, clone)
    641             if applies: deep_mapped = map_fn(deep_mapped)
    642             return deep_mapped

~/miniconda3/envs/rlzoo/lib/python3.6/site-packages/holoviews/core/layout.py in __setitem__(self, key, value)
    214                 self.data[key] = value
    215             else:
--> 216                 raise ValueError('AdjointLayout only accepts Element types.')
    217         else:
    218             raise Exception('Position %s not valid in AdjointLayout.' % key)

ValueError: AdjointLayout only accepts Element types.
@jlstevens jlstevens added the type: bug Something isn't correct or isn't working label Jul 5, 2017
@philippjfr
Copy link
Member

Easy fix, assigning to 1.8.1.

@philippjfr philippjfr added this to the v1.8.1 milestone Jul 5, 2017
@philippjfr
Copy link
Member

@jlstevens Actually this needs some discussion. The problem here is that this code uses the .map function, which is returning None in this instance. That part is correct, unfortunately because it's mapping against a nested object the container of the object (in this case an AdjointLayout but it could be other types) ends up complaining because it doesn't like its values being None. The simplest fix is for map to simply drop objects which return None when the function is applied. This makes sense in the context of HoloViews objects, but in theory at least NdMapping types and other hypothetical containers inheriting from Dimensioned may want to allow None types as values. Any opinions?

@jlstevens
Copy link
Contributor

Unless you can think of a particular use-case, I don't see an issue with disallowing None as values. Containers such as HoloMaps expect the values to be HoloViews elements/objects and not None as it is afaik.

@philippjfr
Copy link
Member

Unless you can think of a particular use-case

I cannot.

Containers such as HoloMaps expect the values to be HoloViews elements/objects and not None as it is afaik.

Right all our concrete containers do, but some of the baseclasses, e.g. Tree and NdMapping don't have such restrictions at present afaik.

@jlstevens
Copy link
Contributor

None values as tree values don't seem particularly desirable and I don't have an issue with disallowing None values in NdMapping either. Right now I think fixing this issue takes priority over supporting None values.

@philippjfr
Copy link
Member

Good, I was just playing devils advocate. My preference is also to make this fix now.

@philippjfr
Copy link
Member

This should be fixed now and will land in the 1.8.1 release scheduled for tomorrow, please reopen if you encounter any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

No branches or pull requests

3 participants