Skip to content

Commit

Permalink
Fixed bug in bokeh TablePlot not escaping dimensions correctly (#2336)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed Feb 13, 2018
1 parent 09e3905 commit 2fc8743
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
33 changes: 18 additions & 15 deletions holoviews/plotting/bokeh/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,23 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):
source = self._init_datasource(data)
self.handles['source'] = source

columns = self._get_columns(element, data)
style['reorderable'] = False
table = DataTable(source=source, columns=columns, height=self.height,
width=self.width, **style)
self.handles['plot'] = table
self.handles['glyph_renderer'] = table
self._execute_hooks(element)
self.drawn = True

for cb in self.callbacks:
cb.initialize()

return table

def _get_columns(self, element, data):
columns = []
dims = element.dimensions()
for d in dims:
for d in element.dimensions():
col = dimension_sanitizer(d.name)
kind = data[col].dtype.kind
if kind == 'i':
Expand All @@ -89,21 +103,10 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):
else:
formatter = StringFormatter()
editor = StringEditor()
column = TableColumn(field=d.name, title=d.pprint_label,
column = TableColumn(field=dimension_sanitizer(d.name), title=d.pprint_label,
editor=editor, formatter=formatter)
columns.append(column)
style['reorderable'] = False
table = DataTable(source=source, columns=columns, height=self.height,
width=self.width, **style)
self.handles['plot'] = table
self.handles['glyph_renderer'] = table
self._execute_hooks(element)
self.drawn = True

for cb in self.callbacks:
cb.initialize()

return table
return columns


def update_frame(self, key, ranges=None, plot=None):
Expand Down
7 changes: 7 additions & 0 deletions tests/plotting/bokeh/testtabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def test_table_plot(self):
self.assertIsInstance(column.formatter, fmt)
self.assertIsInstance(column.editor, edit)

def test_table_plot_escaped_dimension(self):
table = Table([1, 2, 3], ['A Dimension'])
plot = bokeh_renderer.get_plot(table)
source = plot.handles['source']
renderer = plot.handles['glyph_renderer']
self.assertEqual(list(source.data.keys())[0], renderer.columns[0].field)

def test_table_plot_datetimes(self):
table = Table([dt.now(), dt.now()], 'Date')
plot = bokeh_renderer.get_plot(table)
Expand Down

0 comments on commit 2fc8743

Please sign in to comment.