Skip to content

Commit 574dd64

Browse files
FIX - Proper escaping of special characters for data ops tooltips (#1764)
Co-authored-by: Jérôme Dockès <jerome@dockes.org>
1 parent 4c9846a commit 574dd64

4 files changed

Lines changed: 22 additions & 1 deletion

File tree

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ Bugfixes
7474
- Fixed an issue where :class:`TableReport` would fail when computing associations
7575
for Polars dataframes if PyArrow was not installed.
7676
:pr:`1742` by :user:`Riccardo Cappuzzo <rcap107>`.
77+
- Fixed an issue in the Data Ops report generation in cases where the DataOp
78+
contained escape characters or were spanning multiple lines.
79+
:pr:`1764` by :user:`Riccardo Cappuzzo <rcap107>`.
7780
- Added :meth:`get_feature_names_out` to :class:`Cleaner` for consistency with the
7881
:class:`TableVectorizer` and other transformers. :pr:`1762` by
7982
:user:`Riccardo Cappuzzo <rcap107>`.
@@ -84,7 +87,6 @@ Bugfixes
8487
``.skb.mark_as_y()`` used to raise an error, this has been fixed in :pr:`1782`
8588
by :user:`Jérôme Dockès <jeromedockes>`.
8689

87-
8890
Release 0.6.2
8991
=============
9092

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ exclude = [
261261
"doc/_build",
262262
"doc/auto_examples",
263263
"build",
264+
"pixi.lock"
264265
]
265266

266267
[tool.ruff.lint]

skrub/_data_ops/_inspection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ def _node_kwargs(data_op, url=None):
309309
tooltip = html.escape(data_op._skrub_impl.creation_stack_last_line())
310310
if description := data_op._skrub_impl.description:
311311
tooltip = f"{tooltip}\n\n{html.escape(description)}"
312+
# Also escape backslahses inserted in the .dot file
313+
# otherwise they are interpreted as escape sequences by graphviz
314+
tooltip = tooltip.replace("\\", "\\\\")
312315
kwargs["tooltip"] = tooltip
313316
if isinstance(data_op._skrub_impl, (Var, Value)):
314317
kwargs["peripheries"] = 2

skrub/tests/test_data_ops_stack_description.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from sklearn.preprocessing import FunctionTransformer
66

77
import skrub
8+
from skrub._data_ops import _inspection
89

910
# Those tests have to be outside of the `_data_ops` module (and thus out of
1011
# _data_ops/tests/, as we place the tests inside the package), because to
@@ -78,3 +79,17 @@ def test_apply_eval_failure(eval_data_op):
7879
r'^.*d = c\.skb\.apply\(FunctionTransformer\(lambda x: x \+ "string"\)\)',
7980
):
8081
eval_data_op(e, {"a": 1.0, "b": 2.0})
82+
83+
84+
@pytest.mark.skipif(not _inspection._has_graphviz(), reason="report requires graphviz")
85+
def test_escaping_characters():
86+
# fmt: off
87+
out = skrub.as_data_op("") + "\n" + '"' + "\t" +'\\ ' \
88+
'\t'
89+
# fmt: on
90+
g = out.skb.draw_graph()
91+
result = g.svg.decode("utf-8")
92+
assert (
93+
"""out = skrub.as_data_op(&quot;&quot;) + &quot;\\n&quot; """
94+
"""+ &#39;&quot;&#39; + &quot;\\t&quot; +&#39;\\ &#39; \\""" in result
95+
)

0 commit comments

Comments
 (0)