Skip to content

Commit

Permalink
sagemathgh-36857: use unicode characters to display tables
Browse files Browse the repository at this point in the history
    
This is using unicode box-drawing characters to make better-looking
tables.

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.

### ⌛ Dependencies

- sagemath#36861

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->
    
URL: sagemath#36857
Reported by: Frédéric Chapoton
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Jan 1, 2024
2 parents 59a911c + d03c94c commit 73468b7
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 248 deletions.
14 changes: 7 additions & 7 deletions src/doc/en/prep/Programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,13 @@ when doing some of our plotting and limits. What do you think will
happen if you put dollar signs around the labels in the header? ::

sage: table( [('i', 'det(A^i)')] + [ (i,det(A^i)) for i in [0..4] ], header_row=True)
i det(A^i)
+---+----------+
0 1
1 -2
2 4
3 -8
4 16
i det(A^i)
├───┼──────────┤
0 1
1 -2
2 4
3 -8
4 16


.. _Defs:
Expand Down
228 changes: 114 additions & 114 deletions src/sage/combinat/bijectionist.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,54 +68,54 @@
sage: bij.set_statistics((len, len), (alpha1, beta1), (alpha2, beta2))
sage: a, b = bij.statistics_table()
sage: table(a, header_row=True, frame=True)
+-----------+--------+--------+--------+
| a | α_1(a) | α_2(a) | α_3(a) |
+===========+========+========+========+
| [] | 0 | 0 | 0 |
+-----------+--------+--------+--------+
| [1] | 1 | 1 | 1 |
+-----------+--------+--------+--------+
| [1, 2] | 2 | 2 | 2 |
+-----------+--------+--------+--------+
| [2, 1] | 2 | 1 | 0 |
+-----------+--------+--------+--------+
| [1, 2, 3] | 3 | 3 | 3 |
+-----------+--------+--------+--------+
| [1, 3, 2] | 3 | 2 | 1 |
+-----------+--------+--------+--------+
| [2, 1, 3] | 3 | 2 | 1 |
+-----------+--------+--------+--------+
| [2, 3, 1] | 3 | 2 | 0 |
+-----------+--------+--------+--------+
| [3, 1, 2] | 3 | 1 | 0 |
+-----------+--------+--------+--------+
| [3, 2, 1] | 3 | 2 | 1 |
+-----------+--------+--------+--------+
┌───────────┬────────┬────────┬────────┐
a | α_1(a) | α_2(a) | α_3(a) |
╞═══════════╪════════╪════════╪════════╡
[] | 0 | 0 | 0 |
├───────────┼────────┼────────┼────────┤
[1] | 1 | 1 | 1 |
├───────────┼────────┼────────┼────────┤
[1, 2] | 2 | 2 | 2 |
├───────────┼────────┼────────┼────────┤
[2, 1] | 2 | 1 | 0 |
├───────────┼────────┼────────┼────────┤
[1, 2, 3] | 3 | 3 | 3 |
├───────────┼────────┼────────┼────────┤
[1, 3, 2] | 3 | 2 | 1 |
├───────────┼────────┼────────┼────────┤
[2, 1, 3] | 3 | 2 | 1 |
├───────────┼────────┼────────┼────────┤
[2, 3, 1] | 3 | 2 | 0 |
├───────────┼────────┼────────┼────────┤
[3, 1, 2] | 3 | 1 | 0 |
├───────────┼────────┼────────┼────────┤
[3, 2, 1] | 3 | 2 | 1 |
└───────────┴────────┴────────┴────────┘
sage: table(b, header_row=True, frame=True)
+-----------+---+--------+--------+--------+
| b | τ | β_1(b) | β_2(b) | β_3(b) |
+===========+===+========+========+========+
| [] | 0 | 0 | 0 | 0 |
+-----------+---+--------+--------+--------+
| [1] | 1 | 1 | 1 | 1 |
+-----------+---+--------+--------+--------+
| [1, 2] | 2 | 2 | 1 | 0 |
+-----------+---+--------+--------+--------+
| [2, 1] | 1 | 2 | 2 | 2 |
+-----------+---+--------+--------+--------+
| [1, 2, 3] | 3 | 3 | 1 | 0 |
+-----------+---+--------+--------+--------+
| [1, 3, 2] | 2 | 3 | 2 | 1 |
+-----------+---+--------+--------+--------+
| [2, 1, 3] | 2 | 3 | 2 | 1 |
+-----------+---+--------+--------+--------+
| [2, 3, 1] | 2 | 3 | 2 | 1 |
+-----------+---+--------+--------+--------+
| [3, 1, 2] | 2 | 3 | 2 | 0 |
+-----------+---+--------+--------+--------+
| [3, 2, 1] | 1 | 3 | 3 | 3 |
+-----------+---+--------+--------+--------+
┌───────────┬───┬────────┬────────┬────────┐
b | τ | β_1(b) | β_2(b) | β_3(b) |
╞═══════════╪═══╪════════╪════════╪════════╡
[] | 0 | 0 | 0 | 0 |
├───────────┼───┼────────┼────────┼────────┤
[1] | 1 | 1 | 1 | 1 |
├───────────┼───┼────────┼────────┼────────┤
[1, 2] | 2 | 2 | 1 | 0 |
├───────────┼───┼────────┼────────┼────────┤
[2, 1] | 1 | 2 | 2 | 2 |
├───────────┼───┼────────┼────────┼────────┤
[1, 2, 3] | 3 | 3 | 1 | 0 |
├───────────┼───┼────────┼────────┼────────┤
[1, 3, 2] | 2 | 3 | 2 | 1 |
├───────────┼───┼────────┼────────┼────────┤
[2, 1, 3] | 2 | 3 | 2 | 1 |
├───────────┼───┼────────┼────────┼────────┤
[2, 3, 1] | 2 | 3 | 2 | 1 |
├───────────┼───┼────────┼────────┼────────┤
[3, 1, 2] | 2 | 3 | 2 | 0 |
├───────────┼───┼────────┼────────┼────────┤
[3, 2, 1] | 1 | 3 | 3 | 3 |
└───────────┴───┴────────┴────────┴────────┘
sage: from sage.combinat.cyclic_sieving_phenomenon import orbit_decomposition
sage: bij.set_constant_blocks(orbit_decomposition(A, rotate_permutation))
Expand Down Expand Up @@ -854,53 +854,53 @@ def statistics_table(self, header=True):
sage: bij.set_statistics((wex, des), (fix, adj))
sage: a, b = bij.statistics_table()
sage: table(a, header_row=True, frame=True)
+-----------+--------+--------+
| a | α_1(a) | α_2(a) |
+===========+========+========+
| [] | 0 | 0 |
+-----------+--------+--------+
| [1] | 1 | 1 |
+-----------+--------+--------+
| [1, 2] | 2 | 2 |
+-----------+--------+--------+
| [2, 1] | 1 | 0 |
+-----------+--------+--------+
| [1, 2, 3] | 3 | 3 |
+-----------+--------+--------+
| [1, 3, 2] | 2 | 1 |
+-----------+--------+--------+
| [2, 1, 3] | 2 | 1 |
+-----------+--------+--------+
| [2, 3, 1] | 2 | 0 |
+-----------+--------+--------+
| [3, 1, 2] | 1 | 0 |
+-----------+--------+--------+
| [3, 2, 1] | 2 | 1 |
+-----------+--------+--------+
┌───────────┬────────┬────────┐
a | α_1(a) | α_2(a) |
╞═══════════╪════════╪════════╡
[] | 0 | 0 |
├───────────┼────────┼────────┤
[1] | 1 | 1 |
├───────────┼────────┼────────┤
[1, 2] | 2 | 2 |
├───────────┼────────┼────────┤
[2, 1] | 1 | 0 |
├───────────┼────────┼────────┤
[1, 2, 3] | 3 | 3 |
├───────────┼────────┼────────┤
[1, 3, 2] | 2 | 1 |
├───────────┼────────┼────────┤
[2, 1, 3] | 2 | 1 |
├───────────┼────────┼────────┤
[2, 3, 1] | 2 | 0 |
├───────────┼────────┼────────┤
[3, 1, 2] | 1 | 0 |
├───────────┼────────┼────────┤
[3, 2, 1] | 2 | 1 |
└───────────┴────────┴────────┘
sage: table(b, header_row=True, frame=True)
+-----------+---+--------+--------+
| b | τ | β_1(b) | β_2(b) |
+===========+===+========+========+
| [] | 0 | 0 | 0 |
+-----------+---+--------+--------+
| [1] | 1 | 1 | 1 |
+-----------+---+--------+--------+
| [1, 2] | 2 | 1 | 0 |
+-----------+---+--------+--------+
| [2, 1] | 1 | 2 | 2 |
+-----------+---+--------+--------+
| [1, 2, 3] | 3 | 1 | 0 |
+-----------+---+--------+--------+
| [1, 3, 2] | 2 | 2 | 1 |
+-----------+---+--------+--------+
| [2, 1, 3] | 2 | 2 | 1 |
+-----------+---+--------+--------+
| [2, 3, 1] | 2 | 2 | 1 |
+-----------+---+--------+--------+
| [3, 1, 2] | 2 | 2 | 0 |
+-----------+---+--------+--------+
| [3, 2, 1] | 1 | 3 | 3 |
+-----------+---+--------+--------+
┌───────────┬───┬────────┬────────┐
b | τ | β_1(b) | β_2(b) |
╞═══════════╪═══╪════════╪════════╡
[] | 0 | 0 | 0 |
├───────────┼───┼────────┼────────┤
[1] | 1 | 1 | 1 |
├───────────┼───┼────────┼────────┤
[1, 2] | 2 | 1 | 0 |
├───────────┼───┼────────┼────────┤
[2, 1] | 1 | 2 | 2 |
├───────────┼───┼────────┼────────┤
[1, 2, 3] | 3 | 1 | 0 |
├───────────┼───┼────────┼────────┤
[1, 3, 2] | 2 | 2 | 1 |
├───────────┼───┼────────┼────────┤
[2, 1, 3] | 2 | 2 | 1 |
├───────────┼───┼────────┼────────┤
[2, 3, 1] | 2 | 2 | 1 |
├───────────┼───┼────────┼────────┤
[3, 1, 2] | 2 | 2 | 0 |
├───────────┼───┼────────┼────────┤
[3, 2, 1] | 1 | 3 | 3 |
└───────────┴───┴────────┴────────┘
TESTS:
Expand All @@ -911,29 +911,29 @@ def statistics_table(self, header=True):
sage: bij = Bijectionist(A, B, tau)
sage: a, b = bij.statistics_table()
sage: table(a, header_row=True, frame=True)
+--------+
| a |
+========+
| [] |
+--------+
| [1] |
+--------+
| [1, 2] |
+--------+
| [2, 1] |
+--------+
┌────────┐
a |
╞════════╡
[] |
├────────┤
[1] |
├────────┤
[1, 2] |
├────────┤
[2, 1] |
└────────┘
sage: table(b, header_row=True, frame=True)
+--------+---+
| b | τ |
+========+===+
| [] | 0 |
+--------+---+
| [1] | 1 |
+--------+---+
| [1, 2] | 2 |
+--------+---+
| [2, 1] | 1 |
+--------+---+
┌────────┬───┐
b | τ |
╞════════╪═══╡
[] | 0 |
├────────┼───┤
[1] | 1 |
├────────┼───┤
[1, 2] | 2 |
├────────┼───┤
[2, 1] | 1 |
└────────┴───┘
We can omit the header::
Expand Down
Loading

0 comments on commit 73468b7

Please sign in to comment.