mwouts / itables

Pandas DataFrames as Interactive DataTables
https://mwouts.github.io/itables/
MIT License
723 stars 54 forks source link

Support for Polars Dataframes #159

Closed Arengard closed 1 year ago

Arengard commented 1 year ago

Could you support Polars DataFrames?

import polars as pl

from itables import init_notebook_mode
import itables.options as opt
opt.css = """
.itables table td { font-style: italic; }
.itables table th { font-style: oblique; }

init_notebook_mode(all_interactive=True,  connected=False)

df = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
df
mwouts commented 1 year ago

Hello @Arengard , well sure I'd love to provide support for these dataframes as well.

However I must say I have never used them for now, so I will need your help here!

If we want to provide the same level of support as for Pandas DataFrames, we would have to do more or less the following:

  1. We would have to contribute more examples of Polars DataFrames. Do you think you could port (a subset?) of sample_dfs.py to Polars DataFrames? In particular I need to know what are the classical column types, and if there is anything like indexes or multi-indexes.
  2. Then, we would have to write the conversion of the dataframe content to JSON. Currently this is done in datatables_format.datatables_rows. That part should be easy.
  3. We also need to write a HTML header for the table. If we don't have multiple levels of columns then that is easy. For Pandas DataFrames I use their own implementation as it is not so obvious to get the multi index right...
  4. You will also have to tell me how to estimate the size of a DataFrame, and how to extract some rows/columns when we have to downsample it (currently done at downsample._downsample)

So let me know if you feel comfortable with helping me on the examples and on the Polars DataFrame specificities, and then we can get started on a proof of concept!

mwouts commented 1 year ago

Well I have just drafted a PR (#164 ) for this... it might still move a bit but you can already give it a try:

pip install git+https://github.com/mwouts/itables.git@polars

Keep me posted!

mwouts commented 1 year ago

This is available in itables==1.5.0. Please let me know how it works for you!