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(Python): Allow left/center as table cell alignment format for notebooks #15915

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

lisphilar
Copy link

@lisphilar lisphilar commented Apr 26, 2024

Closes #15822

We use polars.Config.set_tbl_cell_alignment() to change the table cell alignment format for print(pl.DataFrame()).
This PR enables to change format of display(pl.DataFrame()) outputs on Jupyter Notebook and Google Colab.

To-do

  • NotebookFormatter.write_style() selects text-align reading "POLARS_FMT_TABLE_CELL_ALIGNMENT" env variable
  • NotebookFormatter.write_style() selects text-align reading "POLARS_FMT_TABLE_CELL_NUMERIC_ALIGNMENT"
  • update docs of polars.Config.set_tbl_cell_alignment()
  • update docs of polars.Config.set_tbl_cell_numeric_alignment()
  • add additional test for display (if possible)

lisphilar and others added 2 commits April 27, 2024 01:06
…tebooks pola-rs#15822

* feat: set text_align with POLARS_FMT_TABLE_CELL_ALIGNMENT env variable

* docs: mention expected impact of set_tbl_cell_alignment in docstring

* fix: KeyError when un-assigned

* docs: fix W505 Doc line too long (111 > 88)

* docs: fix D205 1 blank line required between summary line and description

* fix: text_align tag is not lower case

* feat: set numeric text align with POLARS_FMT_TABLE_CELL_NUMERIC_ALIGNMENT env variable

* docs: mention expected impact of set_tbl_cell_numeric_alignment in docstring

* docs: fix D417 Missing argument description in the docstring for `get_attributes`: `col_idx`

* docs: update docstring for clarification

* refactor: access environment variables at DataFrame level

* docs: fix D213 [*] Multi-line docstring summary should start at the second line

* docs: fix W505 Doc line too long (99 > 88)

* fix: F821 Undefined name `numeric_align`

* test: add tests with _repr_html and table cell alignment settings

* fix: AttributeError

* fix: lines too long

* test: fix F541 [*] f-string without any placeholders

* fix: lines too long

* refactor: fix errors suggested by lint

* refactor: reorder variable assignment

* refactor: fix errors suggested by lint

* refactor: fix error suggested by lint

* test: remove unnecessary characters

* test: fix errors suggested by lint

* test: fix errors suggested by lint

* test: fix errors suggested by lint

* test: fix typo

* fix: ignore[arg-type] for mypy

* fix:  Return value expected  [return-value]

* refactor: get attributes at once

* fix: KeyError: '\n              text-align'

* fix:  Value of type "set[dict[str, str] | None]" is not indexable

* fix: KeyError by f-string with unescaped {}

* refactor: fix format

* fix: Value of type "Set[Dict[str, str]]" is not indexable

* refactor

* fix: used set mistakenly

* fix: Key expression in dictionary comprehension has incompatible type "int"; expected type "str"  [misc]

* refactor

* fix: Argument 3 to "Tag" has incompatible type "**Dict[str, str]"; expected "Optional[Dict[str, str]]"  [arg-type]

* fix: TypeError: Tag.__init__() got an unexpected keyword argument 'align'

* fix: Value expression in dictionary comprehension has incompatible type "Optional[Dict[str, str]]"; expected type "Dict[str, str]"  [misc]

* fix: Value of type "dict[int, dict[str, str]] | None" is not indexable  [index]

* fix: repeated code outside conditional statement

* refactor: accept code_reginement

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* refactor: accept code_reginement

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Revert "refactor: accept code_reginement"

This reverts commit 3b4a9b5.

* Revert "refactor: accept code_reginement"

This reverts commit 4e0d734.

---------

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Catch up with the latest polars
@lisphilar lisphilar changed the title [trial with forked] feat(Python): Allow left/center as table cell alignment format for notebooks feat(Python): Allow left/center as table cell alignment format for notebooks Apr 26, 2024
@github-actions github-actions bot added the enhancement New feature or an improvement of an existing feature label Apr 26, 2024
@lisphilar lisphilar marked this pull request as ready for review April 26, 2024 16:40
@lisphilar
Copy link
Author

Rust codes were not changed, but coverage-rust 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`

Copy link

codecov bot commented May 4, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 80.95%. Comparing base (6730a72) to head (51ef3b7).

Files Patch % Lines
py-polars/polars/dataframe/frame.py 25.00% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15915      +/-   ##
==========================================
- Coverage   80.96%   80.95%   -0.01%     
==========================================
  Files        1386     1386              
  Lines      178379   178403      +24     
  Branches     3064     3069       +5     
==========================================
+ Hits       144424   144427       +3     
- Misses      33466    33485      +19     
- Partials      489      491       +2     
Flag Coverage Δ
python 74.47% <80.00%> (-0.03%) ⬇️
rust 78.12% <6.66%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow left/center as table cell alignment format for notebooks
1 participant