holoviz / holoviz/hvplot

Error when not setting heatmap's C option

Open
#1,610 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.4k
Forks
124
Avg merge
1d 18h
Merged PRs (30d)
1

Description

`heatmap`'s docstring for the optional `C` option states that when not set a simple count will be used:

```
C : string, optional
Field to draw heatmap color from. If not specified a simple count will be used.
```

That doesn't seem to work, I get this error running the snippet below: `ValueError: NoneType type could not be interpreted as Dimension. Dimensions must be declared as a string, tuple, dictionary or Dimension type.`.

```python
import hvplot.pandas # noqa
import hvsampledata

df = hvsampledata.earthquakes("pandas")

df.hvplot.heatmap(x='mag_class', y='depth_class')
```

Full traceback

```
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[3], line 6
2 import hvsampledata
4 df = hvsampledata.earthquakes("pandas")
----> 6 df.hvplot.heatmap(x='mag_class', y='depth_class')

File [~/dev/hvplot/hvplot/plotting/core.py:865](http://localhost:8889/lab/workspaces/auto-F/tree/ref/api/manual/~/dev/hvplot/hvplot/plotting/core.py#line=864), in hvPlotTabular.heatmap(self, x, y, C, colorbar, logz, **kwds)
801 def heatmap(self, x=None, y=None, C=None, colorbar=True, logz=False, **kwds):
802 """
803 `heatmap` visualises tabular data indexed by two key dimensions as a grid of colored values.
804 This allows spotting correlations in multivariate data and provides a high-level overview
(...) 863 - Wiki: https://en.wikipedia.org/wiki/Heat_map
864 """
--> 865 return self(x, y, kind='heatmap', C=C, colorbar=colorbar, logz=logz, **kwds)

File [~/dev/hvplot/hvplot/plotting/core.py:95](http://localhost:8889/lab/workspaces/auto-F/tree/ref/api/manual/~/dev/hvplot/hvplot/plotting/core.py#line=94), in hvPlotBase.__call__(self, x, y, kind, **kwds)
92 plot = self._get_converter(x, y, kind, **kwds)(kind, x, y)
93 return pn.panel(plot, **panel_dict)
---> 95 return self._get_converter(x, y, kind, **kwds)(kind, x, y)

File [~/dev/hvplot/hvplot/converter.py:1925](http://localhost:8889/lab/workspaces/auto-F/tree/ref/api/manual/~/dev/hvplot/hvplot/converter.py#line=1924), in HoloViewsConverter.__call__(self, kind, x, y)
1922 dataset = Dataset(data)
1923 dataset = redim_(dataset, **self._redim)
-> 1925 obj = method(x, y)
1926 obj._dataset = dataset
1928 if self.crs and self.project:
1929 # Apply projection before rasterizing

File [~/dev/hvplot/hvplot/converter.py:2758](http://localhost:8889/lab/workspaces/auto-F/tree/ref/api/manual/~/dev/hvplot/hvplot/converter.py#line=2757), in HoloViewsConverter.heatmap(self, x, y, data)
2755 data, x, y = self._process_chart_args(data, x, y, single_y=True)
2757 redim = self._merge_redim({z[0]: self._dim_ranges['c']})
-> 2758 hmap = HeatMap(data, [x, y], z, **self._relabel)
2759 if 'reduce_function' in self.kwds:
2760 hmap = hmap.aggregate(function=self.kwds['reduce_function'])

File [~/dev/hvplot/.pixi/envs/default/lib/python3.12/site-packages/holoviews/element/raster.py:916](http://localhost:8889/lab/workspaces/auto-F/tree/ref/api/manual/~/dev/hvplot/.pixi/envs/default/lib/python3.12/site-packages/holoviews/element/raster.py#line=915), in HeatMap.__init__(self, data, kdims, vdims, **params)
915 def __init__(self, data, kdims=None, vdims=None, **params):
--> 916 super().__init__(data, kdims=kdims, vdims=vdims, **params)
917 self._gridded = None

File [~/dev/hvplot/.pixi/envs/default/lib/python3.12/site-packages/holoviews/element/selection.py:24](http://localhost:8889/lab/workspaces/auto-F/tree/ref/api/manual/~/dev/hvplot/.pixi/envs/default/lib/python3.12/site-packages/holoviews/element/selection.py#line=23), in SelectionIndexExpr.__init__(self, *args, **kwargs)
23 def __init__(self, *args, **kwargs):
---> 24 super().__init__(*args, **kwargs)
25 self._index_skip = False

File [~/dev/hvplot/.pixi/envs/default/lib/python3.12/site-packages/holoviews/core/data/__init__.py:330](http://localhost:8889/lab/workspaces/auto-F/tree/ref/api/manual/~/dev/hvplot/.pixi/envs/default/lib/python3.12/site-packages/holoviews/core/data/__init__.py#line=329), in Dataset.__init__(self, data, kdims, vdims, **kwargs)
327 if input_transforms is None:
328 input_transforms = data._transforms
--> 330 kwargs.update(process_dimensions(kdims, vdims))
331 kdims, vdims = kwargs.get('kdims'), kwargs.get('vdims')
333 validate_vdims = kwargs.pop('_validate_vdims', True)

File [~/dev/hvplot/.pixi/envs/default/lib/python3.12/site-packages/holoviews/core/dimension.py:125](http://localhost:8889/lab/workspaces/auto-F/tree/ref/api/manual/~/dev/hvplot/.pixi/envs/default/lib/python3.12/site-packages/holoviews/core/dimension.py#line=124), in process_dimensions(kdims, vdims)
118 elif not isinstance(dims, list):
119 raise ValueError(
120 f"{group} argument expects a Dimension or list of dimensions, "
121 "specified as tuples, strings, dictionaries or Dimension "
122 f"instances, not a {type(dims).__name__} type. "
123 "Ensure you passed the data as the first argument."
124 )
--> 125 dimensions[group] = [asdim(d) for d in dims]
126 return dimensions

File [~/dev/hvplot/.pixi/envs/default/lib/python3.12/site-packages/holoviews/core/dimension.py:65](http://localhost:8889/lab/workspaces/auto-F/tree/ref/api/manual/~/dev/hvplot/.pixi/envs/default/lib/python3.12/site-packages/holoviews/core/dimension.py#line=64), in asdim(dimension)
53 def asdim(dimension):
54 """Convert the input to a Dimension.
55
56 Parameters
(...) 63 copy is performed if the input is already a Dimension.
64 """
---> 65 return dimension if isinstance(dimension, Dimension) else Dimension(dimension)

File [~/dev/hvplot/.pixi/envs/default/lib/python3.12/site-packages/holoviews/core/dimension.py:276](http://localhost:8889/lab/workspaces/auto-F/tree/ref/api/manual/~/dev/hvplot/.pixi/envs/default/lib/python3.12/site-packages/holoviews/core/dimension.py#line=275), in Dimension.__init__(self, spec, **params)
272 raise ValueError(
273 'Dimension specified as a dict must contain a "name" key'
274 ) from exc
275 else:
--> 276 raise ValueError(
277 f'{type(spec).__name__} type could not be interpreted as Dimension. Dimensions must be '
278 'declared as a string, tuple, dictionary or Dimension type.'
279 )
280 all_params.update(params)
282 if not all_params['name']:

ValueError: NoneType type could not be interpreted as Dimension. Dimensions must be declared as a string, tuple, dictionary or Dimension type.
```


Somewhat related to https://github.com/holoviz/hvplot/issues/908

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.