Skip to content

Commit

Permalink
Fix bar with one value in it (#6301)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Jul 4, 2024
1 parent eb79ab5 commit 2bcd663
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion holoviews/plotting/bokeh/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions holoviews/tests/plotting/bokeh/test_barplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

0 comments on commit 2bcd663

Please sign in to comment.