-
-
Notifications
You must be signed in to change notification settings - Fork 526
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
selected_dataframe
is linked to the current_view
#3670
Comments
I think I just run into this because File [~/mambaforge/envs/lcms_polymer_env/lib/python3.11/site-packages/panel/widgets/tables.py:839](https://file+.vscode-resource.vscode-cdn.net/home/peter/workspace/lcms_polymer_model/notebooks/peter/aspect_platform/apps/~/mambaforge/envs/lcms_polymer_env/lib/python3.11/site-packages/panel/widgets/tables.py:839), in BaseTable.selected_dataframe(self)
837 if not self.selection:
838 return self.current_view.iloc[:0]
--> 839 return self.current_view.iloc[self.selection]
File [~/mambaforge/envs/lcms_polymer_env/lib/python3.11/site-packages/pandas/core/indexing.py:1073](https://file+.vscode-resource.vscode-cdn.net/home/peter/workspace/lcms_polymer_model/notebooks/peter/aspect_platform/apps/~/mambaforge/envs/lcms_polymer_env/lib/python3.11/site-packages/pandas/core/indexing.py:1073), in _LocationIndexer.__getitem__(self, key)
1070 axis = self.axis or 0
1072 maybe_callable = com.apply_if_callable(key, self.obj)
-> 1073 return self._getitem_axis(maybe_callable, axis=axis)
File [~/mambaforge/envs/lcms_polymer_env/lib/python3.11/site-packages/pandas/core/indexing.py:1616](https://file+.vscode-resource.vscode-cdn.net/home/peter/workspace/lcms_polymer_model/notebooks/peter/aspect_platform/apps/~/mambaforge/envs/lcms_polymer_env/lib/python3.11/site-packages/pandas/core/indexing.py:1616), in _iLocIndexer._getitem_axis(self, key, axis)
1614 # a list of integers
1615 elif is_list_like_indexer(key):
-> 1616 return self._get_list_axis(key, axis=axis)
1618 # a single integer
1619 else:
1620 key = item_from_zerodim(key)
File [~/mambaforge/envs/lcms_polymer_env/lib/python3.11/site-packages/pandas/core/indexing.py:1590](https://file+.vscode-resource.vscode-cdn.net/home/peter/workspace/lcms_polymer_model/notebooks/peter/aspect_platform/apps/~/mambaforge/envs/lcms_polymer_env/lib/python3.11/site-packages/pandas/core/indexing.py:1590), in _iLocIndexer._get_list_axis(self, key, axis)
1587 return self.obj._take_with_is_copy(key, axis=axis)
1588 except IndexError as err:
1589 # re-raise with different error message
-> 1590 raise IndexError("positional indexers are out-of-bounds") from err
IndexError: positional indexers are out-of-bounds |
To understand what happens you can play with the code below. import panel as pn
import pandas as pd
import random
from datetime import datetime, timedelta
pn.extension("tabulator", template="fast")
df = pd.DataFrame({
"x": [1,3,2],
"y": ["a", "b", "c"]
})
table = pn.widgets.Tabulator(df, sizing_mode="stretch_both", selectable='checkbox', height=300)
update = pn.widgets.Button(name="Update")
@pn.depends(update)
def result(event):
iloc = df.iloc[table.selection,:]
loc = df.loc[table.selection,:]
return pn.Row(
pn.Column("df", df),
pn.Column("table.current_view", table.current_view),
pn.Column("table.selection", table.selection),
pn.Column("selected_dataframe", table.selected_dataframe),
pn.Column("df.iloc", iloc),
pn.Column("df.loc", loc),
pn.Column("table.current_view.iloc", table.current_view.iloc[table.selection,:]),
pn.Column("table.current_view.loc", table.current_view.loc[table.selection,:]),
)
pn.Column(update, table, result).servable() As long as the user has not sorted Tabulator things works. But if we sort (on column x) things gets out of sync. I think was it not clearly documented is that At least for our use case using |
This happens when filtering is applied as well. Not just on sorting. So, the main problem is in the |
As discussed in #6997, the |
The
selected_dataframe
property is computed based on thecurrent_view
, which can return wrong data or raise an error if some filters are applied. I think theselected_dataframe
should not be linked to thecurrent_view
, it seems useful in a large table to be able to filter (and sort) and select rows at the same time.The text was updated successfully, but these errors were encountered: