holoviz / holoviz/hvplot

DataError: line plot fails when one of two columns is called value

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

Description

hvplot=0.8.1

I am working on improving the docstrings. I would like to use a simple and very understandable dataset for the examples. So I would like to call one of the columns `value`. But this does not work :-)

```python
import hvplot.pandas
import pandas as pd
from pandas import Timestamp as T
df = pd.DataFrame({
'value': [100, 150, 125, 140, 145],
'reference': [90, 153, 125, 139, 141],
'delta': [10, -3, 0, 1, 4],
'date': [T("2022-01-03"), T("2022-01-04"), T("2022-01-05"), T("2022-01-06"), T("2022-01-07")],
'string': ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
'numerical': [1.1, 1.9, 3.2, 3.8, 4.0],
},
)
df.hvplot.line(x="numerical", y=["value", "reference"])
```

```bash
---------------------------------------------------------------------------
DataError Traceback (most recent call last)
Input In [2], in ()
----> 1 df.hvplot.line(x="numerical", y=["value", "reference"])

File ~/repos/private/hvplot/hvplot/plotting/core.py:347, in hvPlotTabular.line(self, x, y, **kwds)
264 def line(self, x=None, y=None, **kwds):
265 """
266 The `line` plot connects the points with a continous curve.
267
(...)
345 - Wiki: https://en.wikipedia.org/wiki/Line_chart
346 """
--> 347 return self(x, y, kind="line", **kwds)

File ~/repos/private/hvplot/hvplot/plotting/core.py:133, in hvPlotBase.__call__(self, x, y, kind, **kwds)
130 plot = self._get_converter(x, y, kind, **kwds)(kind, x, y)
131 return pn.panel(plot, **panel_dict)
--> 133 return self._get_converter(x, y, kind, **kwds)(kind, x, y)

File ~/repos/private/hvplot/hvplot/converter.py:1228, in HoloViewsConverter.__call__(self, kind, x, y)
1226 dataset = Dataset(data)
1227 dataset = dataset.redim(**self._redim)
-> 1228 obj = method(x, y)
1229 obj._dataset = dataset
1231 if self.crs and self.project:
1232 # Apply projection before rasterizing

File ~/repos/private/hvplot/hvplot/converter.py:1633, in HoloViewsConverter.line(self, x, y, data)
1631 def line(self, x=None, y=None, data=None):
1632 self._error_if_unavailable('line')
-> 1633 return self.chart(Curve, x, y, data)

File ~/repos/private/hvplot/hvplot/converter.py:1624, in HoloViewsConverter.chart(self, element, x, y, data)
1622 for c in y:
1623 kdims, vdims = self._get_dimensions([x], [c])
-> 1624 chart = element(data, kdims, vdims).redim(**{c: self.value_label})
1625 charts.append((c, chart.relabel(**self._relabel)))
1626 return (self._by_type(charts, self.group_label, sort=False)
1627 .opts(cur_opts, backend='bokeh')
1628 .opts(compat_opts, backend=self._backend_compat))

File /opt/conda/lib/python3.9/site-packages/holoviews/core/accessors.py:47, in AccessorPipelineMeta.pipelined..pipelined_call(*args, **kwargs)
44 inst._obj._in_method = True
46 try:
---> 47 result = __call__(*args, **kwargs)
49 if not in_method:
50 init_op = factory.instance(
51 output_type=type(inst),
52 kwargs={'mode': getattr(inst, 'mode', None)},
53 )

File /opt/conda/lib/python3.9/site-packages/holoviews/core/accessors.py:430, in Redim.__call__(self, specs, **dimensions)
428 transform = self._create_expression_transform(kdims, vdims, list(renames.values()))
429 transforms = obj._transforms + [transform]
--> 430 clone = obj.clone(data, kdims=kdims, vdims=vdims, transforms=transforms)
431 if self._obj.dimensions(label='name') == clone.dimensions(label='name'):
432 # Ensure that plot_id is inherited as long as dimension
433 # name does not change
434 clone._plot_id = self._obj._plot_id

File /opt/conda/lib/python3.9/site-packages/holoviews/core/data/__init__.py:1211, in Dataset.clone(self, data, shared_data, new_type, link, *args, **overrides)
1208 elif self._in_method and 'dataset' not in overrides:
1209 overrides['dataset'] = self.dataset
-> 1211 return super(Dataset, self).clone(
1212 data, shared_data, new_type, *args, **overrides
1213 )

File /opt/conda/lib/python3.9/site-packages/holoviews/core/dimension.py:576, in LabelledData.clone(self, data, shared_data, new_type, link, *args, **overrides)
574 # Apply name mangling for __ attribute
575 pos_args = getattr(self, '_' + type(self).__name__ + '__pos_params', [])
--> 576 return clone_type(data, *args, **{k:v for k,v in settings.items()
577 if k not in pos_args})

File /opt/conda/lib/python3.9/site-packages/holoviews/element/selection.py:23, in SelectionIndexExpr.__init__(self, *args, **kwargs)
22 def __init__(self, *args, **kwargs):
---> 23 super(SelectionIndexExpr, self).__init__(*args, **kwargs)
24 self._index_skip = False

File /opt/conda/lib/python3.9/site-packages/holoviews/element/chart.py:52, in Chart.__init__(self, data, kdims, vdims, **params)
50 if len(params.get('kdims', [])) == self._max_kdim_count + 1:
51 self.param.warning('Chart elements should only be supplied a single kdim')
---> 52 super(Chart, self).__init__(data, **params)

File /opt/conda/lib/python3.9/site-packages/holoviews/core/data/__init__.py:341, in Dataset.__init__(self, data, kdims, vdims, **kwargs)
338 kdims, vdims = kwargs.get('kdims'), kwargs.get('vdims')
340 validate_vdims = kwargs.pop('_validate_vdims', True)
--> 341 initialized = Interface.initialize(type(self), data, kdims, vdims,
342 datatype=kwargs.get('datatype'))
343 (data, self.interface, dims, extra_kws) = initialized
344 super(Dataset, self).__init__(data, **dict(kwargs, **dict(dims, **extra_kws)))

File /opt/conda/lib/python3.9/site-packages/holoviews/core/data/interface.py:256, in Interface.initialize(cls, eltype, data, kdims, vdims, datatype)
254 continue
255 try:
--> 256 (data, dims, extra_kws) = interface.init(eltype, data, kdims, vdims)
257 break
258 except DataError:

File /opt/conda/lib/python3.9/site-packages/holoviews/core/data/pandas.py:86, in PandasInterface.init(cls, eltype, data, kdims, vdims)
84 d = dimension_name(d)
85 if len([c for c in data.columns if c == d]) > 1:
---> 86 raise DataError('Dimensions may not reference duplicated DataFrame '
87 'columns (found duplicate %r columns). If you want to plot '
88 'a column against itself simply declare two dimensions '
89 'with the same name. '% d, cls)
90 else:
91 # Check if data is of non-numeric type
92 # Then use defined data type
93 kdims = kdims if kdims else kdim_param.default

DataError: Dimensions may not reference duplicated DataFrame columns (found duplicate 'value' columns). If you want to plot a column against itself simply declare two dimensions with the same name.

PandasInterface expects tabular data, for more information on supported datatypes see http://holoviews.org/user_guide/Tabular_Datasets.html
```

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.