Davide Fiocco
Davide Fiocco

Reputation: 5914

Why can't I plot this dask dataframe with datashader (not enough values to unpack)?

I'd like to plot a large-ish graph with datashader + holoviews, but I am getting an error.
Something small and reproducible is:

import holoviews as hv
import pandas as pd
import dask.dataframe as dd
from holoviews.operation.datashader import (
    datashade, aggregate, dynspread,
    bundle_graph, split_dataframe,  regrid
)
from holoviews.element.graphs import layout_nodes
from datashader.layout import forceatlas2_layout, random_layout

hv.extension('bokeh')

targets = [4, 4, 4, 4, 4]
sources = [3, 1, 2, 3, 4]
df = pd.DataFrame({'source': sources, 'target': targets})
edges_df = dd.from_pandas(df, npartitions=3)

graph = layout_nodes(hv.Graph(edges_df), layout=forceatlas2_layout)
forceatlas = bundle_graph(graph, split=False)
pad = dict(x=(-.5, 1.3), y=(-.5, 1.3))
datashade(forceatlas, width=800, height=800) * forceatlas.nodes.redim.range(**pad)

which fails with

ValueError: not enough values to unpack (expected 3, got 0)
---> 17 graph = layout_nodes(hv.Graph(edges_df), layout=forceatlas2_layout)

However, setting targets = [1, 1, 1, 1, 1] I get a plot.
With the "faulty" targets, if I use random_layout instead of forceatlas2, I also get a plot.

I am puzzled! Why I am I getting that error and how to get rid of it? I am using datashader 0.7.0.

Upvotes: 2

Views: 539

Answers (1)

Davide Fiocco
Davide Fiocco

Reputation: 5914

Try to replace the problematic line with
graph = layout_nodes(hv.Graph(edges_df), layout=forceatlas2_layout, kwargs = {'id': 'index'})

This should allow to cope with the library internals.

Upvotes: 1

Related Questions