diff --git a/skore/src/skore/sklearn/_base.py b/skore/src/skore/sklearn/_base.py index f09410f6a..bd043023b 100644 --- a/skore/src/skore/sklearn/_base.py +++ b/skore/src/skore/sklearn/_base.py @@ -70,10 +70,17 @@ def help(self): console.print(self._create_help_panel()) - def __repr__(self): + def _rich_repr(self, class_name, help_method_name): """Return a string representation using rich.""" console = Console(file=StringIO(), force_terminal=False) - console.print(self._create_help_panel()) + console.print( + Panel( + f"Get guidance using the {help_method_name} method", + title=f"[cyan]{class_name}[/cyan]", + border_style="orange1", + expand=False, + ) + ) return console.file.getvalue() diff --git a/skore/src/skore/sklearn/_estimator/metrics_accessor.py b/skore/src/skore/sklearn/_estimator/metrics_accessor.py index 1dd3bf695..fc741b672 100644 --- a/skore/src/skore/sklearn/_estimator/metrics_accessor.py +++ b/skore/src/skore/sklearn/_estimator/metrics_accessor.py @@ -819,6 +819,13 @@ def _get_help_legend(self): def _get_help_tree_title(self): return "[bold cyan]reporter.metrics[/bold cyan]" + def __repr__(self): + """Return a string representation using rich.""" + return self._rich_repr( + class_name="skore.EstimatorReport.metrics", + help_method_name="reporter.metrics.help()", + ) + ######################################################################################## # Sub-accessors @@ -1096,3 +1103,10 @@ def _get_help_panel_title(self): def _get_help_tree_title(self): return "[bold cyan]reporter.metrics.plot[/bold cyan]" + + def __repr__(self): + """Return a string representation using rich.""" + return self._rich_repr( + class_name="skore.EstimatorReport.metrics.plot", + help_method_name="reporter.metrics.plot.help()", + ) diff --git a/skore/src/skore/sklearn/_estimator/report.py b/skore/src/skore/sklearn/_estimator/report.py index 2b977715a..fdd19b84a 100644 --- a/skore/src/skore/sklearn/_estimator/report.py +++ b/skore/src/skore/sklearn/_estimator/report.py @@ -255,3 +255,9 @@ def estimator_name(self): else: name = self._estimator.__class__.__name__ return name + + def __repr__(self): + """Return a string representation using rich.""" + return self._rich_repr( + class_name="skore.EstimatorReport", help_method_name="reporter.help()" + ) diff --git a/skore/tests/unit/sklearn/test_estimator.py b/skore/tests/unit/sklearn/test_estimator.py index 4e0e6e4c2..faef7d711 100644 --- a/skore/tests/unit/sklearn/test_estimator.py +++ b/skore/tests/unit/sklearn/test_estimator.py @@ -285,7 +285,7 @@ def test_estimator_report_repr(binary_classification_data): report = EstimatorReport(estimator, X_test=X_test, y_test=y_test) repr_str = repr(report) - assert f"📓 Tools to diagnose estimator {estimator.__class__.__name__}" in repr_str + assert "skore.EstimatorReport" in repr_str @pytest.mark.parametrize( @@ -344,7 +344,7 @@ def test_estimator_report_plot_repr(binary_classification_data): report = EstimatorReport(estimator, X_test=X_test, y_test=y_test) repr_str = repr(report.metrics.plot) - assert "🎨 Available plot methods" in repr_str + assert "skore.EstimatorReport.metrics.plot" in repr_str def test_estimator_report_plot_roc(binary_classification_data): @@ -483,7 +483,7 @@ def test_estimator_report_metrics_repr(binary_classification_data): report = EstimatorReport(estimator, X_test=X_test, y_test=y_test) repr_str = repr(report.metrics) - assert "📏 Available metrics methods" in repr_str + assert "skore.EstimatorReport.metrics" in repr_str @pytest.mark.parametrize(