Skip to content

Commit 1b01c52

Browse files
jeromedockesrcap107
authored andcommitted
show transformed data not dataop itself in fit report (#1623)
1 parent 79293a0 commit 1b01c52

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Bugfixes
5050
(not into their subclasses). If you need the items evaluated (ie if they
5151
contain DataOps or Choices), store them in one of the builtin collections.
5252
:pr:`1612` by :user:`Jérôme Dockès <jeromedockes>`.
53+
- :meth:`SkrubLearner.report` with ``mode="fit"`` used to display the dataops
54+
themselves, rather than their outputs, in the report. This has been fixed in
55+
:pr:`1623` by :user:`Jérôme Dockès <jeromedockes>`.
5356
- Fixed a bug that happened when ``get_feature_names_out`` was called on instances
5457
of the :class:`DatetimeEncoder`. :pr:`1622` by :user:`Riccardo Cappuzzo<rcap107>`.
5558

skrub/_data_ops/_evaluation.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,9 @@ def evaluate(data_op, mode="preview", environment=None, clear=False, callbacks=(
444444
else:
445445
callbacks = ()
446446
try:
447-
result = _Evaluator(
448-
mode=mode, environment=environment, callbacks=callbacks
449-
).run(data_op)
450-
return data_op if mode == "fit" else result
447+
return _Evaluator(mode=mode, environment=environment, callbacks=callbacks).run(
448+
data_op
449+
)
451450
finally:
452451
if clear:
453452
clear_results(data_op, mode=mode)

skrub/_data_ops/tests/test_evaluation.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,12 @@ class Dict(dict):
382382

383383
d = Dict()
384384
assert skrub.as_data_op(d).skb.eval() is d
385+
386+
387+
def test_eval_fit():
388+
# evaluate() does no special handling of "fit" mode.
389+
# the learner's fit() discards the result and returns self.
390+
dop = skrub.as_data_op(1)
391+
assert _evaluation.evaluate(dop, mode="fit") == 1
392+
learner = dop.skb.make_learner()
393+
assert learner.fit({}) is learner

skrub/_data_ops/tests/test_inspection.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import sys
44
import webbrowser
5+
from pathlib import Path
56
from unittest.mock import Mock
67

78
import pytest
@@ -84,6 +85,25 @@ def test_full_report_failed_apply():
8485
assert report["error"] is not None
8586

8687

88+
@pytest.mark.skipif(not _inspection._has_graphviz(), reason="report requires graphviz")
89+
def test_report_fit_mode():
90+
# non-regression: in fit mode the individual node pages used to show the
91+
# dataop itself as the output instead of the result of fit_transform for
92+
# intermediate nodes.
93+
learner = (
94+
skrub.var("a")
95+
.skb.apply_func(lambda x: x[::-1])
96+
.skb.apply_func(lambda x: x.upper())
97+
.skb.make_learner()
98+
)
99+
report = learner.report(environment={"a": "hello"}, mode="fit", open=False)
100+
report_dir = Path(report["report_path"]).parent
101+
node_1_report = (report_dir / "node_1.html").read_text("utf-8")
102+
# the page does display the actual output rather than the repr of the node
103+
# ('hello'[::-1] = 'olleh')
104+
assert "olleh" in node_1_report
105+
106+
87107
@pytest.mark.skipif(not _inspection._has_graphviz(), reason="report requires graphviz")
88108
def test_full_report_open(monkeypatch):
89109
mock = Mock()

0 commit comments

Comments
 (0)