holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.83k stars 519 forks source link

Error raised on edit events when a header filter is active #3660

Closed maximlt closed 4 months ago

maximlt commented 2 years ago

Execute the example below in a notebook, filter col1 by a and edit one of the rows in col2.

import pandas as pd
import panel as pn
pn.extension('tabulator')

df = pd.DataFrame({
    'col1': list('aaabcd'),
    'col2': list('ABCDEF')
})
header_filters = {
    'col1': {'type': 'input', 'func': 'like'}
}
widget = pn.widgets.Tabulator(
    df,
    header_filters=header_filters,
)
def cb(e):
    print(e)

widget.on_edit(cb)

Traceback:

Traceback (most recent call last):
  File "/Users/mliquet/miniconda3/envs/panel-dev38/lib/python3.8/site-packages/pyviz_comms/__init__.py", line 325, in _handle_msg
    self._on_msg(msg)
  File "/Users/mliquet/work/dev/panel/panel/viewable.py", line 292, in _on_msg
    doc.unhold()
  File "/Users/mliquet/miniconda3/envs/panel-dev38/lib/python3.8/site-packages/bokeh/document/document.py", line 799, in unhold
    self.callbacks.unhold()
  File "/Users/mliquet/miniconda3/envs/panel-dev38/lib/python3.8/site-packages/bokeh/document/callbacks.py", line 396, in unhold
    self.trigger_on_change(event)
  File "/Users/mliquet/miniconda3/envs/panel-dev38/lib/python3.8/site-packages/bokeh/document/callbacks.py", line 373, in trigger_on_change
    invoke_with_curdoc(doc, event.callback_invoker)
  File "/Users/mliquet/miniconda3/envs/panel-dev38/lib/python3.8/site-packages/bokeh/document/callbacks.py", line 408, in invoke_with_curdoc
    return f()
  File "/Users/mliquet/miniconda3/envs/panel-dev38/lib/python3.8/site-packages/bokeh/util/callback_manager.py", line 191, in invoke
    callback(attr, old, new)
  File "/Users/mliquet/work/dev/panel/panel/reactive.py", line 392, in _comm_change
    self._schedule_change(doc, comm)
  File "/Users/mliquet/work/dev/panel/panel/reactive.py", line 376, in _schedule_change
    self._change_event(doc)
  File "/Users/mliquet/work/dev/panel/panel/reactive.py", line 370, in _change_event
    self._process_events(events)
  File "/Users/mliquet/work/dev/panel/panel/reactive.py", line 1106, in _process_events
    self._process_data(events.pop('data'))
  File "/Users/mliquet/work/dev/panel/panel/reactive.py", line 1080, in _process_data
    self._update_column(col, values)
  File "/Users/mliquet/work/dev/panel/panel/widgets/tables.py", line 1339, in _update_column
    self.value.loc[index, column] = array
  File "/Users/mliquet/miniconda3/envs/panel-dev38/lib/python3.8/site-packages/pandas/core/indexing.py", line 723, in __setitem__
    iloc._setitem_with_indexer(indexer, value, self.name)
  File "/Users/mliquet/miniconda3/envs/panel-dev38/lib/python3.8/site-packages/pandas/core/indexing.py", line 1732, in _setitem_with_indexer
    self._setitem_single_block(indexer, value, name)
  File "/Users/mliquet/miniconda3/envs/panel-dev38/lib/python3.8/site-packages/pandas/core/indexing.py", line 1968, in _setitem_single_block
    self.obj._mgr = self.obj._mgr.setitem(indexer=indexer, value=value)
  File "/Users/mliquet/miniconda3/envs/panel-dev38/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 355, in setitem
    return self.apply("setitem", indexer=indexer, value=value)
  File "/Users/mliquet/miniconda3/envs/panel-dev38/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 327, in apply
    applied = getattr(b, f)(**kwargs)
  File "/Users/mliquet/miniconda3/envs/panel-dev38/lib/python3.8/site-packages/pandas/core/internals/blocks.py", line 983, in setitem
    values[indexer] = value
ValueError: shape mismatch: value array of shape (6,) could not be broadcast to indexing result of shape (3,)
philippjfr commented 4 months ago

Fixed!