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

Patching fails with DataFrame that don't have a monotonic range #5554

Closed
maximlt opened this issue Sep 28, 2023 · 0 comments · Fixed by #5645
Closed

Patching fails with DataFrame that don't have a monotonic range #5554

maximlt opened this issue Sep 28, 2023 · 0 comments · Fixed by #5645
Labels
component: tabulator Related to the Tabulator widget type: bug Something isn't correct or isn't working

Comments

@maximlt
Copy link
Member

maximlt commented Sep 28, 2023

Patching a Tabulator widget with a DataFrame whose index isn't the usual monotonic integer 0, 1, 2, etc. isn't supported.

import numpy as np
import pandas as pd
import panel as pn

pn.extension('tabulator')

df = pd.DataFrame(
    index=[10, 50, 100],
    data=dict(
        A=list(range(3)),
        B=list('abc'),
))
w = pn.widgets.Tabulator(df)
w.patch(df)

Traceback:

ValueError                                Traceback (most recent call last)
Cell In[10], line 1
----> 1 w.patch(df)

File ~/dev/panel/panel/widgets/tables.py:796, in BaseTable.patch(self, patch_value, as_index)
    792 if isinstance(patch_value, pd.DataFrame):
    793     patch_value_dict = {
    794         column: list(patch_value[column].items()) for column in patch_value.columns
    795     }
--> 796     self.patch(patch_value_dict, as_index=as_index)
    797 elif isinstance(patch_value, pd.Series):
    798     if "index" in patch_value:  # Series orient is row

File ~/dev/panel/panel/widgets/tables.py:816, in BaseTable.patch(self, patch_value, as_index)
    814             else:
    815                 self.value.iloc[ind, columns.index(k)] = value
--> 816     self._patch(patch_value)
    817 else:
    818     raise ValueError(
    819         f"Patching with a patch_value of type {type(patch_value).__name__} "
    820         "is not supported. Please provide a DataFrame, Series or Dict."
    821     )

File ~/dev/panel/panel/util/__init__.py:380, in updating.<locals>.wrapped(self, *args, **kwargs)
    378 self._updating = True
    379 try:
--> 380     fn(self, *args, **kwargs)
    381 finally:
    382     self._updating = updating

File ~/dev/panel/panel/widgets/tables.py:1476, in Tabulator._patch(self, patch)
   1474 if not patch:
   1475     return
-> 1476 super()._patch(patch)
   1477 self._update_style()
   1478 self._update_selectable()

File ~/dev/panel/panel/util/__init__.py:380, in updating.<locals>.wrapped(self, *args, **kwargs)
    378 self._updating = True
    379 try:
--> 380     fn(self, *args, **kwargs)
    381 finally:
    382     self._updating = updating

File ~/dev/panel/panel/reactive.py:954, in SyncableData._patch(self, patch)
    952 if comm or not doc.session_context or state._unblocked(doc):
    953     with unlocked():
--> 954         m.source.patch(patch)
    955     if comm and 'embedded' not in root.tags:
    956         push(doc, comm)

File ~/miniconda3/envs/panel38/lib/python3.8/site-packages/bokeh/models/sources.py:681, in ColumnDataSource.patch(self, patches, setter)
    679 if isinstance(ind, int):
    680     if ind > col_len or ind < 0:
--> 681         raise ValueError("Out-of bounds index (%d) in patch for column: %s" % (ind, name))
    683 # slice index, patch multiple values of 1d column
    684 elif isinstance(ind, slice):

ValueError: Out-of bounds index (10) in patch for column: A
@maximlt maximlt added type: bug Something isn't correct or isn't working component: tabulator Related to the Tabulator widget labels Sep 28, 2023
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