From e4f92e3325d015d5d59f82d1ef3fb13f172cbfb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Fri, 28 Jun 2024 21:01:44 +0200 Subject: [PATCH 1/2] Update to work with one value bar --- holoviews/plotting/bokeh/chart.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/holoviews/plotting/bokeh/chart.py b/holoviews/plotting/bokeh/chart.py index 0bbd705ada..17ef699835 100644 --- a/holoviews/plotting/bokeh/chart.py +++ b/holoviews/plotting/bokeh/chart.py @@ -922,7 +922,8 @@ def get_data(self, element, ranges, style): is_dt = isdatetime(xvals) if is_dt or xvals.dtype.kind not in 'OU': xdiff = np.abs(np.diff(xvals)) - if len(np.unique(xdiff)) == 1 and xdiff[0] == 0: + diff_size = len(np.unique(xdiff)) + if diff_size == 0 or (diff_size == 1 and xdiff[0] == 0): xdiff = 1 if is_dt: width *= xdiff.astype('timedelta64[ms]').astype(np.int64) From 24f8da4bcb71d3c4fc38198e4897de69ba4c10e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Mon, 1 Jul 2024 10:13:18 +0200 Subject: [PATCH 2/2] Add unit tests --- holoviews/tests/plotting/bokeh/test_barplot.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/holoviews/tests/plotting/bokeh/test_barplot.py b/holoviews/tests/plotting/bokeh/test_barplot.py index fd16dbd7bb..46345442f3 100644 --- a/holoviews/tests/plotting/bokeh/test_barplot.py +++ b/holoviews/tests/plotting/bokeh/test_barplot.py @@ -37,6 +37,14 @@ def test_empty_bars(self): for v in source.data.values(): self.assertEqual(len(v), 0) + def test_bars_single_value(self): + df = pd.DataFrame({"time": [1], "value": [-1]}) + bars = Bars(df) + plot = bokeh_renderer.get_plot(bars) + source = plot.handles['source'] + assert source.data['time'], np.array([1]) + assert source.data['value'], np.array([-1]) + def test_bars_grouped_categories(self): bars = Bars([('A', 0, 1), ('A', 1, -1), ('B', 0, 2)], kdims=['Index', 'Category'], vdims=['Value'])