Skip to content

Commit

Permalink
mob next [ci-skip] [ci skip] [skip ci]
Browse files Browse the repository at this point in the history
lastFile:tests/unit/test_project.py
  • Loading branch information
rouk1 committed Sep 9, 2024
1 parent cf63bef commit 373377b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/skore/project.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""""""

import base64
import json
from dataclasses import dataclass
from typing import Any, List
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 0 additions & 10 deletions tests/test_dataframe_item.py

This file was deleted.

13 changes: 8 additions & 5 deletions tests/unit/test_project.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
import pandas

import numpy
import pandas
import sklearn.svm
import skops.io
from skore.project import Item, transform


Expand Down Expand Up @@ -37,16 +37,19 @@ 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(
raw=o,
raw_class_name="numpy.ndarray",
serialized=json.dumps(
{
"skops": skops.io.dumps(o).decode(),
"html": sklearn.utils.estimator_html_repr(o),
"skops": "",
"html": "",
}
),
)
Expand Down

0 comments on commit 373377b

Please sign in to comment.