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

No attribute 'session_context' with redim range and datashade #4347

Closed
mmorys opened this issue Mar 31, 2020 · 5 comments · Fixed by #4355
Closed

No attribute 'session_context' with redim range and datashade #4347

mmorys opened this issue Mar 31, 2020 · 5 comments · Fixed by #4355
Labels
tag: backend: bokeh type: bug Something isn't correct or isn't working
Milestone

Comments

@mmorys
Copy link
Contributor

mmorys commented Mar 31, 2020

Software version info

Ubuntu 18.04
python 3.7.6
bokeh 2.0.1
holoviews 1.13.1
notebook 6.0.3
browser: Chromium 80.0.3987.149

Description of expected behavior and the observed behavior

If a plot, such as Scatter, has its range modified using redim prior to being datashaded
(e.g.datashade(hv.Scatter(df, 'x', 'y').redim(y=hv.Dimension('y', range=(-0.5,1.5)))) ),
an error is thrown. This should not cause an error, and worked prior to holoviews 1.13.0.

Conditions for this error behavior:

  • holoviews>=1.13.0
  • Deployed using bokeh serve (Same error when deployed using panel.show() if using panel library)
  • redim used to modify range values

This error does not occur if any of the following are true:

  • holoviews<1.13.0
  • Run in a Jupyter notebook
  • redim does not modify range (e.g. hv.Scatter(df, 'x', 'y').redim(y=hv.Dimension('y2')))

Complete, minimal, self-contained example code that reproduces the issue

# minimal_example.py

import holoviews as hv
import numpy as np
import pandas as pd
from holoviews.operation.datashader import datashade

hv.extension('bokeh')
renderer = hv.renderer('bokeh')

# Create dummy dataset
num_pts = 1000
df = pd.DataFrame({'x':np.linspace(0,100,num_pts), 'y':np.random.random(num_pts)})

# Create scatterplot
hv_plot = hv.Scatter(df, 'x', 'y')

# Redim range (THIS IS THE LINE THAT CAUSES AN ERROR)
hv_plot = hv_plot.redim(y=hv.Dimension('y', range=(-0.5,1.5)))

# Datashade the scatter plot
datashaded_plot = datashade(hv_plot)

# Create bokeh doc
doc = renderer.server_doc(datashaded_plot)

# Run example using 'bokeh serve --show minimal_example.py' from console

Stack traceback and/or browser JavaScript console output

bokeh.application.application - ERROR - Error running application handler <bokeh.application.handlers.script.ScriptHandler object at 0x7f58c595dcd0>: 'NoneType' object has no attribute 'session_context'
File "plot.py", line 218, in refresh:
if self.document.session_context: Traceback (most recent call last):
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/bokeh/application/handlers/code_runner.py", line 197, in run
    exec(self._code, module.__dict__)
  File "/home/user/Documents/panel_viz/bin/minimal_example.py", line 25, in <module>
    doc = renderer.server_doc(datashaded_plot)
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/holoviews/plotting/renderer.py", line 466, in server_doc
    return obj.layout.server_doc(doc)
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/panel/viewable.py", line 600, in server_doc
    model = self.get_root(doc)
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/panel/viewable.py", line 536, in get_root
    root = self._get_model(doc, comm=comm)
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/panel/layout.py", line 136, in _get_model
    objects = self._get_objects(model, [], doc, root, comm)
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/panel/layout.py", line 126, in _get_objects
    child = pane._get_model(doc, root, model, comm)
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/panel/pane/holoviews.py", line 227, in _get_model
    plot = self._render(doc, comm, root)
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/panel/pane/holoviews.py", line 286, in _render
    return renderer.get_plot(self.object, **kwargs)
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/holoviews/plotting/bokeh/renderer.py", line 73, in get_plot
    plot = super(BokehRenderer, self_or_cls).get_plot(obj, doc, renderer, **kwargs)
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/holoviews/plotting/renderer.py", line 223, in get_plot
    plot.update(init_key)
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/holoviews/plotting/plot.py", line 878, in update
    return self.initialize_plot()
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/holoviews/plotting/bokeh/element.py", line 1334, in initialize_plot
    Stream.trigger(trigger)
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/holoviews/streams.py", line 169, in trigger
    subscriber(**dict(union))
  File "/home/user/anaconda3/envs/bokeh-dev/lib/python3.7/site-packages/holoviews/plotting/plot.py", line 218, in refresh
    if self.document.session_context:
AttributeError: 'NoneType' object has no attribute 'session_context'
@mmorys mmorys changed the title Not attribute 'session_context' with redim range and datashade No attribute 'session_context' with redim range and datashade Mar 31, 2020
@philippjfr philippjfr added tag: backend: bokeh type: bug Something isn't correct or isn't working labels Mar 31, 2020
@philippjfr philippjfr added this to the v1.13.2 milestone Mar 31, 2020
@philippjfr
Copy link
Member

We'll have to update the docs, I would not recommend using renderer.server_doc at this point (although it should be fixed for backward compatibility). Instead I'd use panel:

import panel as pn
pn.panel(datashaded_plot).servable()

@mmorys
Copy link
Contributor Author

mmorys commented Apr 1, 2020

I will be using panel as you mentioned. However, the same bug still exists when launching the code using panel serve --show minimal_example.py.

@philippjfr
Copy link
Member

Okay, thanks, I can indeed reproduce.

@philippjfr
Copy link
Member

Will hopefully find a fix today and then release 1.13.2.

Copy link

This issue 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
tag: backend: bokeh type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants