Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabulator selection with pd.MultiIndex is not working in Panel 1.5.1 #7333

Closed
hoxbro opened this issue Sep 27, 2024 · 0 comments · Fixed by #7336
Closed

Tabulator selection with pd.MultiIndex is not working in Panel 1.5.1 #7333

hoxbro opened this issue Sep 27, 2024 · 0 comments · Fixed by #7336
Labels
component: tabulator Related to the Tabulator widget type: bug Something isn't correct or isn't working

Comments

@hoxbro
Copy link
Member

hoxbro commented Sep 27, 2024

Worked in Panel 1.5, Without doing a git bisect likely it is #7304

Two examples:

import panel as pn
import pandas as pd

pn.extension("tabulator")

index = pd.MultiIndex.from_tuples([(i, j) for i in range(10) for j in range(10)], names=["A", "B"])
df = pd.DataFrame(index=index, data={"C": range(100)})

w = pn.widgets.Tabulator(df, pagination="remote")
w.on_click(lambda x: print(x))
w.servable()
Traceback
message: Message 'PATCH-DOC' content: {'events': [{'kind': 'MessageSent', 'msg_type': 'bokeh_event', 'msg_data': {'type': 'event', 'name': 'cell-click', 'values': {'type': 'map', 'entries': [['model', {'id': 'p1220'}], ['column', 'B'], ['row', 9]]}}}]}
 error: ValueError('The Tabulator widget expects the provided `value` Pandas DataFrame to have unique indexes, in particular when it has to deal with click or edit events. Found this duplicate index: 9')
Traceback (most recent call last):
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/server/protocol_handler.py", line 94, in handle
    work = await handler(message, connection)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/server/session.py", line 94, in _needs_document_lock_wrapper
    result = func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/server/session.py", line 286, in _handle_patch
    message.apply_to_document(self.document, self)
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/protocol/messages/patch_doc.py", line 104, in apply_to_document
    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.payload, setter=setter))
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/document/callbacks.py", line 453, in invoke_with_curdoc
    return f()
           ^^^
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/protocol/messages/patch_doc.py", line 104, in <lambda>
    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.payload, setter=setter))
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/document/document.py", line 391, in apply_json_patch
    DocumentPatchedEvent.handle_event(self, event, setter)
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/document/events.py", line 244, in handle_event
    event_cls._handle_event(doc, event)
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/document/events.py", line 279, in _handle_event
    cb(event.msg_data)
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/document/callbacks.py", line 400, in trigger_event
    model._trigger_event(event)
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/util/callback_manager.py", line 111, in _trigger_event
    self.document.callbacks.notify_event(cast(Model, self), event, invoke)
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/document/callbacks.py", line 262, in notify_event
    invoke_with_curdoc(doc, callback_invoker)
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/document/callbacks.py", line 453, in invoke_with_curdoc
    return f()
           ^^^
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.12/site-packages/bokeh/util/callback_manager.py", line 107, in invoke
    cast(EventCallbackWithEvent, callback)(event)
  File "/home/shh/projects/holoviz/repos/panel/panel/reactive.py", line 572, in _server_event
    self._comm_event(doc, event)
  File "/home/shh/projects/holoviz/repos/panel/panel/reactive.py", line 559, in _comm_event
    state._handle_exception(e)
  File "/home/shh/projects/holoviz/repos/panel/panel/io/state.py", line 468, in _handle_exception
    raise exception
  File "/home/shh/projects/holoviz/repos/panel/panel/reactive.py", line 557, in _comm_event
    self._process_bokeh_event(doc, event)
  File "/home/shh/projects/holoviz/repos/panel/panel/reactive.py", line 494, in _process_bokeh_event
    self._process_event(event)
  File "/home/shh/projects/holoviz/repos/panel/panel/widgets/tables.py", line 1343, in _process_event
    self._validate_iloc(idx, iloc)
  File "/home/shh/projects/holoviz/repos/panel/panel/widgets/tables.py", line 1300, in _validate_iloc
    raise ValueError(
ValueError: The Tabulator widget expects the provided `value` Pandas DataFrame to have unique indexes, in particular when it has to deal with click or edit events. Found this duplicate index: 9
import panel as pn
import pandas as pd

pn.extension("tabulator")

index = pd.MultiIndex.from_tuples([(i, j) for i in range(10) for j in range(10)], names=["A", "B"])
df = pd.DataFrame(index=index, data={"C": range(100)})

w = pn.widgets.Tabulator(df, pagination="remote", selectable='checkbox')
w.servable()

b = pn.widgets.Button(name='Print selected rows', on_click=lambda x: print(w.selection))
b.servable()

Will just return an empty list

@hoxbro hoxbro added type: bug Something isn't correct or isn't working component: tabulator Related to the Tabulator widget labels Sep 27, 2024
@holoviz holoviz deleted a comment from holovizbot Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tabulator Related to the Tabulator widget type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant