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

Tabulator: confusion around the row value returned by `selection` and the click/edit events #7006

Open maximlt opened 4 months ago

maximlt commented 4 months ago

The Tabulator widget has a few attributes and events that refer to particular rows of the dataframe:

The two events, via their row attribute, and selection, indicate the integer-location of the row(s) relative to the original dataframe, i.e widget.value.

Users have reported sometimes being confused by the semantics of the returned row value (e.g. https://github.com/holoviz/panel/issues/6997):

I would also like to report a small UX issue with the events in particular, which return row and column that often leads me to incorrectly use df.loc[event.row, event.column] when I want to get a handle on the complete row. df.loc will only work if the dataframe has the default Pandas index, otherwise, it will error or, worse, return the wrong row (e.g. with a dataframe that's already be filtered in a preprocessing step). The right call to make is df.loc[df.index.get_loc(event.row), event.column], or alternatively df.iloc[event.row, df.columns.get_loc(event.column)].

image

philippjfr commented 4 months ago

I'd suggest we add the row index to the events to distinguish and then improve the documentation to be very clear that the .selection and the event row values are integer indexes into the original data.

philippjfr commented 4 months ago

Also let's make sure we add nicer docstrings to the CellClickEvent and TableEditEvent.