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 better display of object columns with multi-line repr in tablereport #1196

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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
Loading