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

Avoid KeyError when overlaying dynamic groupbys #5603

Closed
wants to merge 1 commit into from

Conversation

jlstevens
Copy link
Contributor

@jlstevens jlstevens commented Jan 26, 2023

WIP

Here is the test example:

import holoviews as hv
import pandas as pd
import numpy as np
hv.extension('bokeh')

df1 = pd.DataFrame({'sym':['CAT1']*5 + ['CAT2']*5, 'x':list(range(10)), 'y':np.random.rand(10)})
df2 = pd.DataFrame({'sym':['CAT1']*10, 'x':list(range(10)), 'y':np.random.rand(10)})

ds1 = hv.Dataset(df1)
ds2 = hv.Dataset(df2)
ds1.to(hv.Spikes, 'x', 'y', groupby=['sym'], dynamic=True) * ds2.to(hv.Spikes, 'x', 'y', groupby=['sym'], dynamic=True).opts(color='blue')

With this PR you can select CAT2:

image

On main you get a keyerror:

Traceback (most recent call last): File "/Users/jstevens/Desktop/development/holoviews/holoviews/plotting/renderer.py", line 538, in plotting_class plotclass = Store.registry[cls.backend][element_type] KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/pyviz_comms/init.py", line 338, in _handle_msg
self._on_msg(msg)
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/panel/viewable.py", line 294, in _on_msg
doc.unhold()
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/bokeh/document/document.py", line 799, in unhold
self.callbacks.unhold()
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/bokeh/document/callbacks.py", line 396, in unhold
self.trigger_on_change(event)
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/bokeh/document/callbacks.py", line 373, in trigger_on_change
invoke_with_curdoc(doc, event.callback_invoker)
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/bokeh/document/callbacks.py", line 408, in invoke_with_curdoc
return f()
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/bokeh/util/callback_manager.py", line 191, in invoke
callback(attr, old, new)
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/panel/reactive.py", line 405, in _comm_change
state._handle_exception(e)
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/panel/io/state.py", line 391, in _handle_exception
raise exception
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/panel/reactive.py", line 403, in _comm_change
self._schedule_change(doc, comm)
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/panel/reactive.py", line 385, in _schedule_change
self._change_event(doc)
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/panel/reactive.py", line 381, in _change_event
self._process_events(events)
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/panel/reactive.py", line 319, in process_events
self.param.update(**self_events)
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/param/parameterized.py", line 1898, in update
self
._batch_call_watchers()
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/param/parameterized.py", line 2059, in batch_call_watchers
self
._execute_watcher(watcher, events)
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/param/parameterized.py", line 2021, in _execute_watcher
watcher.fn(*args, **kwargs)
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/panel/pane/holoviews.py", line 240, in _widget_callback
self._update_plot(plot, pane)
File "/Users/jstevens/miniconda3/envs/analytics/lib/python3.7/site-packages/panel/pane/holoviews.py", line 222, in _update_plot
plot.update(key)
File "/Users/jstevens/Desktop/development/holoviews/holoviews/plotting/plot.py", line 937, in update
item = self.getitem(key)
File "/Users/jstevens/Desktop/development/holoviews/holoviews/plotting/plot.py", line 423, in getitem
self.update_frame(frame)
File "/Users/jstevens/Desktop/development/holoviews/holoviews/plotting/bokeh/element.py", line 2432, in update_frame
defaults=False)
File "/Users/jstevens/Desktop/development/holoviews/holoviews/plotting/plot.py", line 890, in _traverse_options
traversed = obj.traverse(lookup, specs)
File "/Users/jstevens/Desktop/development/holoviews/holoviews/core/dimension.py", line 662, in traverse
accumulator += el.traverse(fn, specs, full_breadth)
File "/Users/jstevens/Desktop/development/holoviews/holoviews/core/dimension.py", line 655, in traverse
accumulator.append(fn(self))
File "/Users/jstevens/Desktop/development/holoviews/holoviews/plotting/plot.py", line 879, in lookup
options = cls.lookup_options(x, opt_type)
File "/Users/jstevens/Desktop/development/holoviews/holoviews/plotting/plot.py", line 275, in lookup_options
return lookup_options(obj, group, cls.backend)
File "/Users/jstevens/Desktop/development/holoviews/holoviews/core/options.py", line 94, in lookup_options
plot_class = Store.renderers[backend].plotting_class(obj)
File "/Users/jstevens/Desktop/development/holoviews/holoviews/plotting/renderer.py", line 540, in plotting_class
raise SkipRendering(f"No plotting class for {element_type.name} found")
AttributeError: 'NoneType' object has no attribute 'name'

I thought I could return an empty element from the dynamicmap created by groupby in the .to call but I always hit key errors in the plotting code until this change.

@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2023

Codecov Report

Merging #5603 (0a14467) into main (387503f) will decrease coverage by 0.01%.
The diff coverage is 50.00%.

@@            Coverage Diff             @@
##             main    #5603      +/-   ##
==========================================
- Coverage   88.33%   88.33%   -0.01%     
==========================================
  Files         302      302              
  Lines       62428    62430       +2     
==========================================
+ Hits        55147    55148       +1     
- Misses       7281     7282       +1     
Impacted Files Coverage Δ
holoviews/plotting/plot.py 93.44% <50.00%> (-0.08%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@jlstevens
Copy link
Contributor Author

Closing in favor of #5604 - turns out it was just a bug in formatting an error message!

@jlstevens jlstevens closed this Jan 26, 2023
@hoxbro hoxbro deleted the dynamic_dataset_empty_element branch February 24, 2023 08:33
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants