Skip to content

Commit

Permalink
Fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Nov 17, 2023
1 parent c6c6c61 commit fbc81e8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
6 changes: 3 additions & 3 deletions panel/tests/widgets/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,12 +1406,12 @@ def test_tabulator_paginated_sorted_selection(document, comm):
table._process_events({'indices': [0, 1]})
assert table.selection == [4, 3]

table._process_events({'indices': [1]})
assert table.selection == [3]
table._process_events({'indices': [2]})
assert table.selection == [4, 3, 2]

table.sorters = [{'field': 'A', 'sorter': 'number', 'dir': 'asc'}]
table._process_events({'indices': [1]})
assert table.selection == [1]
assert table.selection == [4, 3, 2, 1]


def test_tabulator_stream_dataframe(document, comm):
Expand Down
35 changes: 21 additions & 14 deletions panel/widgets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,21 +294,21 @@ def _update_index_mapping(self):

@updating
def _update_cds(self, *events: param.parameterized.Event):
# old_processed = self._processed
old_processed = self._processed
self._processed, data = self._get_data()
self._update_index_mapping()
# If there is a selection we have to compute new index
# if self.selection and old_processed is not None:
# indexes = list(self._processed.index)
# selection = []
# for sel in self.selection:
# try:
# iv = old_processed.index[sel]
# idx = indexes.index(iv)
# selection.append(idx)
# except Exception:
# continue
# self.selection = selection
if self.selection and old_processed is not None and self.pagination != 'remote':
indexes = list(self._processed.index)
selection = []
for sel in self.selection:
try:
iv = old_processed.index[sel]
idx = indexes.index(iv)
selection.append(idx)
except Exception:
continue
self.selection = selection
self._data = {k: _convert_datetime_array_ignore_list(v) for k, v in data.items()}
msg = {'data': self._data}
for ref, (m, _) in self._models.items():
Expand Down Expand Up @@ -1605,17 +1605,24 @@ def _update_selection(self, indices: List[int] | SelectionEvent):
if self.pagination != 'remote':
self.selection = indices
return
if isinstance(indices, list):
selected = True
else:
# Selection event
selected = indices.selected
indices = [indices.index]

nrows = self.page_size
start = (self.page-1)*nrows
index = self._processed.iloc[[start+indices.index]].index
index = self._processed.iloc[[start+ind for ind in indices]].index
ilocs = self.selection
for v in index.values:
try:
iloc = self.value.index.get_loc(v)
self._validate_iloc(v, iloc)
except KeyError:
continue
if indices.selected:
if selected:
ilocs.append(iloc)
else:
ilocs.remove(iloc)
Expand Down

0 comments on commit fbc81e8

Please sign in to comment.