diff --git a/src/skore/project.py b/src/skore/project.py index 2a6cd3cf9..f9a5f62f3 100644 --- a/src/skore/project.py +++ b/src/skore/project.py @@ -1,5 +1,6 @@ """""" +import base64 import json from dataclasses import dataclass from typing import Any, List @@ -14,8 +15,7 @@ class Item: raw_class_name: str | None = None - -def transform(o: Any) -> Item: +def transform(o: Any) -> Item | None: """Transform an object into an item.""" try: serialized = json.dumps(o) @@ -44,11 +44,12 @@ def transform(o: Any) -> Item: raw_class_name="sklearn.base.BaseEstimator", serialized=json.dumps( { - "skops": skops.io.dumps(o).decode(), + "skops": base64.b64encode(skops.io.dumps(o)).decode("ascii"), "html": sklearn.utils.estimator_html_repr(o), } ), ) + return None class Project: diff --git a/tests/test_dataframe_item.py b/tests/test_dataframe_item.py deleted file mode 100644 index 95269400f..000000000 --- a/tests/test_dataframe_item.py +++ /dev/null @@ -1,10 +0,0 @@ -import pandas as pd -from skore.project import DataFrameItem - - -def test_dataframe_item(): - df = pd.DataFrame([[1, 2, 3], [4, 5, 6]]) - item = DataFrameItem(df) - - assert item.raw == df - assert item.transformed == None diff --git a/tests/unit/test_project.py b/tests/unit/test_project.py index a8fa77293..a8ebdbe70 100644 --- a/tests/unit/test_project.py +++ b/tests/unit/test_project.py @@ -1,8 +1,8 @@ import json -import pandas + import numpy +import pandas import sklearn.svm -import skops.io from skore.project import Item, transform @@ -37,7 +37,10 @@ def test_transform_numpy_ndarray(): assert actual == expected -def test_transform_sklearn_base_baseestimator(): +def test_transform_sklearn_base_baseestimator(monkeypatch): + monkeypatch.setattr("sklearn.utils.estimator_html_repr", lambda _: "") + monkeypatch.setattr("skops.io.dumps", lambda _: "") + o = sklearn.svm.SVC() actual = transform(o) expected = Item( @@ -45,8 +48,8 @@ def test_transform_sklearn_base_baseestimator(): raw_class_name="numpy.ndarray", serialized=json.dumps( { - "skops": skops.io.dumps(o).decode(), - "html": sklearn.utils.estimator_html_repr(o), + "skops": "", + "html": "", } ), )