Skip to content

Commit 6ecf8d0

Browse files
Feat: Add title to report (#1654)
Co-authored-by: Riccardo Cappuzzo <7548232+rcap107@users.noreply.github.com> Co-authored-by: Riccardo Cappuzzo <riccardo.cappuzzo@gmail.com>
1 parent b29f2b8 commit 6ecf8d0

6 files changed

Lines changed: 31 additions & 3 deletions

File tree

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ New features
2626
environments produced by a CV splitter -- similar to
2727
:meth:`DataOp.skb.train_test_split` but for multiple cross-validation splits.
2828
:pr:`1653` by :user:`Jérôme Dockès <jeromedockes>`.
29+
- :meth:`DataOp.skb.full_report` now accepts a new parameter, title, that is displayed
30+
in the html report.
31+
:pr:`1654` by :user:`Marie Sacksick <MarieSacksick>`.
2932

3033
Changes
3134
-------

doc/modules/data_ops/ml_pipeline/evaluating_debugging_data_ops.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ Evaluating and debugging the DataOps plan with :meth:`.skb.full_report() <DataOp
66

77
All operations on DataOps are recorded in a computational graph, which can be
88
inspected with :meth:`.skb.full_report() <DataOp.skb.full_report>`. This method
9-
generates a html report that shows the full plan, including all nodes,
10-
their names, descriptions, and the transformations applied to the data.
9+
generates a html report that shows the full plan, including all nodes, their names,
10+
descriptions, and the transformations applied to the data. It is possible to give a
11+
title to the evaluation report this way:
12+
``my_data_op.skb.full_report(title="my title")``.
1113

1214
An example of the report can be found
1315
`here <../../../_static/credit_fraud_report/index.html>`_.

skrub/_data_ops/_inspection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def full_report(
119119
open=True,
120120
output_dir=None,
121121
overwrite=False,
122+
title=None,
122123
):
123124
if clear:
124125
clear_results(data_op, mode)
@@ -130,6 +131,7 @@ def full_report(
130131
open=open,
131132
output_dir=output_dir,
132133
overwrite=overwrite,
134+
title=title,
133135
)
134136
finally:
135137
if clear:
@@ -143,6 +145,7 @@ def _make_full_report(
143145
open=True,
144146
output_dir=None,
145147
overwrite=False,
148+
title=None,
146149
):
147150
_check_graphviz()
148151
output_dir = _get_output_dir(output_dir, overwrite)
@@ -168,7 +171,7 @@ def make_url(node):
168171
svg = draw_data_op_graph(data_op, url=make_url).svg.decode("utf-8")
169172
jinja_env = _get_jinja_env()
170173
index = jinja_env.get_template("index.html").render(
171-
{"svg": svg, "node_status": node_status}
174+
{"svg": svg, "node_status": node_status, "title": title}
172175
)
173176
index_file = output_dir / "index.html"
174177
index_file.write_text(index, "utf-8")

skrub/_data_ops/_skrub_namespace.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,7 @@ def full_report(
14661466
open=True,
14671467
output_dir=None,
14681468
overwrite=False,
1469+
title=None,
14691470
):
14701471
"""Generate a full report of the DataOp's evaluation.
14711472
@@ -1492,6 +1493,10 @@ def full_report(
14921493
What to do if the output directory already exists. If
14931494
``overwrite``, replace it, otherwise raise an exception.
14941495
1496+
title: str (default=None)
1497+
Title to display at the top of the report. If ``None``, no title will be
1498+
displayed.
1499+
14951500
Returns
14961501
-------
14971502
dict
@@ -1568,6 +1573,7 @@ def full_report(
15681573
open=open,
15691574
output_dir=output_dir,
15701575
overwrite=overwrite,
1576+
title=title,
15711577
)
15721578

15731579
def make_learner(self, *, fitted=False, keep_subsampling=False):

skrub/_data_ops/tests/test_inspection.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ def test_full_report():
6060
assert "This step did not run" in (out / "node_4.html").read_text("utf-8")
6161

6262

63+
@pytest.mark.skipif(not _inspection._has_graphviz(), reason="report requires graphviz")
64+
def test_full_report_title():
65+
# TODO we should have a private function that returns the JSON data so we
66+
# can check the content before rendering with jinja
67+
# however that requires first settling on the content of the report etc.
68+
data_op = skrub.var("a", 1)
69+
title = "small data ops"
70+
report = data_op.skb.full_report(open=False, title=title)
71+
assert title in report["report_path"].read_text("utf-8")
72+
73+
6374
@pytest.mark.skipif(not _inspection._has_graphviz(), reason="report requires graphviz")
6475
def test_preview_subsample():
6576
X = datasets.fetch_employee_salaries().X

skrub/_reporting/_data/templates/data_ops/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
</head>
1212

1313
<body>
14+
{% if title %}
15+
<h1>{{ title }}</h1>
16+
{% endif %}
1417
<p>
1518
Click on a node to display more information.
1619
</p>

0 commit comments

Comments
 (0)