holoviews icon indicating copy to clipboard operation
holoviews copied to clipboard

unable to use datashader with holoviews

Open junefeld opened this issue 1 year ago • 1 comments

ALL software version info

miniconda, python 3.9.4, conda install -c pyviz holoviews bokeh datashader, networkx==2.8.5, windows server 2016

Description of expected behavior and the observed behavior

Trying to run datashader plug in (also tried native datashader), used various versions of datashader, holoviews, networkx, numba, etc.

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

import pandas as pd
node = ['a','b','c','d']
edge = ['b','c','d','f']
df_nx = pd.DataFrame(zip(node,edge))

import networkx as nx

G = nx.from_pandas_edgelist(df_nx, source=0, target=1)

from holoviews.operation.datashader import datashade, bundle_graph
datashade(bundle_graph(G), normalization='linear', width=800, height=800) *\
bundled.select(circle='circle15').opts(node_fill_color='white')

Stack traceback and/or browser JavaScript console output

Traceback (most recent call last):
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\IPython\core\interactiveshell.py", line 3398, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "C:\Users\cfeld\AppData\Local\Temp\2\ipykernel_15172\2047935676.py", line 2, in <cell line: 2>
    datashade(bundle_graph(G), normalization='linear', width=800, height=800) *\
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\param\parameterized.py", line 3631, in __new__
    return inst.__call__(*args,**params)
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\holoviews\core\operation.py", line 220, in __call__
    return element.apply(self, **kwargs)
AttributeError: 'Graph' object has no attribute 'apply'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\IPython\core\interactiveshell.py", line 1993, in showtraceback
    stb = self.InteractiveTB.structured_traceback(
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\IPython\core\ultratb.py", line 1118, in structured_traceback
    return FormattedTB.structured_traceback(
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\IPython\core\ultratb.py", line 1012, in structured_traceback
    return VerboseTB.structured_traceback(
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\IPython\core\ultratb.py", line 865, in structured_traceback
    formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\IPython\core\ultratb.py", line 818, in format_exception_as_a_whole
    frames.append(self.format_record(r))
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\IPython\core\ultratb.py", line 736, in format_record
    result += ''.join(_format_traceback_lines(frame_info.lines, Colors, self.has_colors, lvals))
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\stack_data\utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\stack_data\core.py", line 698, in lines
    pieces = self.included_pieces
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\stack_data\utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\stack_data\core.py", line 645, in included_pieces
    scope_pieces = self.scope_pieces
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\stack_data\utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\stack_data\core.py", line 585, in scope_pieces
    for piece in self.source.pieces
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\stack_data\utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\stack_data\core.py", line 90, in pieces
    return list(self._clean_pieces())
  File "E:\Data_Science\virtual_envs\trajectory_dev\lib\site-packages\stack_data\core.py", line 114, in _clean_pieces
    raise AssertionError("Pieces mismatches: %s" % mismatches)
AssertionError: Pieces mismatches: [{660, 661}, {675, 676}, {688, 689}, {694, 695}]

junefeld avatar Jul 26 '22 22:07 junefeld

This is more of a user question and would be better to ask on Discourse.

The main problem is that you need to convert the Graph to a Holoviews object, which can then be passed to Datashader. For more information look here.

An example of what I mean:

image

import pandas as pd
import networkx as nx
import holoviews as hv
from holoviews.operation.datashader import datashade, bundle_graph
hv.extension("bokeh")

node = ['a','b','c','d']
edge = ['b','c','d','f']
df_nx = pd.DataFrame(zip(node,edge))
G = nx.from_pandas_edgelist(df_nx, source=0, target=1)

graph = hv.Graph((G.edges,))
graph

shade_plot = datashade(bundle_graph(graph), width=800, height=800).opts(padding=0.1) 
node_plot = graph.nodes.select(circle='circle15').opts(fill_color='white')
shade_plot * node_plot

hoxbro avatar Jul 29 '22 07:07 hoxbro