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

feat: polars dataframe support #195

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ dev = [
"dask[dataframe]; python_version < '3.7'",
"playwright; python_version > '3.6'",
"pytest-playwright; python_version > '3.6'",
"polars",
]
assets = [
"solara-assets==1.22.0"
Expand Down
2 changes: 2 additions & 0 deletions solara/components/datatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def DataTable(

if df_type(df) == "pandas":
column_data = dfs[columns].to_dict("records")
elif df_type(df) == "polars":
column_data = dfs[columns].to_dicts()
else:
column_data = dfs[columns].to_records()
for i in range(i2 - i1):
Expand Down
2 changes: 2 additions & 0 deletions solara/lab/hooks/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ def use_df_column_names(df):
return df.get_column_names()
elif df_type(df) == "pandas":
return df.columns.tolist()
elif df_type(df) == "polars":
return df.columns
else:
raise TypeError(f"{type(df)} not supported")
4 changes: 3 additions & 1 deletion tests/unit/datatable_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import pytest
import solara
import vaex
import polars as pl
from solara.components.datatable import DataTable, DataTableWidget

df_vaex = vaex.datasets.titanic()
df_pandas = df_vaex.to_pandas_df()
df_polars = pl.from_pandas(df_pandas)


@pytest.mark.parametrize("df", [df_vaex, df_pandas])
@pytest.mark.parametrize("df", [df_vaex, df_pandas, df_polars])
def test_render(df):
@solara.component
def Test():
Expand Down
Loading