Skip to content

Conversation

@uellue
Copy link

@uellue uellue commented Oct 22, 2025

How to reproduce

# In a Notebook, for example
import panel as pn
import pandas as pd
pn.extension('tabulator')

columns = ['a', 'b']

df = pd.DataFrame([(1, 2)], columns=columns)
tab = pn.widgets.Tabulator(
    df,
    buttons={
        'delete': '<i class="fa fa-trash"></i>',
    }
)

def delete_row(table, row):
    df = table.value
    key = df.index[row]
    table.value = df.drop(key)
    

tab.on_click(
    lambda e: delete_row(tab, e.row) if e.column == 'delete' else None,
    column='delete'
)
tab

...and click on the delete button.

What happens

Traceback (most recent call last):
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/pandas/core/indexing.py", line 1714, in _get_list_axis
    return self.obj._take_with_is_copy(key, axis=axis)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/pandas/core/generic.py", line 4172, in _take_with_is_copy
    result = self.take(indices=indices, axis=axis)
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/pandas/core/generic.py", line 4152, in take
    new_data = self._mgr.take(
        indices,
        axis=self._get_block_manager_axis(axis),
        verify=True,
    )
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/pandas/core/internals/managers.py", line 891, in take
    indexer = maybe_convert_indices(indexer, n, verify=verify)
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/pandas/core/indexers/utils.py", line 282, in maybe_convert_indices
    raise IndexError("indices are out-of-bounds")
IndexError: indices are out-of-bounds

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/pyviz_comms/__init__.py", line 341, in _handle_msg
    self._on_msg(msg)
    ~~~~~~~~~~~~^^^^^
  File "/home/weber/src/panel/panel/viewable.py", line 500, in _on_msg
    doc.unhold()
    ~~~~~~~~~~^^
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/bokeh/document/document.py", line 791, in unhold
    self.callbacks.unhold()
    ~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/bokeh/document/callbacks.py", line 441, in unhold
    self.trigger_on_change(event)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/bokeh/document/callbacks.py", line 418, in trigger_on_change
    invoke_with_curdoc(doc, event.callback_invoker)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/bokeh/document/callbacks.py", line 453, in invoke_with_curdoc
    return f()
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/bokeh/util/callback_manager.py", line 174, in invoke
    callback(attr, old, new)
    ~~~~~~~~^^^^^^^^^^^^^^^^
  File "/home/weber/src/panel/panel/reactive.py", line 565, in _comm_change
    state._handle_exception(e)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^
  File "/home/weber/src/panel/panel/io/state.py", line 496, in _handle_exception
    raise exception
  File "/home/weber/src/panel/panel/reactive.py", line 563, in _comm_change
    self._schedule_change(doc, comm)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/home/weber/src/panel/panel/reactive.py", line 545, in _schedule_change
    self._change_event(doc)
    ~~~~~~~~~~~~~~~~~~^^^^^
  File "/home/weber/src/panel/panel/reactive.py", line 541, in _change_event
    self._process_events(events)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/home/weber/src/panel/panel/widgets/tables.py", line 1422, in _process_events
    return super()._process_events(events)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/home/weber/src/panel/panel/reactive.py", line 1463, in _process_events
    self._update_selection(events.pop('indices'))
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/weber/src/panel/panel/widgets/tables.py", line 1873, in _update_selection
    ilocs = self._map_indexes(inds, ilocs, add=selected)
  File "/home/weber/src/panel/panel/widgets/tables.py", line 1847, in _map_indexes
    index = self._processed.iloc[[start+ind for ind in indexes]].index
            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/pandas/core/indexing.py", line 1191, in __getitem__
    return self._getitem_axis(maybe_callable, axis=axis)
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/pandas/core/indexing.py", line 1743, in _getitem_axis
    return self._get_list_axis(key, axis=axis)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/home/weber/miniforge3/envs/calib313/lib/python3.13/site-packages/pandas/core/indexing.py", line 1717, in _get_list_axis
    raise IndexError("positional indexers are out-of-bounds") from err
IndexError: positional indexers are out-of-bounds

Analysis

For some reason a spurious selection update event with the previously selected row 0 is processed after the data frame has been emptied, resulting in an IndexError.

Quick fix

With the change in this PR an empty selection is created in case of an IndexError.

Discussion

I'm not sure if this is the proper way to fix this and how to test this. The error doesn't occur if the row is dropped outside of the event handler. My guess is that clicking also triggers the selection, and the selection is handled after the custom on_click()?

For some reason a spurious selection update event is
processed after the data frame has been emptied, resulting
in an IndexError.

With this change an empty selection is created in case
any of the selected indices are invalid.
@uellue
Copy link
Author

uellue commented Oct 22, 2025

By the way, the error doesn't occur if selectable=False.

@codecov
Copy link

codecov bot commented Oct 22, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.12%. Comparing base (8eb0b14) to head (b6f31af).

Files with missing lines Patch % Lines
panel/widgets/tables.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8256      +/-   ##
==========================================
- Coverage   70.12%   70.12%   -0.01%     
==========================================
  Files         347      347              
  Lines       54092    54095       +3     
==========================================
  Hits        37933    37933              
- Misses      16159    16162       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@uellue
Copy link
Author

uellue commented Oct 23, 2025

The test FAILED panel/tests/ui/widgets/test_tabulator.py::test_tabulator_patch_no_height_resize - TimeoutError: wait_until timed out in 5000 milliseconds fails locally for me for both main and this branch. It seems unrelated to this change?

@philippjfr
Copy link
Member

Thanks for the contribution. Will take a look at this tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants