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

Support polars directly in DataGrid and render.data_frame #1439

Closed
machow opened this issue May 30, 2024 · 1 comment
Closed

Support polars directly in DataGrid and render.data_frame #1439

machow opened this issue May 30, 2024 · 1 comment
Assignees
Labels
data frame Related to @render.data_frame
Milestone

Comments

@machow
Copy link
Collaborator

machow commented May 30, 2024

Currently, the DataGrid supports polars by calling its polars.DataFrame.to_pandas() method. From pairing with @schloerke, I can take a pass at supporting polars directly in the DataGrid. This will give me a chance to see what DataFrame specific logic is in there.

TODO:

  • Separate out DataFrame specific logic (similar to in Great Tables _tbl_data.py)
  • Should not create hard dependencies on any given DataFrame library
  • Should handle polars dtypes (a big part of the DataFrame specific logic right now).
  • After submitting PR, all the DataFrame-specific logic should be in one place, so I can evaluate plugging in narwhals

Example app

from shiny.express import render
import polars as pl

df = pl.DataFrame({"x": [1,2,3], "y": ["a", "b", "c"], "z": [{"val": 1}, {"val": 2}, {"val": 3}]})

@render.data_frame
def frame():
    return render.DataGrid(df)

NOTES:

  • htmltools.HTML subclasses str, but this causes polars.Series to coerce it to str. This means that you can't get HTML back. (subclassing UserString or something avoids this behavior).
@schloerke
Copy link
Collaborator

Fixed in #1474

@schloerke schloerke added this to the v1.0.0 milestone Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data frame Related to @render.data_frame
Projects
None yet
Development

No branches or pull requests

2 participants