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 makes wrong selection when combined with a filter #2642

Closed
fogo5 opened this issue Aug 18, 2021 · 2 comments
Closed

Tabulator makes wrong selection when combined with a filter #2642

fogo5 opened this issue Aug 18, 2021 · 2 comments
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@fogo5
Copy link

fogo5 commented Aug 18, 2021

Description of expected behavior and the observed behavior

The tabulator widget makes the wrong selection when combined with a filter.

If the table get filted, the selected row is based on the row number selected and not the actual row selected. See screenshots.

The expected behavior: The filtered table, when selected should provide selection and selected_dataframe based on the shown filtered table.

Complete, minimal, self-contained example code that reproduces the issue

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


df = pd.DataFrame([['a', 'b', 'c', 'd', 'e'],[1,2,3,5,6]], index = ['name', 'num1']).T
table_widget = pn.widgets.Tabulator(df, disabled = True)
num1_slider = pn.widgets.IntRangeSlider(start=1, end=6, name='num1')
table_widget.add_filter(num1_slider, 'num1')
pn.Row(num1_slider, table_widget)


table_widget.selected_dataframe
table_widget.selection

Screenshots or screencasts of the bug in action

Working example with NO filtering:
Before filtering

After filtering, it no longer works:
After Filtering

Software version info

Mozilla Firefox - 91.0 (64-bit)
Google Chrome - Version 92.0.4515.131 (Official Build) (64-bit)

bokeh 2.3.3 py39h06a4308_0
conda 4.10.3 py39hf3d152e_0 conda-forge
ipykernel 6.1.0 py39hef51801_0 conda-forge
ipython 7.26.0 py39hef51801_0 conda-forge
jupyter_client 6.1.12 pyhd8ed1ab_0 conda-forge
jupyter_core 4.7.1 py39hf3d152e_0 conda-forge
jupyter_server 1.10.2 pyhd8ed1ab_0 conda-forge
jupyterlab 3.1.6 pyhd8ed1ab_0 conda-forge
jupyterlab_server 2.7.0 pyhd8ed1ab_0 conda-forge
numpy 1.20.3 py39hf144106_0
pandas 1.3.1 py39h8c16a72_0
panel 0.12.1 py_0 pyviz
param 1.11.1 py_0 pyviz
python 3.9.1 hdb3f193_2
tornado 6.1 py39h3811e60_1 conda-forge

@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label Aug 18, 2021
@philippjfr philippjfr added this to the 0.12.2 milestone Aug 18, 2021
@Stubatiger
Copy link
Contributor

Stubatiger commented Aug 23, 2021

Seems like that here

  @property
  def selected_dataframe(self):
      """
      Returns a DataFrame of the currently selected rows.
      """

      if not self.selection:
          return self.value
      return self.value.iloc[self.selection]

we select by value and not via the filtered dataframe.
I see several ways to fix that, but not sure what is the best way to go.

We could use the _filter_dataframe function

   self._filter_dataframe(self.value).iloc[self.selection]

but i guess computing that for every access seems too heavy

or we could use the underlying self._processed attribute which seems to hold the filtered dataframe from the self._get_data() function, but not sure if we are allowed to access that.

   self._processed.iloc[self.selection]

@philippjfr
Copy link
Member

I think the latter option (i.e. using self._processed) is the right fix.

philippjfr pushed a commit that referenced this issue Aug 29, 2021
#2676)

* correctly accessing the filtered dataframe for selection of tabulator #2642

* removing unused fixture
philippjfr pushed a commit that referenced this issue Sep 1, 2021
#2676)

* correctly accessing the filtered dataframe for selection of tabulator #2642

* removing unused fixture
maximlt added a commit that referenced this issue Sep 16, 2021
* Fix #2631 - handle RuntimeError: dictionary changed size during iteration (#2632)

* Fix #2631 - handle RuntimeError: dictionary changed size during iteration

* Update panel/reactive.py

Co-authored-by: Marc Skov Madsen <masma@orsted.dk>
Co-authored-by: Philipp Rudiger <prudiger@anaconda.com>

* Ensure tests pass in packaged version (#2636)

* Ensure tests pass in packaged version

* Update plotly test

* Add option to hide constant parameters (#2637)

* Add option to hide constant parameters

* Add test

* Add support for bokeh 2.4 (#2644)

* Ensure sessions get distinct files in config (#2646)

* Fix bug when updating Trend data (#2647)

* Enhance templates docs (#2658)

* clarifiy a sentence in the intro

* add a short definition for modal

* update the number of areas

* add links to template reference

* add an image of the 4 template areas

* add a modal section

* add link to the Golden framework

* clarify theming

* Added on_session_destroyed callback (#2659)

* Cleanup

* Ensure sorters are applied correctly after updating Tabulator value (#2639)

* Ensure sorters are applied correctly after updating Tabulator value

* Fix indents

* Add Folium reference notebook (#2672)

* add Folium reference

* clean up notebook

* Fix typo

* clear notebook

* Fix compatibility with bokeh 2.4 DocumentCallbackManager (#2687)

* Fix compatibility with bokeh 2.4 DocumentCallbackManager

* Fix flake

* correctly accessing the filtered dataframe for selection of tabulator… (#2676)

* correctly accessing the filtered dataframe for selection of tabulator #2642

* removing unused fixture

* Ensure threaded servers are killed after test failures (#2688)

* Unpin xarray

* Unescape child literal HTML in ReactiveHTML (#2690)

* Stricter validation for linking syntax in ReactiveHTML._template (#2689)

* Stricter validation for linking syntax in ReactiveHTML._template

* Add tests

* Update docs

* Clarify child templates

* fix-reloading (#2692)

Co-authored-by: Marc Skov Madsen <masma@orsted.dk>

* Ensure Trend indicator can be rendered in layout (#2694)

* Resolve remaining compatibility issues with bokeh 2.4 (#2696)

* resize plot when window resizes (#2704)

Co-authored-by: Marc Skov Madsen <masma@orsted.dk>

* Editable sliders' `name` can be changed (#2678)

* add tests for editable int and float sliders

* add failing tests when updating their name

* prevent the composite layout from using name

The Column/Row wrapping the composite widget inherited the name param
and watched it. This is no longer true, which allows the title of some
composite widgets to be updated.

* Switch binder links to latest version (#2705)

* fix-plotly-mapbox-relayout (#2717)

Co-authored-by: Marc Skov Madsen <masma@orsted.dk>

* Add the version number in the binder badge (#2711)

* Add the version number in the binder badge

Which should help us remember that the link has to be updated after a new release.

* Support assignment operators in ReactiveHTML scripts (#2718)

* Support assignment operators in ReactiveHTML scripts

* Add test

* Fix support for async functions on pn.state.add_periodic_callback (#2737)

* Upgrade to bokeh 2.4 and drop compatibility for older versions (#2739)

* Update changelog

* Fix rebase error

* Fix flake

* Bump panel.js version

* Fix rc version

* Update bokeh versions

Co-authored-by: Marc Skov Madsen <marc.skov.madsen@gmail.com>
Co-authored-by: Marc Skov Madsen <masma@orsted.dk>
Co-authored-by: Maxime Liquet <35924738+maximlt@users.noreply.github.com>
Co-authored-by: Nestor Ghenzi <46707985+nghenzi@users.noreply.github.com>
Co-authored-by: Simon <simonparlow@gmx.net>
Co-authored-by: maximlt <mliquet@anaconda.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

No branches or pull requests

3 participants