Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bar with one value in it #6301

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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