错误 运行 和弦图的 Holoview 示例

Error Running Holoview Example of Chord Diagram

我目前正在学习 HoloViews 并想从主页复制 Chord-Example:

http://holoviews.org/gallery/demos/bokeh/route_chord.html

我将每行的行复制到我的 jupyter-nb 中,但总是在这一行出错:

chord = hv.Chord((route_counts, nodes), ['SourceID', 'DestinationID'], ['Stops'])

错误信息是:

TypeError                                 Traceback (most recent call last)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
    116     try:
--> 117         num = operator.index(num)
    118     except TypeError:

TypeError: 'numpy.float64' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-13-b727deae3660> in <module>
----> 1 chord = hv.Chord((route_counts, nodes), ['SourceID', 'DestinationID'], ['Stops'])
      2 

~\AppData\Local\Continuum\anaconda3\lib\site-packages\holoviews\element\graphs.py in __init__(self, data, kdims, vdims, compute, **params)
    768         if compute:
    769             self._nodes = nodes
--> 770             chord = layout_chords(self)
    771             self._nodes = chord.nodes
    772             self._edgepaths = chord.edgepaths

~\AppData\Local\Continuum\anaconda3\lib\site-packages\param\parameterized.py in __new__(class_, *args, **params)
   2810         inst = class_.instance()
   2811         inst.param._set_name(class_.__name__)
-> 2812         return inst.__call__(*args,**params)
   2813 
   2814     def __call__(self,*args,**kw):

~\AppData\Local\Continuum\anaconda3\lib\site-packages\holoviews\core\operation.py in __call__(self, element, **kwargs)
    162         elif 'streams' not in kwargs:
    163             kwargs['streams'] = self.p.streams
--> 164         return element.apply(self, **kwargs)
    165 
    166 

~\AppData\Local\Continuum\anaconda3\lib\site-packages\holoviews\core\accessors.py in __call__(self, function, streams, link_inputs, dynamic, **kwargs)
    108             if hasattr(function, 'dynamic'):
    109                 inner_kwargs['dynamic'] = False
--> 110             return function(self._obj, **inner_kwargs)
    111         elif self._obj._deep_indexable:
    112             mapped = []

~\AppData\Local\Continuum\anaconda3\lib\site-packages\holoviews\core\operation.py in __call__(self, element, **kwargs)
    159                                       for k, el in element.items()])
    160             elif isinstance(element, ViewableElement):
--> 161                 return self._apply(element)
    162         elif 'streams' not in kwargs:
    163             kwargs['streams'] = self.p.streams

~\AppData\Local\Continuum\anaconda3\lib\site-packages\holoviews\core\operation.py in _apply(self, element, key)
    119         for hook in self._preprocess_hooks:
    120             kwargs.update(hook(self, element))
--> 121         ret = self._process(element, key)
    122         for hook in self._postprocess_hooks:
    123             ret = hook(self, ret, **kwargs)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\holoviews\element\graphs.py in _process(self, element, key)
    677             n_conn = weights_of_areas[i]
    678             p0, p1 = points[i], points[i+1]
--> 679             angles = np.linspace(p0, p1, n_conn)
    680             coords = list(zip(np.cos(angles), np.sin(angles)))
    681             all_areas.append(coords)

<__array_function__ internals> in linspace(*args, **kwargs)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
    119         raise TypeError(
    120             "object of type {} cannot be safely interpreted as an integer."
--> 121                 .format(type(num)))
    122 
    123     if num < 0:

TypeError: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer.

非常感谢任何帮助。

最佳

根据要求:

print((type(route_counts), type(nodes)))
print((route_counts.dtypes))

(<class 'pandas.core.frame.DataFrame'>, <class 'holoviews.core.data.Dataset'>)
SourceID         int64
DestinationID    int64
Stops            int64
dtype: object

包和版本:

holoviews                 1.12.7                     py_0    pyviz
pandas                    1.0.0            py37h47e9c7a_0
numpy                     1.18.1           py37h93ca92e_0
bokeh                     1.4.0                    py37_0

尝试了下载的笔记本,得到了同样的错误信息。

这是一个错误。处理 numpy 1.18.1 时出现问题。

我用 numpy 1.17.4 试过了,没有问题。
当我升级到 1.18.1 时,我也遇到了这个错误。

正如您在错误消息中看到的,错误是由 holoviews 中的这一行引起的:

angles = np.linspace(p0, p1, n_conn)


创建问题:
https://github.com/holoviz/holoviews/issues/4223

事实证明,已经有问题了:
https://github.com/holoviz/holoviews/issues/4209