Skip to content

Commit

Permalink
Fixed DataFrame widget datetime formatting (#1221)
Browse files Browse the repository at this point in the history
* Fixed DataFrame widget datetime formatting

* Add test
  • Loading branch information
philippjfr authored Apr 2, 2020
1 parent 8d02f5a commit ab58d4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 15 additions & 1 deletion panel/tests/widgets/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

try:
import pandas as pd
from pandas.util.testing import makeTimeDataFrame
except ImportError:
pytestmark = pytest.mark.skip('pandas not available')

from bokeh.models.widgets.tables import (
NumberFormatter, IntEditor, NumberEditor, StringFormatter,
SelectEditor
SelectEditor, DateFormatter, DateEditor
)

from panel.widgets import DataFrame
Expand Down Expand Up @@ -40,6 +41,19 @@ def test_dataframe_widget(dataframe, document, comm):
assert isinstance(float_col.editor, NumberEditor)


def test_dataframe_widget_datetimes(document, comm):

table = DataFrame(makeTimeDataFrame())

model = table.get_root(document, comm)

dt_col, _, _, _, _ = model.columns

assert dt_col.title == 'index'
assert isinstance(dt_col.formatter, DateFormatter)
assert isinstance(dt_col.editor, DateEditor)


def test_dataframe_editors(dataframe, document, comm):
editor = SelectEditor(options=['A', 'B', 'C'])
table = DataFrame(dataframe, editors={'str': editor})
Expand Down
3 changes: 2 additions & 1 deletion panel/widgets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ def _get_columns(self):
elif kind == 'f':
formatter = NumberFormatter(format='0,0.0[00000]')
editor = NumberEditor()
elif isdatetime(data):
elif isdatetime(data) or kind == 'M':
formatter = DateFormatter(format='%Y-%m-%d %H:%M:%S')
editor = DateEditor()
else:
formatter = StringFormatter()
editor = StringEditor()

if col in self.editors:
editor = self.editors[col]
if col in self.formatters:
Expand Down

0 comments on commit ab58d4b

Please sign in to comment.