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: Separate aggregators for different columns blocked by type hint #7281

Closed
AxZolotl opened this issue Sep 15, 2024 · 2 comments · Fixed by #7450
Closed

Tabulator: Separate aggregators for different columns blocked by type hint #7281

AxZolotl opened this issue Sep 15, 2024 · 2 comments · Fixed by #7450
Assignees
Labels
component: tabulator Related to the Tabulator widget

Comments

@AxZolotl
Copy link

Software Version Info
panel 1.4.5 

Description of expected behavior and the observed behavior

  • 'If separate aggregators for different columns are required the dictionary may be nested as {index_name: {column_name: aggregator}}'
  • Aggregators parameter in class DataTabulator accepts only Dict(String, String)

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

pn.widgets.Tabulator(
            value = value, 
            hierarchical = True, 
            aggregators = {index_name: {column_name: aggregator}}

Stack traceback and/or browser JavaScript console output

ValueError: failed to validate DataTabulator(id=id, ...).aggregators: expected a dict of type Dict(String, String), got a dict with invalid values for keys: index_name
@thuydotm thuydotm added the component: tabulator Related to the Tabulator widget label Oct 2, 2024
@thuydotm
Copy link
Collaborator

thuydotm commented Oct 3, 2024

@AxZolotl Thanks for reporting this. Can you please add a small reproducible example?

@thuydotm thuydotm self-assigned this Oct 29, 2024
@thuydotm
Copy link
Collaborator

thuydotm commented Oct 29, 2024

Reproducible example:

import pandas as pd
import panel as pn

df = pd.DataFrame([
    ('Germany', 2020, 9, 2.4, 'A'),
    ('Germany', 2021, 3, 7.3, 'C'),
    ('Germany', 2022, 6, 3.1, 'B'),
    ('UK', 2020, 5, 8.0, 'A'),
    ('UK', 2021, 1, 3.9, 'B'),
    ('UK', 2022, 9, 2.2, 'A')
], columns=['Country', 'Year', 'Int', 'Float', 'Str'])

pn.widgets.Tabulator(value=df.set_index(['Year', 'Country']), hierarchical=True,
                  aggregators={'Year': {'Int': 'sum', 'Float': 'mean'}}).servable()

Traceback:

2024-10-29 11:34:56,968 Error running application handler <panel.io.handlers.ScriptHandler object at 0x113fce1b0>: failed to validate DataTabulator(id='p1031', ...).aggregators: expected a dict of type Dict(String, String), got a dict with invalid values for keys: Year
File 'bases.py', line 363, in prepare_value:
raise ValueError(f"failed to validate {obj_repr}.{name}: {error}") Traceback (most recent call last):
  File "/Users/thuydo/work/thuydotm/panel/panel/io/handlers.py", line 405, in run
    exec(self._code, module.__dict__)
  File "/Users/thuydo/work/thuydotm/panel/thuy/tabulator_agg.py", line 15, in <module>
    aggregators={'Year': {'Int': 'sum', 'Float': 'mean'}}).servable()
                                                           ^^^^^^^^^^
  File "/Users/thuydo/work/thuydotm/panel/panel/viewable.py", line 399, in servable
    self.server_doc(title=title, location=location) # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/thuydo/work/thuydotm/panel/panel/viewable.py", line 1006, in server_doc
    model = self.get_root(doc)
            ^^^^^^^^^^^^^^^^^^
  File "/Users/thuydo/work/thuydotm/panel/panel/viewable.py", line 678, in get_root
    root = self._get_model(doc, comm=comm)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/thuydo/work/thuydotm/panel/panel/widgets/tables.py", line 1821, in _get_model
    model = super()._get_model(doc, root, parent, comm)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/thuydo/work/thuydotm/panel/panel/widgets/tables.py", line 357, in _get_model
    model = self._widget_type(**properties)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/thuydo/work/thuydotm/panel/.pixi/envs/default/lib/python3.12/site-packages/bokeh/models/layouts.py", line 102, in __init__
    super().__init__(*args, **kwargs)
  File "/Users/thuydo/work/thuydotm/panel/.pixi/envs/default/lib/python3.12/site-packages/bokeh/models/ui/panes.py", line 50, in __init__
    super().__init__(*args, **kwargs)
  File "/Users/thuydo/work/thuydotm/panel/.pixi/envs/default/lib/python3.12/site-packages/bokeh/models/ui/ui_element.py", line 107, in __init__
    super().__init__(*args, **kwargs)
  File "/Users/thuydo/work/thuydotm/panel/.pixi/envs/default/lib/python3.12/site-packages/bokeh/models/ui/ui_element.py", line 63, in __init__
    super().__init__(*args, **kwargs)
  File "/Users/thuydo/work/thuydotm/panel/.pixi/envs/default/lib/python3.12/site-packages/bokeh/model/model.py", line 119, in __init__
    super().__init__(**kwargs)
  File "/Users/thuydo/work/thuydotm/panel/.pixi/envs/default/lib/python3.12/site-packages/bokeh/core/has_props.py", line 304, in __init__
    setattr(self, name, value)
  File "/Users/thuydo/work/thuydotm/panel/.pixi/envs/default/lib/python3.12/site-packages/bokeh/core/has_props.py", line 336, in __setattr__
    return super().__setattr__(name, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/thuydo/work/thuydotm/panel/.pixi/envs/default/lib/python3.12/site-packages/bokeh/core/property/descriptors.py", line 330, in __set__
    value = self.property.prepare_value(obj, self.name, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/thuydo/work/thuydotm/panel/.pixi/envs/default/lib/python3.12/site-packages/bokeh/core/property/bases.py", line 363, in prepare_value
    raise ValueError(f"failed to validate {obj_repr}.{name}: {error}")
ValueError: failed to validate DataTabulator(id='p1031', ...).aggregators: expected a dict of type Dict(String, String), got a dict with invalid values for keys: Year
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tabulator Related to the Tabulator widget
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants