Skip to content

Commit 6ff67b0

Browse files
committed
Improve string and html output
1 parent fb200e2 commit 6ff67b0

File tree

6 files changed

+173
-109
lines changed

6 files changed

+173
-109
lines changed

python/CHANGELOG.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@
44

55
**Breaking changes**
66

7-
- `Mutation.position` and `Mutation.index` which were deprecated in 0.2.2 (Sep '19) have
7+
- ``Mutation.position`` and ``Mutation.index`` which were deprecated in 0.2.2 (Sep '19) have
88
been removed.
99

1010
**Features**
1111

12-
- Add `Table.append` method for adding rows from classes such as `SiteTableRow` and
13-
`Site` (:user:`benjeffery`, :issue:`1111`, :pr:`1254`).
12+
- Add ``Table.append`` method for adding rows from classes such as ``SiteTableRow`` and
13+
``Site`` (:user:`benjeffery`, :issue:`1111`, :pr:`1254`).
1414

1515
- SVG visualization of a single tree allows all mutations on an edge to be plotted
1616
via the ``all_edge_mutations`` param (:user:`hyanwong`,:issue:`1253`, :pr:`1258`).
1717

18-
- Entity classes such as `Mutation`, `Node` are now python dataclasses
18+
- Entity classes such as ``Mutation``, ``Node`` are now python dataclasses
1919
(:user:`benjeffery`, :pr:`1261`).
2020

2121
- Metadata decoding for table row access is now lazy (:user:`benjeffery`, :pr:`1261`).
2222

23+
- Improve display of tables when ``print``ed, limiting lines to ``tskit.MAX_LINES``
24+
(:user:`benjeffery`,:issue:`1270`, :pr:`1300`)
2325

2426
**Fixes**
2527

python/tests/test_tables.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,14 @@ def test_str(self):
540540
table = self.table_class()
541541
table.set_columns(**input_data)
542542
s = str(table)
543-
assert len(s.splitlines()) == num_rows + 1
543+
assert len(s.splitlines()) == num_rows + 4
544+
input_data = self.make_input_data(41)
545+
table = self.table_class()
546+
table.set_columns(**input_data)
547+
assert "1 rows skipped" in str(table)
548+
tskit.MAX_LINES = None
549+
assert "1 rows skipped" not in str(table)
550+
tskit.MAX_LINES = 40
544551

545552
def test_repr_html(self):
546553
for num_rows in [0, 10, 40, 50]:
@@ -556,7 +563,7 @@ def test_repr_html(self):
556563
assert len(html.splitlines()) == num_rows + 11
557564
assert (
558565
html.split("</tr>")[21]
559-
== "\n<tr><td><em>... skipped 10 rows ...</em></td>"
566+
== "\n<tr><td><em>10 rows skipped (tskit.MAX_LINES)</em></td>"
560567
)
561568
else:
562569
assert len(html.splitlines()) == num_rows + 20

python/tests/test_util.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ def test_obj_to_collapsed_html(obj, expected):
407407
)
408408

409409

410+
def test_truncate_string_end():
411+
assert util.truncate_string_end("testing") == "testing"
412+
assert util.truncate_string_end("testing", 7) == "testing"
413+
assert util.truncate_string_end("testing", 5) == "te..."
414+
415+
410416
def test_unicode_table():
411417
assert (
412418
util.unicode_table(
@@ -437,5 +443,21 @@ def test_unicode_table():
437443
╟──┼──┼──┼──╢
438444
║90│10│11│12║
439445
╚══╧══╧══╧══╝
446+
"""
447+
)
448+
449+
assert (
450+
util.unicode_table(
451+
[["1", "2", "3", "4"], ["5", "6", "7", "8"], ["90", "10", "11", "12"]],
452+
title="TITLE",
453+
row_separator=False,
454+
)
455+
== """╔═══════════╗
456+
║TITLE ║
457+
╠══╤══╤══╤══╣
458+
║1 │ 2│ 3│ 4║
459+
║5 │ 6│ 7│ 8║
460+
║90│10│11│12║
461+
╚══╧══╧══╧══╝
440462
"""
441463
)

python/tskit/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
ALLELES_ACGT = ("A", "C", "G", "T")
4848

4949
#: Special NAN value used to indicate unknown mutation times
50-
"""
51-
Say what
52-
"""
5350
UNKNOWN_TIME = _tskit.UNKNOWN_TIME
5451

52+
#: Max number of lines to show when printing a table to text or html
53+
MAX_LINES = 40
54+
5555
from tskit.provenance import __version__ # NOQA
5656
from tskit.provenance import validate_provenance # NOQA
5757
from tskit.formats import * # NOQA

0 commit comments

Comments
 (0)