holoviews
holoviews copied to clipboard
Curve steps interpolation on string-valued/categorical kdims is not possible
trafficstars
Software version info
- OS: Ubuntu 20.04.4 LTS x86_64
- environment: miniconda3-4.7.12
- Python: 3.9.7 - holoviews: 1.14.8 - bokeh: 2.4.1 - pandas: 1.4.2
- environment: miniconda3-4.7.12
Description of expected behavior and the observed behavior
While plotting a curve with a string or categorical independent variable is possible, as shown in the user guide,
the render fails when using the 'steps' interpolation modes.
The error seems to be the same for string and categorical types,
and the error is either a TypeError when using 'steps-mid' interpolation mode
or a ValueError when using 'steps-pre' or 'steps-post' modes.
Complete, minimal, self-contained example code that reproduces the issue
"""With string kdim."""
import pandas as pd
import holoviews as hv
hv.extension('bokeh')
df = pd.DataFrame.from_dict({'int': [1, 2], 'string': ['a', 'b']})
curve = hv.Curve(df, 'string', 'int')
curve.opts(interpolation='steps-mid')
hv.render(curve)
"""With categorical kdim. Behaves the same as string kdims."""
import pandas as pd
import holoviews as hv
hv.extension('bokeh')
df = pd.DataFrame.from_dict({'int': [1, 2], 'string': ['a', 'b']})
df['string'] = df['string'].astype('category')
curve = hv.Curve(df, 'string', 'int')
curve.opts(interpolation='steps-mid')
hv.render(curve)
"""With 'steps-pre' instead of 'steps-mid', gives a different error."""
import pandas as pd
import holoviews as hv
hv.extension('bokeh')
df = pd.DataFrame.from_dict({'int': [1, 2], 'string': ['a', 'b']})
curve = hv.Curve(df, 'string', 'int')
curve.opts(interpolation='steps-pre')
hv.render(curve)
Stack tracebacks
'steps-mid' interpolation
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/util/__init__.py", line 857, in render
plot = renderer_obj.get_plot(obj)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/plotting/bokeh/renderer.py", line 73, in get_plot
plot = super(BokehRenderer, self_or_cls).get_plot(obj, doc, renderer, **kwargs)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/plotting/renderer.py", line 243, in get_plot
plot.update(init_key)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/plotting/plot.py", line 991, in update
return self.initialize_plot()
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/plotting/bokeh/element.py", line 1418, in initialize_plot
self._init_glyphs(plot, element, ranges, source)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/plotting/bokeh/element.py", line 1362, in _init_glyphs
data, mapping, style = self.get_data(element, ranges, style)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/plotting/bokeh/chart.py", line 363, in get_data
element = interpolate_curve(element, interpolation=self.interpolation)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/param/parameterized.py", line 3652, in __new__
return inst.__call__(*args,**params)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/operation.py", line 220, in __call__
return element.apply(self, **kwargs)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/accessors.py", line 47, in pipelined_call
result = __call__(*args, **kwargs)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/accessors.py", line 204, in __call__
new_obj = apply_function(self._obj, **inner_kwargs)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/operation.py", line 214, in __call__
return self._apply(element)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/operation.py", line 141, in _apply
ret = self._process(element, key)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/operation/element.py", line 988, in _process
return element.map(self._process_layer, Element)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/data/__init__.py", line 207, in pipelined_fn
result = method_fn(*args, **kwargs)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/data/__init__.py", line 1223, in map
return super(Dataset, self).map(*args, **kwargs)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/dimension.py", line 710, in map
return map_fn(self) if applies else self
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/operation/element.py", line 982, in _process_layer
xs, dvals = INTERPOLATE_FUNCS[self.p.interpolation](x, dvals)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/operation/element.py", line 943, in pts_to_midstep
steps[1:-1:2] = steps[2::2] = x[:-1] + (x[1:] - x[:-1])/2
TypeError: unsupported operand type(s) for -: 'str' and 'str'
'steps-pre' interpolation (same error as 'step-post')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/util/__init__.py", line 857, in render
plot = renderer_obj.get_plot(obj)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/plotting/bokeh/renderer.py", line 73, in get_plot
plot = super(BokehRenderer, self_or_cls).get_plot(obj, doc, renderer, **kwargs)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/plotting/renderer.py", line 243, in get_plot
plot.update(init_key)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/plotting/plot.py", line 991, in update
return self.initialize_plot()
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/plotting/bokeh/element.py", line 1418, in initialize_plot
self._init_glyphs(plot, element, ranges, source)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/plotting/bokeh/element.py", line 1362, in _init_glyphs
data, mapping, style = self.get_data(element, ranges, style)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/plotting/bokeh/chart.py", line 363, in get_data
element = interpolate_curve(element, interpolation=self.interpolation)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/param/parameterized.py", line 3652, in __new__
return inst.__call__(*args,**params)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/operation.py", line 220, in __call__
return element.apply(self, **kwargs)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/accessors.py", line 47, in pipelined_call
result = __call__(*args, **kwargs)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/accessors.py", line 204, in __call__
new_obj = apply_function(self._obj, **inner_kwargs)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/operation.py", line 214, in __call__
return self._apply(element)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/operation.py", line 141, in _apply
ret = self._process(element, key)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/operation/element.py", line 988, in _process
return element.map(self._process_layer, Element)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/data/__init__.py", line 207, in pipelined_fn
result = method_fn(*args, **kwargs)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/data/__init__.py", line 1223, in map
return super(Dataset, self).map(*args, **kwargs)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/core/dimension.py", line 710, in map
return map_fn(self) if applies else self
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/operation/element.py", line 982, in _process_layer
xs, dvals = INTERPOLATE_FUNCS[self.p.interpolation](x, dvals)
File "/home/REDACTED/.pyenv/versions/miniconda3-4.7.12/envs/REDACTED/lib/python3.9/site-packages/holoviews/operation/element.py", line 927, in pts_to_prestep
steps[0::2] = x
ValueError: could not convert string to float: 'a'