Skip to content

Commit

Permalink
fix getting the column dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
maximlt committed Sep 15, 2022
1 parent 6b3c439 commit 723e9e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
20 changes: 10 additions & 10 deletions panel/tests/widgets/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def test_tabulator_multi_index(document, comm):
{'field': 'A'},
{'field': 'C'},
{'field': 'B'},
{'field': 'D'}
{'field': 'D', 'sorter': 'timestamp'}
]

assert np.array_equal(model.source.data['A'], np.array([0., 1., 2., 3., 4.]))
Expand All @@ -269,7 +269,7 @@ def test_tabulator_multi_index_remote_pagination(document, comm):
{'field': 'A'},
{'field': 'C'},
{'field': 'B'},
{'field': 'D'}
{'field': 'D', 'sorter': 'timestamp'}
]

assert np.array_equal(model.source.data['A'], np.array([0., 1., 2.]))
Expand Down Expand Up @@ -386,7 +386,7 @@ def test_tabulator_config_defaults(document, comm):
{'field': 'A'},
{'field': 'B'},
{'field': 'C'},
{'field': 'D'}
{'field': 'D', 'sorter': 'timestamp'}
]
assert model.configuration['selectable'] == True

Expand All @@ -401,7 +401,7 @@ def test_tabulator_config_widths_percent(document, comm):
{'field': 'A', 'width': '22%'},
{'field': 'B'},
{'field': 'C'},
{'field': 'D'}
{'field': 'D', 'sorter': 'timestamp'}
]
assert model.columns[2].width == 100

Expand All @@ -416,7 +416,7 @@ def test_tabulator_header_filters_config_boolean(document, comm):
{'field': 'A', 'headerFilter': True},
{'field': 'B', 'headerFilter': True},
{'field': 'C', 'headerFilter': True},
{'field': 'D', 'headerFilter': True}
{'field': 'D', 'headerFilter': True, 'sorter': 'timestamp'}
]

def test_tabulator_header_filters_column_config_list(document, comm):
Expand All @@ -430,7 +430,7 @@ def test_tabulator_header_filters_column_config_list(document, comm):
{'field': 'A'},
{'field': 'B'},
{'field': 'C', 'headerFilter': 'list', 'headerFilterParams': {'valuesLookup': True}},
{'field': 'D'}
{'field': 'D', 'sorter': 'timestamp'}
]
assert model.configuration['selectable'] == True

Expand All @@ -449,7 +449,7 @@ def test_tabulator_header_filters_column_config_select_autocomplete_backwards_co
{'field': 'A'},
{'field': 'B'},
{'field': 'C', 'headerFilter': 'list', 'headerFilterParams': {'valuesLookup': True}},
{'field': 'D', 'headerFilter': 'list', 'headerFilterParams': {'valuesLookup': True}},
{'field': 'D', 'headerFilter': 'list', 'headerFilterParams': {'valuesLookup': True}, 'sorter': 'timestamp'},
]
assert model.configuration['selectable'] == True

Expand All @@ -472,7 +472,7 @@ def test_tabulator_header_filters_column_config_dict(document, comm):
'headerFilterFunc': '!=',
'headerFilterPlaceholder': 'Not equal'
},
{'field': 'D'}
{'field': 'D', 'sorter': 'timestamp'}
]
assert model.configuration['selectable'] == True

Expand Down Expand Up @@ -582,7 +582,7 @@ def test_tabulator_groups(document, comm):
{'title': 'Other',
'columns': [
{'field': 'C'},
{'field': 'D'}
{'field': 'D', 'sorter': 'timestamp'}
]}
]

Expand Down Expand Up @@ -615,7 +615,7 @@ def test_tabulator_frozen_cols(document, comm):
{'field': 'A'},
{'field': 'B'},
{'field': 'C'},
{'field': 'D'}
{'field': 'D', 'sorter': 'timestamp'}
]


Expand Down
9 changes: 8 additions & 1 deletion panel/widgets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,14 @@ def _config_columns(self, column_objs: List[TableColumn]) -> List[Dict[str, Any]
formatter = dict(formatter)
col_dict['formatter'] = formatter.pop('type')
col_dict['formatterParams'] = formatter
dtype = getattr(self.value, column.field).dtype
col_name = self._renamed_cols[column.field]
if column.field in self.indexes:
if len(self.indexes) == 1:
dtype = self.value.index.dtype
else:
dtype = self.value.index.get_level_values(self.indexes.index(column.field)).dtype
else:
dtype = self.value.dtypes[col_name]
if dtype.kind == 'M':
col_dict['sorter'] = 'timestamp'
editor = self.editors.get(column.field)
Expand Down

0 comments on commit 723e9e0

Please sign in to comment.