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

Cannot sync Tabulator.value to url - DataFrame is not JSON serializable #6784

Open
MarcSkovMadsen opened this issue Apr 23, 2024 · 0 comments
Labels
type: enhancement Minor feature or improvement to an existing feature
Milestone

Comments

@MarcSkovMadsen
Copy link
Collaborator

In Panel 1.4.2 we added support for syncing DataFrame parameters to the url.

This works fine for simple Parameterized classes. But for the Tabulator value parameter it does not.

Please add support for syncing dataframe parameters of widgets and panes in general.

import panel as pn
import pandas as pd
import param

pn.extension("tabulator")

data = pd.DataFrame({"x": [1], "y": [2]})

table = pn.widgets.Tabulator(data)

# class Table(param.Parameterized):
#     value = param.DataFrame()

# table = Table(value=data)

pn.state.location.sync(table, parameters=["value"])

pn.template.FastListTemplate(
    title="Sync a DataFrame and the url parameters",
    main=[table]
).servable()
TypeError: Object of type DataFrame is not JSON serializable

Traceback (most recent call last):
  File "C:\repos\private\panel\.venv\Lib\site-packages\panel\io\handlers.py", line 389, in run
    exec(self._code, module.__dict__)
  File "C:\repos\private\panel\script.py", line 16, in <module>
    pn.state.location.sync(table, parameters=["value"])
  File "C:\repos\private\panel\.venv\Lib\site-packages\panel\io\location.py", line 251, in sync
    v = json.dumps(v)
        ^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\json\encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\json\encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\json\encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type DataFrame is not JSON serializable
@MarcSkovMadsen MarcSkovMadsen added the type: enhancement Minor feature or improvement to an existing feature label Apr 23, 2024
@MarcSkovMadsen MarcSkovMadsen added this to the Wishlist milestone Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant