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 for Polars Struct #290

Open
Samox1 opened this issue Jun 17, 2024 · 2 comments · May be fixed by #292
Open

Support for Polars Struct #290

Samox1 opened this issue Jun 17, 2024 · 2 comments · May be fixed by #292

Comments

@Samox1
Copy link

Samox1 commented Jun 17, 2024

I ran into a problem with the Polars library and their approach to the Dict = Struct type (in Polars). A simple cast to String takes care of it, but I prefer to ask if there is a possibility to add functionality to show a column with type Struct without error.

What appears now (in IPYNB file):
image

Example:

kappa = polars.DataFrame(['id_1','id_1','id_2','id_1','id_4','id_3','id_1','id_2','id_1'],
                        schema={'col_1'}).select(polars.col('col_1').value_counts())
kappa

Returns:
image

with itables:

show(kappa)

image

Adding casting to String:

kappa = polars.DataFrame(['id_1','id_1','id_2','id_1','id_4','id_3','id_1','id_2','id_1'],
                        schema={'col_1'}).select(polars.col('col_1').value_counts().cast(polars.String))

itables returns:
image

@mwouts
Copy link
Owner

mwouts commented Jun 17, 2024

Hi @Samox1 , thank you for pointing out this issue (and for sharing a reproducible example, that's great!). I will look into it soon.

@mwouts mwouts linked a pull request Jun 19, 2024 that will close this issue
@mwouts
Copy link
Owner

mwouts commented Jun 19, 2024

Hi @Samox1 , I have a tentative PR, which you can try following these instructions.

Interestingly the reason why we see Object shown by DataTables is that the data passed to the table (a two dimensional array) contains dicts (which are converted to javascript maps). In my PR I am now replacing these dicts with their str representation, but so far the result is different from the default rendering by Polars so the PR might need a bit more work.

We could possibly use a cast as you do above, or look into the code that polars use to display these special dataframes.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants