TypeError when using Datashade

Hi, I try to use Datashade in a project, but I get an error as soon as I use Datashade.
I’ve try to get to basic with this tutorial : http://holoviews.org/user_guide/Large_Data.html but I get the error as soon I run a cell with datashade.

Do I miss something somewhere ?

The error is (the error is better display on my stackoverflow post https://stackoverflow.com/questions/62310437/typeerror-cannot-cast-array-data-from-dtypeint64-to-dtypeint32-accordin ):

WARNING:param.dynamic_operation: Callable raised "TypeError("Cannot cast array data from dtype('int64') to dtype('int32') according to the rule 'safe'")".
Invoked as dynamic_operation(height=400, scale=1.0, width=400, x_range=None, y_range=None)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj, include, exclude)
    968 
    969             if method is not None:
--> 970                 return method(include=include, exclude=exclude)
    971             return None
    972         else:

~\Anaconda3\lib\site-packages\holoviews\core\dimension.py in _repr_mimebundle_(self, include, exclude)
   1310         combined and returned.
   1311         """
-> 1312         return Store.render(self)
   1313 
   1314 

~\Anaconda3\lib\site-packages\holoviews\core\options.py in render(cls, obj)
   1393         data, metadata = {}, {}
   1394         for hook in hooks:
-> 1395             ret = hook(obj)
   1396             if ret is None:
   1397                 continue

~\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in pprint_display(obj)
    280     if not ip.display_formatter.formatters['text/plain'].pprint:
    281         return None
--> 282     return display(obj, raw_output=True)
    283 
    284 

~\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in display(obj, raw_output, **kwargs)
    253     elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
    254         with option_state(obj):
--> 255             output = layout_display(obj)
    256     elif isinstance(obj, (HoloMap, DynamicMap)):
    257         with option_state(obj):

~\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in wrapped(element)
    144         try:
    145             max_frames = OutputSettings.options['max_frames']
--> 146             mimebundle = fn(element, max_frames=max_frames)
    147             if mimebundle is None:
    148                 return {}, {}

~\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in layout_display(layout, max_frames)
    218         return None
    219 
--> 220     return render(layout)
    221 
    222 

~\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in render(obj, **kwargs)
     66         renderer = renderer.instance(fig='png')
     67 
---> 68     return renderer.components(obj, **kwargs)
     69 
     70 

~\Anaconda3\lib\site-packages\holoviews\plotting\renderer.py in components(self, obj, fmt, comm, **kwargs)
    386                 doc = Document()
    387                 with config.set(embed=embed):
--> 388                     model = plot.layout._render_model(doc, comm)
    389                 if embed:
    390                     return render_model(model, comm)

~\Anaconda3\lib\site-packages\panel\viewable.py in _render_model(self, doc, comm)
    415         if comm is None:
    416             comm = state._comm_manager.get_server_comm()
--> 417         model = self.get_root(doc, comm)
    418 
    419         if config.embed:

~\Anaconda3\lib\site-packages\panel\viewable.py in get_root(self, doc, comm)
    640         """
    641         doc = doc or _curdoc()
--> 642         root = self._get_model(doc, comm=comm)
    643         self._preprocess(root)
    644         ref = root.ref['id']

~\Anaconda3\lib\site-packages\panel\layout.py in _get_model(self, doc, root, parent, comm)
    118         if root is None:
    119             root = model
--> 120         objects = self._get_objects(model, [], doc, root, comm)
    121         props = dict(self._init_properties(), objects=objects)
    122         model.update(**self._process_param_change(props))

~\Anaconda3\lib\site-packages\panel\layout.py in _get_objects(self, model, old_objects, doc, root, comm)
    108             else:
    109                 try:
--> 110                     child = pane._get_model(doc, root, model, comm)
    111                 except RerenderError:
    112                     return self._get_objects(model, current_objects[:i], doc, root, comm)

~\Anaconda3\lib\site-packages\panel\pane\holoviews.py in _get_model(self, doc, root, parent, comm)
    225             plot = self.object
    226         else:
--> 227             plot = self._render(doc, comm, root)
    228 
    229         plot.pane = self

~\Anaconda3\lib\site-packages\panel\pane\holoviews.py in _render(self, doc, comm, root)
    284             kwargs = {}
    285 
--> 286         return renderer.get_plot(self.object, **kwargs)
    287 
    288     def _cleanup(self, root):

~\Anaconda3\lib\site-packages\holoviews\plotting\bokeh\renderer.py in get_plot(self_or_cls, obj, doc, renderer, **kwargs)
     71         combining the bokeh model with another plot.
     72         """
---> 73         plot = super(BokehRenderer, self_or_cls).get_plot(obj, doc, renderer, **kwargs)
     74         if plot.document is None:
     75             plot.document = Document() if self_or_cls.notebook_context else curdoc()

~\Anaconda3\lib\site-packages\holoviews\plotting\renderer.py in get_plot(self_or_cls, obj, doc, renderer, comm, **kwargs)
    214 
    215         # Initialize DynamicMaps with first data item
--> 216         initialize_dynamic(obj)
    217 
    218         if not renderer:

~\Anaconda3\lib\site-packages\holoviews\plotting\util.py in initialize_dynamic(obj)
    249             continue
    250         if not len(dmap):
--> 251             dmap[dmap._initial_key()]
    252 
    253 

~\Anaconda3\lib\site-packages\holoviews\core\spaces.py in __getitem__(self, key)
   1285         # Not a cross product and nothing cached so compute element.
   1286         if cache is not None: return cache
-> 1287         val = self._execute_callback(*tuple_key)
   1288         if data_slice:
   1289             val = self._dataslice(val, data_slice)

~\Anaconda3\lib\site-packages\holoviews\core\spaces.py in _execute_callback(self, *args)
   1059 
   1060         with dynamicmap_memoization(self.callback, self.streams):
-> 1061             retval = self.callback(*args, **kwargs)
   1062         return self._style(retval)
   1063 

~\Anaconda3\lib\site-packages\holoviews\core\spaces.py in __call__(self, *args, **kwargs)
    693 
    694         try:
--> 695             ret = self.callable(*args, **kwargs)
    696         except KeyError:
    697             # KeyError is caught separately because it is used to signal

~\Anaconda3\lib\site-packages\holoviews\util\__init__.py in dynamic_operation(*key, **kwargs)
   1008         def dynamic_operation(*key, **kwargs):
   1009             key, obj = resolve(key, kwargs)
-> 1010             return apply(obj, *key, **kwargs)
   1011 
   1012         operation = self.p.operation

~\Anaconda3\lib\site-packages\holoviews\util\__init__.py in apply(element, *key, **kwargs)
   1000         def apply(element, *key, **kwargs):
   1001             kwargs = dict(util.resolve_dependent_kwargs(self.p.kwargs), **kwargs)
-> 1002             processed = self._process(element, key, kwargs)
   1003             if (self.p.link_dataset and isinstance(element, Dataset) and
   1004                 isinstance(processed, Dataset) and processed._dataset is None):

~\Anaconda3\lib\site-packages\holoviews\util\__init__.py in _process(self, element, key, kwargs)
    982         elif isinstance(self.p.operation, Operation):
    983             kwargs = {k: v for k, v in kwargs.items() if k in self.p.operation.param}
--> 984             return self.p.operation.process_element(element, key, **kwargs)
    985         else:
    986             return self.p.operation(element, **kwargs)

~\Anaconda3\lib\site-packages\holoviews\core\operation.py in process_element(self, element, key, **params)
    172             self.p = param.ParamOverrides(self, params,
    173                                           allow_extra_keywords=self._allow_extra_keywords)
--> 174         return self._apply(element, key)
    175 
    176 

~\Anaconda3\lib\site-packages\holoviews\core\operation.py in _apply(self, element, key)
    130 
    131         element_pipeline = getattr(element, '_pipeline', None)
--> 132         ret = self._process(element, key)
    133 
    134         for hook in self._postprocess_hooks:

~\Anaconda3\lib\site-packages\holoviews\operation\datashader.py in _process(self, element, key)
   1443     def _process(self, element, key=None):
   1444         agg = rasterize._process(self, element, key)
-> 1445         shaded = shade._process(self, agg, key)
   1446         return shaded
   1447 

~\Anaconda3\lib\site-packages\holoviews\operation\datashader.py in _process(self, element, key)
   1275                 return RGB(img, **params)
   1276             else:
-> 1277                 img = tf.shade(array, **shade_opts)
   1278         return RGB(self.uint32_to_uint8_xr(img), **params)
   1279 

~\Anaconda3\lib\site-packages\datashader\transfer_functions\__init__.py in shade(agg, cmap, color_key, how, alpha, min_alpha, span, name, color_baseline)
    509 
    510     if agg.ndim == 2:
--> 511         return _interpolate(agg, cmap, how, alpha, span, min_alpha, name)
    512     elif agg.ndim == 3:
    513         return _colorize(agg, color_key, how, alpha, span, min_alpha, name, color_baseline)

~\Anaconda3\lib\site-packages\datashader\transfer_functions\__init__.py in _interpolate(agg, cmap, how, alpha, span, min_alpha, name)
    240     with np.errstate(invalid="ignore", divide="ignore"):
    241         # Transform data (log, eq_hist, etc.)
--> 242         data = interpolater(data, mask)
    243 
    244         # Transform span

~\Anaconda3\lib\site-packages\datashader\transfer_functions\__init__.py in eq_hist(data, mask, nbins)
    171         if data2.dtype.kind == 'u':
    172              data2 = data2.astype('i8')
--> 173         hist = np.bincount(data2.ravel())
    174         bin_centers = np.arange(len(hist))
    175         idx = int(np.nonzero(hist)[0][0])

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

TypeError: Cannot cast array data from dtype('int64') to dtype('int32') according to the rule 'safe'

Hi @axirr168,

I got very similar error when I used datashader functionality in conjunction with python 3.8 on a windows system, after digging around I saw on the pip site up to python 3.7 was supported so I attempted a downgrade and this error went away.

If you have python 3.8+ it’s probably a compatibility issue like I ran into, hope of some help.

Thanks, Carl.

Hi @carl,
Thanks alot for your answer. I’ll try to downgrade to see if it help.