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 header_filter with multiselect enabled: AttributeError #7110

Closed
thuydotm opened this issue Aug 9, 2024 · 4 comments · Fixed by #7111
Closed

Tabulator header_filter with multiselect enabled: AttributeError #7110

thuydotm opened this issue Aug 9, 2024 · 4 comments · Fixed by #7111
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@thuydotm
Copy link
Collaborator

thuydotm commented Aug 9, 2024

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(**self_params)
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_call_watchers
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 philippjfr added this to the v1.5.0 milestone Aug 9, 2024
@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label Aug 9, 2024
@philippjfr
Copy link
Member

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

@philippjfr
Copy link
Member

Nvm I can.

@philippjfr
Copy link
Member

The filter definition is wrong, it should be:

        'value': {'type': 'list', 'values': ['a', 'b', 'c'], 'multiselect': True, 'func': 'in'}

@thuydotm
Copy link
Collaborator Author

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.

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

Successfully merging a pull request may close this issue.

2 participants