holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.74k stars 516 forks source link

Tabulator header_filter with multiselect enabled: AttributeError #7110

Closed thuydotm closed 2 months ago

thuydotm commented 2 months ago

ALL software version info

panel 1.4.5

Description of expected behavior and the observed behavior

Enabling multiselect in header_filters caused AttributeError.

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

import pandas as pd
import panel as pn

df = pd.DataFrame({
    'value': ['a', 'b', 'c'],
})

df_widget = pn.widgets.Tabulator(
    df,
    header_filters={
        'value': {'type': 'list', 'values': ['a', 'b', 'c'], 'multiselect': True}
    },
)

df_widget.servable()

Stack traceback

2024-08-09 20:53:20,169 Exception in callback functools.partial(<bound method IOLoop._discard_future_result of <tornado.platform.asyncio.AsyncIOMainLoop object at 0x123f811f0>>, <Task finished name='Task-82' coro=<ServerSession.with_document_locked() done, defined at /Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/bokeh/server/session.py:77> exception=AttributeError("'numpy.ndarray' object has no attribute 'upper'")>) Traceback (most recent call last): File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/tornado/ioloop.py", line 740, in _run_callback ret = callback() File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/tornado/ioloop.py", line 764, in _discard_future_result future.result() File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/bokeh/server/session.py", line 98, in _needs_document_lock_wrapper result = await result File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/panel/reactive.py", line 438, in _change_coroutine state._handle_exception(e) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/panel/io/state.py", line 458, in _handle_exception raise exception File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/panel/reactive.py", line 436, in _change_coroutine self._change_event(doc) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/panel/reactive.py", line 454, in _change_event self._process_events(events) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/panel/reactive.py", line 1339, in _process_events super(ReactiveData, self)._process_events(events) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/panel/reactive.py", line 391, in _process_events self.param.update(selfparams) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/param/parameterized.py", line 2319, in update restore = dict(self._update(arg, kwargs)) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/param/parameterized.py", line 2352, in update self._batch_call_watchers() File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/param/parameterized.py", line 2546, in _batch_callwatchers self._execute_watcher(watcher, events) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/param/parameterized.py", line 2506, in _execute_watcher watcher.fn(*args, *kwargs) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/panel/widgets/tables.py", line 1573, in _update_cds self.processed, = self._get_data() File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/panel/widgets/tables.py", line 1342, in _get_data return super()._get_data() File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/panel/widgets/tables.py", line 600, in _get_data return self._process_df_and_convert_to_cds(self.value) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/panel/widgets/tables.py", line 604, in _process_df_and_convert_to_cds df = self._filter_dataframe(df) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/panel/widgets/tables.py", line 457, in _filter_dataframe filters.extend(self._get_header_filters(df)) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/panel/widgets/tables.py", line 510, in _get_header_filters filters.append(col.str.contains(val, case=False, regex=False)) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/pandas/core/strings/accessor.py", line 137, in wrapper return func(self, args, **kwargs) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/pandas/core/strings/accessor.py", line 1335, in contains result = self._data.array._str_contains(pat, case, flags, na, regex) File "/Users/thuydo/miniconda3/envs/panel39/lib/python3.9/site-packages/pandas/core/strings/object_array.py", line 143, in _str_contains upper_pat = pat.upper() AttributeError: 'numpy.ndarray' object has no attribute 'upper'

philippjfr commented 2 months ago

I cannot reproduce this, can you report your pandas version?

philippjfr commented 2 months ago

Nvm I can.

philippjfr commented 2 months ago

The filter definition is wrong, it should be:

        'value': {'type': 'list', 'values': ['a', 'b', 'c'], 'multiselect': True, 'func': 'in'}
thuydotm commented 2 months ago

Alright, it works well if specifying func='in' in the definition. Just a bit inconsistency between single and multi selection. First one is case insensitive while the other is case sensitive.