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

fix: Ensure List element truncation ellipses respect ASCII* table formats #19835

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Nov 17, 2024

Closes #19821.

Follows-up #19404, which missed the List dtype ellipsis truncation.

Example

import polars as pl

df = pl.DataFrame({
    "a": [1, 2],
    "b": [4, 5],
    "c": [[list(range(1, 26))], [list(range(1, 76))]],
})
with pl.Config(ascii_tables=True):
    print(df)   

Before:
(utf8 ellipsis char used in ascii table)

# shape: (2, 3)
# +-----+-----+-----------------+
# | a   | b   | c               |
# | --- | --- | ---             |
# | i64 | i64 | list[list[i64]] |
# +=============================+
# | 1   | 4   | [[1, 2, … 25]]  |
# | 2   | 5   | [[1, 2, … 75]]  |
# +-----+-----+-----------------+

After:
(ascii ellipsis chars)

# shape: (2, 3)
# +-----+-----+------------------+
# | a   | b   | c                |
# | --- | --- | ---              |
# | i64 | i64 | list[list[i64]]  |
# +==============================+
# | 1   | 4   | [[1, 2, ... 25]] |
# | 2   | 5   | [[1, 2, ... 75]] |
# +-----+-----+------------------+

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Nov 17, 2024
@alexander-beedie alexander-beedie force-pushed the fmt-list-ascii-ellipses branch 2 times, most recently from b517846 to 9f59870 Compare November 17, 2024 17:40
Copy link

codecov bot commented Nov 17, 2024

Codecov Report

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

Project coverage is 79.33%. Comparing base (6ccb187) to head (05b232e).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/polars-core/src/fmt.rs 80.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #19835   +/-   ##
=======================================
  Coverage   79.33%   79.33%           
=======================================
  Files        1548     1548           
  Lines      214245   214237    -8     
  Branches     2460     2460           
=======================================
+ Hits       169968   169972    +4     
+ Misses      43719    43707   -12     
  Partials      558      558           

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

@alexander-beedie alexander-beedie changed the title fix: Ensure List element truncation ellipses respect ASCII format fix: Ensure List element truncation ellipses respect ASCII* table formats Nov 17, 2024
@kevinli1993
Copy link

kevinli1993 commented Nov 17, 2024

Thanks @alexander-beedie - this is slightly out of scope for this PR, but I wonder if we should adopt the Oxford comma?

e.g. from

[[1, 2, ... 25]]

to

[[1, 2, ..., 25]]

@alexander-beedie
Copy link
Collaborator Author

alexander-beedie commented Nov 17, 2024

I wonder if we should adopt the Oxford comma?

We should not - it gives up valuable horizontal space for no obvious gain ;)

The only reference I found (after an admittedly very casual search!) talking about this situation seems to agree:

The ellipsis itself is typically used to indicate omitted content. Since it replaces part of the list, treating it as part of the structure (without an additional comma) is common.

@kevinli1993
Copy link

I see, that makes sense. Though I will say that mathematical writing follows the opposite convention of including the Oxford comma in this context.

@ritchie46 ritchie46 merged commit b706c0a into pola-rs:main Nov 18, 2024
26 checks passed
@alexander-beedie alexander-beedie deleted the fmt-list-ascii-ellipses branch November 18, 2024 08:29
@alexander-beedie
Copy link
Collaborator Author

alexander-beedie commented Nov 18, 2024

I see, that makes sense. Though I will say that mathematical writing follows the opposite convention of including the Oxford comma in this context.

Yup. Different domain; here we prioritise visualisation and effective use of horizontal space. The priority in a mathematical domain will understandably err towards formal precision. Each is appropriate in their respective context 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

List columns uses non-ascii characters in display, even when pl.Config.set_ascii_tables(True)
3 participants