ibis icon indicating copy to clipboard operation
ibis copied to clipboard

fix: truncate columns in repr for wide tables

Open jcrist opened this issue 3 years ago • 3 comments
trafficstars

By default rich will decrease the size of columns until they're unreadable to make all columns fit in repr. This PR attempts to fix that by adding a trailing ... column to indicate there are more columns to the right, and truncating the number of columns displayed to only those whose column names can be completely rendered (we set min_width=len(column_name) for every column).

This also switches to using horizontal ellipsis () everywhere instead of vertical ellipsis. Vertical ellipsis mess with the alignment in non-terminal rendering (e.g. copy-paste the output into a code block comment in github), while horizontal ellipsis don't have this problem.

Example:

In [1]: import ibis

In [2]: con = ibis.duckdb.connect()

In [3]: ibis.options.interactive = True

In [4]: import numpy as np, pandas as pd

In [5]: df = pd.DataFrame({f"col_{i}": np.random.normal(size=100) for i in range(20)})

In [6]: t = con.register(df)

In [7]: t
Out[7]: 
┏━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━┳━━━┓
┃ col_0 ┃ col_1 ┃ col_2 ┃ col_3 ┃ col_4 ┃ col_5 ┃ col_6 ┃ col_7 ┃ col_8 ┃ col_9 ┃ col_10 ┃ … ┃
┡━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━╇━━━┩
│ floa… │ floa… │ floa… │ floa… │ floa… │ floa… │ floa… │ floa… │ floa… │ floa… │ float… │ … │
├───────┼───────┼───────┼───────┼───────┼───────┼───────┼───────┼───────┼───────┼────────┼───┤
│ -0.0… │ 0.87… │ 0.23… │ -2.9… │ 0.69… │ 0.89… │ -0.4… │ -0.7… │ 0.37… │ 0.46… │ 1.474… │ … │
│ 0.10… │ -0.3… │ -0.8… │ 0.13… │ -1.1… │ 1.73… │ -0.3… │ -0.7… │ 1.38… │ 0.31… │ -0.73… │ … │
│ 0.63… │ 1.87… │ 1.29… │ 0.32… │ -0.9… │ -0.3… │ -0.9… │ -1.2… │ -0.2… │ 0.21… │ 1.146… │ … │
│ 0.77… │ 2.04… │ 0.93… │ 0.73… │ 0.63… │ 0.52… │ 0.01… │ -0.5… │ -1.6… │ 1.94… │ -0.37… │ … │
│ -0.3… │ 1.22… │ 0.61… │ -0.1… │ 0.06… │ -0.6… │ 0.63… │ 0.26… │ -0.0… │ 0.26… │ -0.79… │ … │
│ 0.08… │ -0.5… │ 1.24… │ 1.68… │ -0.7… │ -1.2… │ -0.3… │ -0.2… │ -2.3… │ -0.9… │ -0.92… │ … │
│ -1.3… │ 1.44… │ 0.44… │ 1.29… │ -0.9… │ 0.55… │ -0.2… │ 1.26… │ 2.35… │ 1.96… │ -0.88… │ … │
│ 0.42… │ -1.8… │ 1.54… │ 0.20… │ -1.0… │ -0.2… │ -1.3… │ 0.04… │ 1.05… │ 0.23… │ -1.19… │ … │
│ 0.14… │ 0.36… │ -1.3… │ 1.84… │ -0.4… │ 0.52… │ -0.8… │ 0.70… │ -0.4… │ -0.1… │ 0.160… │ … │
│ -0.6… │ -0.6… │ 0.12… │ -1.5… │ 0.09… │ 1.74… │ 0.77… │ -0.0… │ -1.0… │ -0.1… │ -0.69… │ … │
│   …   │   …   │   …   │   …   │   …   │   …   │   …   │   …   │   …   │   …   │   …    │ … │
└───────┴───────┴───────┴───────┴───────┴───────┴───────┴───────┴───────┴───────┴────────┴───┘

jcrist avatar Sep 21 '22 19:09 jcrist

I was going to add/update the tests, but it looks like no tests exist for this functionality?

jcrist avatar Sep 21 '22 19:09 jcrist

Test Results

       35 files         35 suites   1h 17m 9s :stopwatch:   9 861 tests   7 775 :heavy_check_mark: 2 086 :zzz: 0 :x: 36 021 runs  27 978 :heavy_check_mark: 8 043 :zzz: 0 :x:

Results for commit 4bc2c907.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Sep 21 '22 19:09 github-actions[bot]

Codecov Report

Merging #4554 (4bc2c90) into master (cab27e0) will decrease coverage by 0.04%. The diff coverage is 95.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4554      +/-   ##
==========================================
- Coverage   92.55%   92.50%   -0.05%     
==========================================
  Files         183      183              
  Lines       20004    20021      +17     
  Branches     2961     2966       +5     
==========================================
+ Hits        18514    18520       +6     
- Misses       1114     1120       +6     
- Partials      376      381       +5     
Impacted Files Coverage Δ
ibis/expr/types/relations.py 94.37% <95.83%> (-0.02%) :arrow_down:
ibis/common/pretty.py 85.93% <0.00%> (-14.07%) :arrow_down:
ibis/backends/impala/__init__.py 85.89% <0.00%> (-0.22%) :arrow_down:

codecov[bot] avatar Sep 21 '22 19:09 codecov[bot]