Skip to content

Commit

Permalink
FIX better display of object columns with multi-line repr in tablerep…
Browse files Browse the repository at this point in the history
…ort (#1196)
  • Loading branch information
jeromedockes authored and TheooJ committed Dec 11, 2024
1 parent 92434a8 commit dcb7f59
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Bug fixes
:user:`Jérôme Dockès <jeromedockes>` and the matplotlib issue can be tracked
[here](https://github.com/matplotlib/matplotlib/issues/25041).

* The labels on bar plots in the ``TableReport`` for columns of object dtypes
that have a repr spanning multiple lines could be unreadable. This has been
fixed in :pr:`1196` by :user:`Jérôme Dockès <jeromedockes>`.

* Improve the performance of :func:`deduplicate` by removing some unnecessary
computations. :pr:`1193` by :user:`Jérôme Dockès <jeromedockes>`.

Expand Down
4 changes: 2 additions & 2 deletions skrub/_reporting/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def quantiles(column):

def ellide_string(s, max_len=30):
"""Shorten a string so it can be used as a plot axis title or label."""
if not isinstance(s, str):
return s
s = str(s)

# normalize whitespace
s = re.sub(r"\s+", " ", s)
if len(s) <= max_len:
Expand Down
12 changes: 11 additions & 1 deletion skrub/_reporting/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@pytest.mark.parametrize(
"s_in, s_out",
[
(1, 1),
(1, "1"),
("aa", "aa"),
("a\na", "a a"),
("a" * 70, "a" * 30 + "…\u200e"),
Expand Down Expand Up @@ -55,6 +55,16 @@ def test_ellide_string_empty():
assert _utils.ellide_string(" a", 1) == "…"


def test_ellide_non_string():
# non-regression for #1195: objects in columns must be converted to strings
# before elliding and plotting
class A:
def __repr__(self):
return "one\ntwo\nthree"

assert _utils.ellide_string(A()) == "one two three"


@pytest.mark.parametrize(
"n_in, n_out",
[
Expand Down

0 comments on commit dcb7f59

Please sign in to comment.