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
thomass-dev committed Sep 11, 2024
1 parent edbc62b commit d8e54c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/skore/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def serialize(o: Any) -> Item:
return Item(
raw=o,
item_type=ItemType.MEDIA,
serialized=output.getvalue(),
serialized=base64.b64encode(output.getvalue()).decode("ascii"),
media_type="image/jpeg",
)

Expand Down
19 changes: 18 additions & 1 deletion tests/unit/test_project.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import base64
import json
from io import BytesIO

import altair
import numpy
Expand Down Expand Up @@ -181,10 +183,25 @@ def savefig(*args, **kwargs):
pil_image = Image.new("RGB", (100, 100), color="red")
project.put("pil_image", pil_image) # MediaItem (PNG)

with BytesIO() as output:
pil_image.save(output, format="jpeg")
pil_image_str = base64.b64encode(output.getvalue()).decode("ascii")

# Add raw bytes with media type
# raw_bytes = b"Some raw data"
# project.put_item("raw_data", MediaItem(raw_bytes, "application/octet-stream"))

# mybytes = b""
# project.put_item(
# "mybytes",
# Item(
# raw=mybytes,
# item_type=ItemType.MEDIA,
# media_type="application/octet-stream",
# serialized=mybytes.decode()
# )
# )

# Add a scikit-learn model
model = RandomForestClassifier()
model.fit(numpy.array([[1, 2], [3, 4]]), [0, 1])
Expand Down Expand Up @@ -248,7 +265,7 @@ def savefig(*args, **kwargs):
},
"pil_image": {
"item_type": str(ItemType.MEDIA),
"serialized": "",
"serialized": pil_image_str,
"media_type": "image/jpeg",
},
}
Expand Down

0 comments on commit d8e54c3

Please sign in to comment.