pola-rs / polars

Dataframes powered by a multithreaded, vectorized query engine, written in Rust
https://docs.pola.rs
Other
29.67k stars 1.9k forks source link

Allow left/center as table cell alignment format for notebooks #15822

Open lisphilar opened 5 months ago

lisphilar commented 5 months ago

Description

Description

We use polars.Config.set_tbl_cell_alignment() to change the table cell alignment format for print(pl.DataFrame()). However, this configuration does not work when calling display(pl.DataFrame()) on Jupyter Notebook and Google Colab.

It will be useful for notebook users to allow left/center as formats of display(pl.DataFrame()).

With polars version 0.20.22 on Google Colab: https://gist.github.com/lisphilar/6036542413e2b5991751d706541a7795 image

Solution

If I understand the codes correctly, we can add this feature by updating the following lines, especially 165 line ("text-align: right;").

https://github.com/pola-rs/polars/blob/3d100a87fa5d56f27c08a628ff59ad0dbb8d6090/py-polars/polars/dataframe/_html.py#L153-L177

(I'd like to try my first PR, if acceptable.)

lisphilar commented 5 months ago

Related codes

alexander-beedie commented 5 months ago

I think this is a good idea; in other areas^1 of the NotebookFormatter code we do read the related table environment variables, and I think should do the same here.

貢献を歓迎します :)

lisphilar commented 5 months ago

@alexander-beedie Thank you for your acceptance! ご快諾いただきありがとうございます!

Just a draft, but I created PR #15830 to use "POLARS_FMT_TABLE_CELL_NUMERIC_ALIGNMENT" in NotebookFormatter.write_style() method and to update polars.Config.set_tbl_cell_alignment() docstring.

I'm trying the following unchecked tasks.

To-do

lisphilar commented 5 months ago

@alexander-beedie I created #15915 for review. Could you review it when you get some time?

I struggled to use pre-commit on my PC today, but could not install ruff check with errors. I will try installation later or use my forked repository for repeated tests.

~~#15915 does not change any Rust codes, but coverage-rust check failed with the following error message. Revision of the workflow may be required with another PR.~~

libunwind: stepWithCompactEncoding - invalid compact unwind encoding
error: test failed, to rerun pass `-p polars-sql --test statements`