From 83747f759866deb7da818b1d45aefd629b5a2bf4 Mon Sep 17 00:00:00 2001 From: Thomas S Date: Wed, 8 Jan 2025 12:05:51 +0100 Subject: [PATCH] Squashed commit of the following: commit 86281ca475f59c2fa43760b243c366c23c38b787 Author: Auguste Baum Date: Wed Jan 8 12:00:46 2025 +0100 mob next [ci-skip] [ci skip] [skip ci] lastFile:skore/tests/integration/ui/test_ui.py commit 9f6f1931584de22ab08a9e4a9779a5f17dee4501 Author: Thomas S Date: Wed Jan 8 11:52:12 2025 +0100 mob next [ci-skip] [ci skip] [skip ci] lastFile:skore/tests/integration/ui/test_ui.py commit cd385f66a805390893a6e415761ab1c0ea65550e Author: Auguste Baum Date: Wed Jan 8 11:41:10 2025 +0100 mob next [ci-skip] [ci skip] [skip ci] lastFile:skore/src/skore/persistence/item/sklearn_base_estimator_item.py commit 41c53559266f139c785211fc97a43e1e2b281203 Author: Thomas S Date: Wed Jan 8 11:27:16 2025 +0100 mob next [ci-skip] [ci skip] [skip ci] lastFile:skore/tests/integration/sklearn/test_cross_validate.py commit a7d956edfeab6ef56020aaae8752e59f7f4e3491 Author: Auguste Baum Date: Wed Jan 8 11:14:59 2025 +0100 mob next [ci-skip] [ci skip] [skip ci] lastFile:skore/tests/unit/view/test_view_repository.py commit 38446cf8499b2d3bcf79d371b00e374a916dd77a Author: Thomas S Date: Wed Jan 8 11:01:43 2025 +0100 mob next [ci-skip] [ci skip] [skip ci] lastFile:skore/src/skore/persistence/item/pickle_item.py commit a6e2a7914ada1e003c5295ccf233c73238972dfc Author: Thomas S Date: Wed Jan 8 10:51:07 2025 +0100 mob start [ci-skip] [ci skip] [skip ci] # automatically added all co-authors from WIP commits # add missing co-authors manually Co-authored-by: Auguste Baum --- skore/src/skore/persistence/item/__init__.py | 5 +- .../persistence/item/cross_validation_item.py | 3 +- .../src/skore/persistence/item/media_item.py | 2 +- .../persistence/item/numpy_array_item.py | 2 +- .../persistence/item/pandas_dataframe_item.py | 2 +- .../persistence/item/pandas_series_item.py | 2 +- .../src/skore/persistence/item/pickle_item.py | 4 +- .../persistence/item/polars_dataframe_item.py | 2 +- .../persistence/item/polars_series_item.py | 2 +- .../skore/persistence/item/primitive_item.py | 2 +- .../item/sklearn_base_estimator_item.py | 7 ++- .../item/skrub_table_report_item.py | 4 +- .../skore/persistence/repository/__init__.py | 7 +++ .../persistence/repository/item_repository.py | 27 +++++----- .../src/skore/persistence/storage/__init__.py | 9 ++++ skore/src/skore/project/create.py | 2 +- skore/src/skore/project/load.py | 8 +-- skore/src/skore/project/project.py | 7 ++- skore/src/skore/ui/project_routes.py | 4 +- skore/tests/conftest.py | 5 +- .../sklearn/test_cross_validate.py | 4 +- skore/tests/integration/ui/test_ui.py | 51 ++++++++++++------- .../unit/item/test_cross_validation_item.py | 8 +-- skore/tests/unit/item/test_item_repository.py | 3 +- skore/tests/unit/item/test_media_item.py | 4 +- .../tests/unit/item/test_numpy_array_item.py | 4 +- .../unit/item/test_pandas_dataframe_item.py | 4 +- .../unit/item/test_pandas_series_item.py | 4 +- .../unit/item/test_polars_dataframe_item.py | 6 +-- .../unit/item/test_polars_series_item.py | 4 +- skore/tests/unit/item/test_primitive_item.py | 6 +-- .../item/test_sklearn_base_estimator_item.py | 4 +- .../unit/item/test_skrub_table_report_item.py | 4 +- skore/tests/unit/persistence/test_disk.py | 2 +- skore/tests/unit/persistence/test_memory.py | 2 +- skore/tests/unit/test_project.py | 20 ++++---- skore/tests/unit/view/test_view_repository.py | 6 +-- 37 files changed, 142 insertions(+), 100 deletions(-) create mode 100644 skore/src/skore/persistence/storage/__init__.py diff --git a/skore/src/skore/persistence/item/__init__.py b/skore/src/skore/persistence/item/__init__.py index 770ce5979..7b2d2f002 100644 --- a/skore/src/skore/persistence/item/__init__.py +++ b/skore/src/skore/persistence/item/__init__.py @@ -5,11 +5,9 @@ from contextlib import suppress from typing import Any -import skrub_table_report_item as SkrubTableReportItem - +from . import skrub_table_report_item as SkrubTableReportItem from .cross_validation_item import CrossValidationItem from .item import Item, ItemTypeError -from .item_repository import ItemRepository from .media_item import MediaItem from .numpy_array_item import NumpyArrayItem from .pandas_dataframe_item import PandasDataFrameItem @@ -72,7 +70,6 @@ def item_to_object(item: Item) -> Any: __all__ = [ "CrossValidationItem", "Item", - "ItemRepository", "MediaItem", "NumpyArrayItem", "PandasDataFrameItem", diff --git a/skore/src/skore/persistence/item/cross_validation_item.py b/skore/src/skore/persistence/item/cross_validation_item.py index e4e4c4a2a..1121117be 100644 --- a/skore/src/skore/persistence/item/cross_validation_item.py +++ b/skore/src/skore/persistence/item/cross_validation_item.py @@ -20,9 +20,10 @@ import plotly.graph_objects import plotly.io -from skore.item.item import Item, ItemTypeError from skore.sklearn.cross_validation import CrossValidationReporter +from .item import Item, ItemTypeError + if TYPE_CHECKING: import sklearn.base diff --git a/skore/src/skore/persistence/item/media_item.py b/skore/src/skore/persistence/item/media_item.py index b83de93e4..b0c957bd6 100644 --- a/skore/src/skore/persistence/item/media_item.py +++ b/skore/src/skore/persistence/item/media_item.py @@ -9,7 +9,7 @@ from io import BytesIO from typing import TYPE_CHECKING, Any -from skore.item.item import Item, ItemTypeError +from .item import Item, ItemTypeError if TYPE_CHECKING: from altair.vegalite.v5.schema.core import TopLevelSpec as Altair diff --git a/skore/src/skore/persistence/item/numpy_array_item.py b/skore/src/skore/persistence/item/numpy_array_item.py index 59d80bf66..5ebe0c82c 100644 --- a/skore/src/skore/persistence/item/numpy_array_item.py +++ b/skore/src/skore/persistence/item/numpy_array_item.py @@ -9,7 +9,7 @@ from json import dumps, loads from typing import TYPE_CHECKING -from skore.item.item import Item, ItemTypeError +from .item import Item, ItemTypeError if TYPE_CHECKING: import numpy diff --git a/skore/src/skore/persistence/item/pandas_dataframe_item.py b/skore/src/skore/persistence/item/pandas_dataframe_item.py index f61fef26c..3d124677e 100644 --- a/skore/src/skore/persistence/item/pandas_dataframe_item.py +++ b/skore/src/skore/persistence/item/pandas_dataframe_item.py @@ -9,7 +9,7 @@ from functools import cached_property from typing import TYPE_CHECKING -from skore.item.item import Item, ItemTypeError +from .item import Item, ItemTypeError if TYPE_CHECKING: import pandas diff --git a/skore/src/skore/persistence/item/pandas_series_item.py b/skore/src/skore/persistence/item/pandas_series_item.py index cd27ebea3..bfc52457c 100644 --- a/skore/src/skore/persistence/item/pandas_series_item.py +++ b/skore/src/skore/persistence/item/pandas_series_item.py @@ -9,7 +9,7 @@ from functools import cached_property from typing import TYPE_CHECKING -from skore.item.item import Item, ItemTypeError +from .item import Item, ItemTypeError if TYPE_CHECKING: import pandas diff --git a/skore/src/skore/persistence/item/pickle_item.py b/skore/src/skore/persistence/item/pickle_item.py index ce9019488..42a0ace5d 100644 --- a/skore/src/skore/persistence/item/pickle_item.py +++ b/skore/src/skore/persistence/item/pickle_item.py @@ -1,8 +1,10 @@ +from __future__ import annotations + from functools import cached_property from pickle import dumps, loads from typing import Any -from skore.item.item import Item +from .item import Item class PickleItem(Item): diff --git a/skore/src/skore/persistence/item/polars_dataframe_item.py b/skore/src/skore/persistence/item/polars_dataframe_item.py index d42292dbe..dc6b05533 100644 --- a/skore/src/skore/persistence/item/polars_dataframe_item.py +++ b/skore/src/skore/persistence/item/polars_dataframe_item.py @@ -9,7 +9,7 @@ from functools import cached_property from typing import TYPE_CHECKING -from skore.item.item import Item, ItemTypeError +from .item import Item, ItemTypeError if TYPE_CHECKING: import polars diff --git a/skore/src/skore/persistence/item/polars_series_item.py b/skore/src/skore/persistence/item/polars_series_item.py index 7d846f9a9..ba0dd3f8c 100644 --- a/skore/src/skore/persistence/item/polars_series_item.py +++ b/skore/src/skore/persistence/item/polars_series_item.py @@ -9,7 +9,7 @@ from functools import cached_property from typing import TYPE_CHECKING -from skore.item.item import Item, ItemTypeError +from .item import Item, ItemTypeError if TYPE_CHECKING: import polars diff --git a/skore/src/skore/persistence/item/primitive_item.py b/skore/src/skore/persistence/item/primitive_item.py index 3e7d1e1a5..039032312 100644 --- a/skore/src/skore/persistence/item/primitive_item.py +++ b/skore/src/skore/persistence/item/primitive_item.py @@ -7,7 +7,7 @@ from typing import TYPE_CHECKING -from skore.item.item import Item, ItemTypeError +from .item import Item, ItemTypeError if TYPE_CHECKING: from typing import Union diff --git a/skore/src/skore/persistence/item/sklearn_base_estimator_item.py b/skore/src/skore/persistence/item/sklearn_base_estimator_item.py index d40b61bba..40321970e 100644 --- a/skore/src/skore/persistence/item/sklearn_base_estimator_item.py +++ b/skore/src/skore/persistence/item/sklearn_base_estimator_item.py @@ -9,7 +9,7 @@ from functools import cached_property from typing import TYPE_CHECKING -from skore.item.item import Item, ItemTypeError +from .item import Item, ItemTypeError if TYPE_CHECKING: import sklearn.base @@ -101,11 +101,14 @@ def factory(cls, estimator: sklearn.base.BaseEstimator) -> SklearnBaseEstimatorI """ import sklearn.base import sklearn.utils - import skops.io if not isinstance(estimator, sklearn.base.BaseEstimator): raise ItemTypeError(f"Type '{estimator.__class__}' is not supported.") + # This line is only needed if we know `estimator` has the right type, so we do + # it after the type check + import skops.io + estimator_html_repr = sklearn.utils.estimator_html_repr(estimator) estimator_skops = skops.io.dumps(estimator) estimator_skops_untrusted_types = skops.io.get_untrusted_types( diff --git a/skore/src/skore/persistence/item/skrub_table_report_item.py b/skore/src/skore/persistence/item/skrub_table_report_item.py index b411256f2..07eae5bbd 100644 --- a/skore/src/skore/persistence/item/skrub_table_report_item.py +++ b/skore/src/skore/persistence/item/skrub_table_report_item.py @@ -4,8 +4,8 @@ from typing import TYPE_CHECKING -from skore.item.item import ItemTypeError -from skore.item.media_item import MediaItem +from .item import ItemTypeError +from .media_item import MediaItem if TYPE_CHECKING: from skrub import TableReport diff --git a/skore/src/skore/persistence/repository/__init__.py b/skore/src/skore/persistence/repository/__init__.py index e69de29bb..c088fdacf 100644 --- a/skore/src/skore/persistence/repository/__init__.py +++ b/skore/src/skore/persistence/repository/__init__.py @@ -0,0 +1,7 @@ +from .item_repository import ItemRepository +from .view_repository import ViewRepository + +__all__ = [ + "ItemRepository", + "ViewRepository", +] diff --git a/skore/src/skore/persistence/repository/item_repository.py b/skore/src/skore/persistence/repository/item_repository.py index 74210964f..aea849f80 100644 --- a/skore/src/skore/persistence/repository/item_repository.py +++ b/skore/src/skore/persistence/repository/item_repository.py @@ -8,20 +8,21 @@ from typing import TYPE_CHECKING +from skore.persistence.item import ( + CrossValidationItem, + MediaItem, + NumpyArrayItem, + PandasDataFrameItem, + PandasSeriesItem, + PolarsDataFrameItem, + PolarsSeriesItem, + PrimitiveItem, + SklearnBaseEstimatorItem, +) + if TYPE_CHECKING: - from skore.item.item import Item - from skore.persistence.abstract_storage import AbstractStorage - - -from skore.item.cross_validation_item import CrossValidationItem -from skore.item.media_item import MediaItem -from skore.item.numpy_array_item import NumpyArrayItem -from skore.item.pandas_dataframe_item import PandasDataFrameItem -from skore.item.pandas_series_item import PandasSeriesItem -from skore.item.polars_dataframe_item import PolarsDataFrameItem -from skore.item.polars_series_item import PolarsSeriesItem -from skore.item.primitive_item import PrimitiveItem -from skore.item.sklearn_base_estimator_item import SklearnBaseEstimatorItem + from skore.persistence.item import Item + from skore.persistence.storage import AbstractStorage class ItemRepository: diff --git a/skore/src/skore/persistence/storage/__init__.py b/skore/src/skore/persistence/storage/__init__.py new file mode 100644 index 000000000..21b6a3b1a --- /dev/null +++ b/skore/src/skore/persistence/storage/__init__.py @@ -0,0 +1,9 @@ +from .abstract_storage import AbstractStorage +from .disk_cache_storage import DiskCacheStorage +from .in_memory_storage import InMemoryStorage + +__all__ = [ + "AbstractStorage", + "DiskCacheStorage", + "InMemoryStorage", +] diff --git a/skore/src/skore/project/create.py b/skore/src/skore/project/create.py index bee8449d5..fcffce9d0 100644 --- a/skore/src/skore/project/create.py +++ b/skore/src/skore/project/create.py @@ -11,10 +11,10 @@ ProjectCreationError, ProjectPermissionError, ) +from skore.persistence.view.view import View from skore.project.load import load from skore.project.project import Project, logger from skore.utils._logger import logger_context -from skore.view.view import View def _validate_project_name(project_name: str) -> tuple[bool, Optional[Exception]]: diff --git a/skore/src/skore/project/load.py b/skore/src/skore/project/load.py index c78948690..0e8e7f064 100644 --- a/skore/src/skore/project/load.py +++ b/skore/src/skore/project/load.py @@ -3,10 +3,12 @@ from pathlib import Path from typing import Union -from skore.item import ItemRepository -from skore.persistence.disk_cache_storage import DirectoryDoesNotExist, DiskCacheStorage +from skore.persistence.repository import ItemRepository, ViewRepository +from skore.persistence.storage.disk_cache_storage import ( + DirectoryDoesNotExist, + DiskCacheStorage, +) from skore.project.project import Project -from skore.view.view_repository import ViewRepository class ProjectLoadError(Exception): diff --git a/skore/src/skore/project/project.py b/skore/src/skore/project/project.py index 299409425..3cca337f2 100644 --- a/skore/src/skore/project/project.py +++ b/skore/src/skore/project/project.py @@ -2,9 +2,10 @@ from __future__ import annotations +import logging from typing import TYPE_CHECKING, Any, Optional, Union -from skore.persistence import item_to_object, object_to_item +from skore.persistence.item import item_to_object, object_to_item if TYPE_CHECKING: from skore.persistence import ( @@ -15,6 +16,10 @@ ) +logger = logging.getLogger(__name__) +logger.addHandler(logging.NullHandler()) # Default to no output +logger.setLevel(logging.INFO) + MISSING = object() diff --git a/skore/src/skore/ui/project_routes.py b/skore/src/skore/ui/project_routes.py index 040e5dbca..79eff5ce6 100644 --- a/skore/src/skore/ui/project_routes.py +++ b/skore/src/skore/ui/project_routes.py @@ -9,9 +9,9 @@ from fastapi import APIRouter, HTTPException, Request, status -from skore.item import Item +from skore.persistence.item import Item +from skore.persistence.view.view import Layout, View from skore.project import Project -from skore.view.view import Layout, View router = APIRouter(prefix="/project") diff --git a/skore/tests/conftest.py b/skore/tests/conftest.py index 6b2e3e0ad..61642fb5b 100644 --- a/skore/tests/conftest.py +++ b/skore/tests/conftest.py @@ -1,10 +1,9 @@ from datetime import datetime, timezone import pytest -from skore.item.item_repository import ItemRepository -from skore.persistence.in_memory_storage import InMemoryStorage +from skore.persistence.repository import ItemRepository, ViewRepository +from skore.persistence.storage import InMemoryStorage from skore.project import Project -from skore.view.view_repository import ViewRepository @pytest.fixture diff --git a/skore/tests/integration/sklearn/test_cross_validate.py b/skore/tests/integration/sklearn/test_cross_validate.py index 8c8992728..e39f6ba58 100644 --- a/skore/tests/integration/sklearn/test_cross_validate.py +++ b/skore/tests/integration/sklearn/test_cross_validate.py @@ -10,7 +10,7 @@ from sklearn.multiclass import OneVsOneClassifier from sklearn.svm import SVC from skore import CrossValidationReporter -from skore.item.cross_validation_item import CrossValidationItem +from skore.persistence.item.cross_validation_item import CrossValidationItem from skore.sklearn.cross_validation.cross_validation_helpers import _get_scorers_to_add @@ -200,7 +200,7 @@ def test_cross_validation_reporter(in_memory_project, fixture_name, request): in_memory_project.put("cross-validation", reporter) - retrieved_item = in_memory_project.get_item("cross-validation") + retrieved_item = in_memory_project.item_repository.get_item("cross-validation") assert isinstance(retrieved_item, CrossValidationItem) diff --git a/skore/tests/integration/ui/test_ui.py b/skore/tests/integration/ui/test_ui.py index f467ff699..f5f984e26 100644 --- a/skore/tests/integration/ui/test_ui.py +++ b/skore/tests/integration/ui/test_ui.py @@ -1,7 +1,9 @@ import datetime +import json import numpy import pandas +import plotly import polars import pytest from fastapi.testclient import TestClient @@ -9,9 +11,8 @@ from sklearn.linear_model import Lasso from sklearn.model_selection import KFold from skore import CrossValidationReporter -from skore.item.media_item import MediaItem +from skore.persistence.view.view import View from skore.ui.app import create_app -from skore.view.view import View @pytest.fixture @@ -136,16 +137,12 @@ def test_serialize_media_item(client, in_memory_project): html = "

éપUœALDXIWDŸΩΩ

" in_memory_project.put("html", html) - in_memory_project.put_item( - "media html", MediaItem.factory_str(html, media_type="text/html") - ) response = client.get("/api/project/items") assert response.status_code == 200 project = response.json() assert "image" in project["items"]["img"][0]["media_type"] assert project["items"]["html"][0]["value"] == html - assert project["items"]["media html"][0]["value"] == html @pytest.fixture @@ -178,9 +175,21 @@ def test_serialize_cross_validation_item( mock_nowstr, fake_cross_validate, ): - monkeypatch.setattr("skore.item.item.datetime", MockDatetime) + monkeypatch.setattr("skore.persistence.item.item.datetime", MockDatetime) + monkeypatch.setattr( + "skore.persistence.item.cross_validation_item.CrossValidationItem.plots", {} + ) + monkeypatch.setattr( + "skore.sklearn.cross_validation.cross_validation_reporter.plot_cross_validation_compare_scores", + lambda _: {}, + ) + monkeypatch.setattr( + "skore.sklearn.cross_validation.cross_validation_reporter.plot_cross_validation_timing_normalized", + lambda _: {}, + ) monkeypatch.setattr( - "skore.item.cross_validation_item.CrossValidationItem.plots", {} + "skore.sklearn.cross_validation.cross_validation_reporter.plot_cross_validation_timing", + lambda _: {}, ) def prepare_cv(): @@ -196,17 +205,12 @@ def prepare_cv(): reporter = CrossValidationReporter(model, X, y, cv=KFold(3)) in_memory_project.put("cv", reporter) - # Mock the item to make the plot empty - item = in_memory_project.get_item("cv") - item.plots_bytes = {"compare_scores": b"{}"} - in_memory_project.put_item("cv_mocked", item) - response = client.get("/api/project/items") assert response.status_code == 200 project = response.json() expected = { - "name": "cv_mocked", + "name": "cv", "media_type": "application/vnd.skore.cross_validation+json", "value": { "scalar_results": [ @@ -227,7 +231,20 @@ def prepare_cv(): ], } ], - "plots": [{"name": "compare_scores", "value": {}}], + "plots": [ + { + "name": "Scores", + "value": json.loads(plotly.io.to_json({}, engine="json")), + }, + { + "name": "Timings", + "value": json.loads(plotly.io.to_json({}, engine="json")), + }, + { + "name": "Normalized timings", + "value": json.loads(plotly.io.to_json({}, engine="json")), + }, + ], "sections": [ { "title": "Model", @@ -266,7 +283,7 @@ def prepare_cv(): "updated_at": mock_nowstr, "created_at": mock_nowstr, } - actual = project["items"]["cv_mocked"][0] + actual = project["items"]["cv"][0] assert expected == actual @@ -282,7 +299,7 @@ def now(*args, **kwargs): MockDatetime.NOW += MockDatetime.TIMEDELTA return MockDatetime.NOW - monkeypatch.setattr("skore.item.item.datetime", MockDatetime) + monkeypatch.setattr("skore.persistence.item.item.datetime", MockDatetime) for i in range(5): in_memory_project.put(str(i), i) diff --git a/skore/tests/unit/item/test_cross_validation_item.py b/skore/tests/unit/item/test_cross_validation_item.py index 6ee82a3a7..af691fc06 100644 --- a/skore/tests/unit/item/test_cross_validation_item.py +++ b/skore/tests/unit/item/test_cross_validation_item.py @@ -4,9 +4,9 @@ import plotly.graph_objects import pytest from sklearn.model_selection import StratifiedKFold -from skore.item.cross_validation_item import ( +from skore.persistence.item import ItemTypeError +from skore.persistence.item.cross_validation_item import ( CrossValidationItem, - ItemTypeError, _hash_numpy, ) from skore.sklearn.cross_validation import CrossValidationReporter @@ -67,7 +67,7 @@ class FakeCrossValidationReporterNoGetParams(CrossValidationReporter): class TestCrossValidationItem: @pytest.fixture(autouse=True) def monkeypatch_datetime(self, monkeypatch, MockDatetime): - monkeypatch.setattr("skore.item.item.datetime", MockDatetime) + monkeypatch.setattr("skore.persistence.item.item.datetime", MockDatetime) def test_factory_exception(self): with pytest.raises(ItemTypeError): @@ -111,7 +111,7 @@ def test_factory(self, mock_nowstr, reporter): def test_get_serializable_dict(self, monkeypatch, mock_nowstr): monkeypatch.setattr( - "skore.item.cross_validation_item.CrossValidationReporter", + "skore.persistence.item.cross_validation_item.CrossValidationReporter", FakeCrossValidationReporter, ) diff --git a/skore/tests/unit/item/test_item_repository.py b/skore/tests/unit/item/test_item_repository.py index 79b93548d..b2672bd30 100644 --- a/skore/tests/unit/item/test_item_repository.py +++ b/skore/tests/unit/item/test_item_repository.py @@ -1,7 +1,8 @@ from datetime import datetime, timezone import pytest -from skore.item import ItemRepository, MediaItem +from skore.persistence.item import MediaItem +from skore.persistence.repository import ItemRepository class TestItemRepository: diff --git a/skore/tests/unit/item/test_media_item.py b/skore/tests/unit/item/test_media_item.py index 97d4b579e..024f2fb5a 100644 --- a/skore/tests/unit/item/test_media_item.py +++ b/skore/tests/unit/item/test_media_item.py @@ -5,13 +5,13 @@ import PIL as pillow import plotly.graph_objects as go import pytest -from skore.item import ItemTypeError, MediaItem +from skore.persistence.item import ItemTypeError, MediaItem class TestMediaItem: @pytest.fixture(autouse=True) def monkeypatch_datetime(self, monkeypatch, MockDatetime): - monkeypatch.setattr("skore.item.item.datetime", MockDatetime) + monkeypatch.setattr("skore.persistence.item.item.datetime", MockDatetime) def test_factory_exception(self): with pytest.raises(ItemTypeError): diff --git a/skore/tests/unit/item/test_numpy_array_item.py b/skore/tests/unit/item/test_numpy_array_item.py index a793cfed1..ed1c29317 100644 --- a/skore/tests/unit/item/test_numpy_array_item.py +++ b/skore/tests/unit/item/test_numpy_array_item.py @@ -2,13 +2,13 @@ import numpy import pytest -from skore.item import ItemTypeError, NumpyArrayItem +from skore.persistence.item import ItemTypeError, NumpyArrayItem class TestNumpyArrayItem: @pytest.fixture(autouse=True) def monkeypatch_datetime(self, monkeypatch, MockDatetime): - monkeypatch.setattr("skore.item.item.datetime", MockDatetime) + monkeypatch.setattr("skore.persistence.item.item.datetime", MockDatetime) def test_factory_exception(self): with pytest.raises(ItemTypeError): diff --git a/skore/tests/unit/item/test_pandas_dataframe_item.py b/skore/tests/unit/item/test_pandas_dataframe_item.py index da9b8f80a..2b6b0edf9 100644 --- a/skore/tests/unit/item/test_pandas_dataframe_item.py +++ b/skore/tests/unit/item/test_pandas_dataframe_item.py @@ -2,13 +2,13 @@ import pytest from pandas import DataFrame, Index, MultiIndex from pandas.testing import assert_frame_equal -from skore.item import ItemTypeError, PandasDataFrameItem +from skore.persistence.item import ItemTypeError, PandasDataFrameItem class TestPandasDataFrameItem: @pytest.fixture(autouse=True) def monkeypatch_datetime(self, monkeypatch, MockDatetime): - monkeypatch.setattr("skore.item.item.datetime", MockDatetime) + monkeypatch.setattr("skore.persistence.item.item.datetime", MockDatetime) def test_factory_exception(self): with pytest.raises(ItemTypeError): diff --git a/skore/tests/unit/item/test_pandas_series_item.py b/skore/tests/unit/item/test_pandas_series_item.py index eb160f765..4a2e396ac 100644 --- a/skore/tests/unit/item/test_pandas_series_item.py +++ b/skore/tests/unit/item/test_pandas_series_item.py @@ -2,13 +2,13 @@ import pytest from pandas import Index, MultiIndex, Series from pandas.testing import assert_series_equal -from skore.item import ItemTypeError, PandasSeriesItem +from skore.persistence.item import ItemTypeError, PandasSeriesItem class TestPandasSeriesItem: @pytest.fixture(autouse=True) def monkeypatch_datetime(self, monkeypatch, MockDatetime): - monkeypatch.setattr("skore.item.item.datetime", MockDatetime) + monkeypatch.setattr("skore.persistence.item.item.datetime", MockDatetime) def test_factory_exception(self): with pytest.raises(ItemTypeError): diff --git a/skore/tests/unit/item/test_polars_dataframe_item.py b/skore/tests/unit/item/test_polars_dataframe_item.py index 8be5250fc..0335e7d06 100644 --- a/skore/tests/unit/item/test_polars_dataframe_item.py +++ b/skore/tests/unit/item/test_polars_dataframe_item.py @@ -2,14 +2,14 @@ import pytest from polars import DataFrame from polars.testing import assert_frame_equal -from skore.item import ItemTypeError, PolarsDataFrameItem -from skore.item.polars_dataframe_item import PolarsToJSONError +from skore.persistence.item import ItemTypeError, PolarsDataFrameItem +from skore.persistence.item.polars_dataframe_item import PolarsToJSONError class TestPolarsDataFrameItem: @pytest.fixture(autouse=True) def monkeypatch_datetime(self, monkeypatch, MockDatetime): - monkeypatch.setattr("skore.item.item.datetime", MockDatetime) + monkeypatch.setattr("skore.persistence.item.item.datetime", MockDatetime) def test_factory_exception(self): with pytest.raises(ItemTypeError): diff --git a/skore/tests/unit/item/test_polars_series_item.py b/skore/tests/unit/item/test_polars_series_item.py index 8ca235c41..1e40a0c3f 100644 --- a/skore/tests/unit/item/test_polars_series_item.py +++ b/skore/tests/unit/item/test_polars_series_item.py @@ -2,13 +2,13 @@ import pytest from polars import Series from polars.testing import assert_series_equal -from skore.item import ItemTypeError, PolarsSeriesItem +from skore.persistence.item import ItemTypeError, PolarsSeriesItem class TestPolarsSeriesItem: @pytest.fixture(autouse=True) def monkeypatch_datetime(self, monkeypatch, MockDatetime): - monkeypatch.setattr("skore.item.item.datetime", MockDatetime) + monkeypatch.setattr("skore.persistence.item.item.datetime", MockDatetime) def test_factory_exception(self): with pytest.raises(ItemTypeError): diff --git a/skore/tests/unit/item/test_primitive_item.py b/skore/tests/unit/item/test_primitive_item.py index 2a97f6eff..babcdf2b8 100644 --- a/skore/tests/unit/item/test_primitive_item.py +++ b/skore/tests/unit/item/test_primitive_item.py @@ -1,5 +1,5 @@ import pytest -from skore.item import ItemTypeError, PrimitiveItem +from skore.persistence.item import ItemTypeError, PrimitiveItem class TestPrimitiveItem: @@ -16,7 +16,7 @@ class TestPrimitiveItem: ], ) def test_factory(self, monkeypatch, mock_nowstr, MockDatetime, primitive): - monkeypatch.setattr("skore.item.item.datetime", MockDatetime) + monkeypatch.setattr("skore.persistence.item.item.datetime", MockDatetime) item = PrimitiveItem.factory(primitive) @@ -43,7 +43,7 @@ def test_factory_exception(self): def test_get_serializable_dict( self, monkeypatch, mock_nowstr, MockDatetime, primitive ): - monkeypatch.setattr("skore.item.item.datetime", MockDatetime) + monkeypatch.setattr("skore.persistence.item.item.datetime", MockDatetime) item = PrimitiveItem.factory(primitive) serializable = item.as_serializable_dict() diff --git a/skore/tests/unit/item/test_sklearn_base_estimator_item.py b/skore/tests/unit/item/test_sklearn_base_estimator_item.py index 469a705bc..d0cbe93cf 100644 --- a/skore/tests/unit/item/test_sklearn_base_estimator_item.py +++ b/skore/tests/unit/item/test_sklearn_base_estimator_item.py @@ -1,7 +1,7 @@ import pytest import sklearn.svm import skops.io -from skore.item import ItemTypeError, SklearnBaseEstimatorItem +from skore.persistence.item import ItemTypeError, SklearnBaseEstimatorItem class Estimator(sklearn.svm.SVC): @@ -11,7 +11,7 @@ class Estimator(sklearn.svm.SVC): class TestSklearnBaseEstimatorItem: @pytest.fixture(autouse=True) def monkeypatch_datetime(self, monkeypatch, MockDatetime): - monkeypatch.setattr("skore.item.item.datetime", MockDatetime) + monkeypatch.setattr("skore.persistence.item.item.datetime", MockDatetime) def test_factory_exception(self): with pytest.raises(ItemTypeError): diff --git a/skore/tests/unit/item/test_skrub_table_report_item.py b/skore/tests/unit/item/test_skrub_table_report_item.py index eef317096..d35236166 100644 --- a/skore/tests/unit/item/test_skrub_table_report_item.py +++ b/skore/tests/unit/item/test_skrub_table_report_item.py @@ -1,12 +1,12 @@ import pytest from pandas import DataFrame -from skore.item import ItemTypeError, SkrubTableReportItem +from skore.persistence.item import ItemTypeError, SkrubTableReportItem from skrub import TableReport class TestSkrubTableReportItem: def test_factory(self, monkeypatch, mock_nowstr, MockDatetime): - monkeypatch.setattr("skore.item.item.datetime", MockDatetime) + monkeypatch.setattr("skore.persistence.item.item.datetime", MockDatetime) monkeypatch.setattr("secrets.token_hex", lambda: "azertyuiop") df = DataFrame(dict(a=[1, 2], b=["one", "two"], c=[11.1, 11.1])) diff --git a/skore/tests/unit/persistence/test_disk.py b/skore/tests/unit/persistence/test_disk.py index 77838978e..7c747c400 100644 --- a/skore/tests/unit/persistence/test_disk.py +++ b/skore/tests/unit/persistence/test_disk.py @@ -2,7 +2,7 @@ import shutil from pathlib import Path -from skore.persistence.disk_cache_storage import DiskCacheStorage +from skore.persistence.storage import DiskCacheStorage def test_disk_storage(tmp_path: Path): diff --git a/skore/tests/unit/persistence/test_memory.py b/skore/tests/unit/persistence/test_memory.py index f28dcc73d..53608496e 100644 --- a/skore/tests/unit/persistence/test_memory.py +++ b/skore/tests/unit/persistence/test_memory.py @@ -1,4 +1,4 @@ -from skore.persistence.in_memory_storage import InMemoryStorage +from skore.persistence.storage import InMemoryStorage def test_in_memory_storage(): diff --git a/skore/tests/unit/test_project.py b/skore/tests/unit/test_project.py index 88b256e54..662ed5e90 100644 --- a/skore/tests/unit/test_project.py +++ b/skore/tests/unit/test_project.py @@ -17,6 +17,7 @@ ProjectAlreadyExistsError, ProjectCreationError, ) +from skore.persistence.view.view import View from skore.project import ( Project, create, @@ -24,7 +25,6 @@ ) from skore.project.create import _validate_project_name from skore.project.load import ProjectLoadError -from skore.view.view import View def test_put_string_item(in_memory_project): @@ -262,17 +262,15 @@ def test_put_several_nested(in_memory_project): assert in_memory_project.get("a") == {"b": "baz"} -def test_put_several_error(in_memory_project): - """If some key-value pairs are wrong, add all that are valid and print a warning.""" - with pytest.raises(NotImplementedError): - in_memory_project.put( - { - "a": "foo", - "b": (lambda: "unsupported object"), - } - ) +def test_put_several_lambda(in_memory_project): + in_memory_project.put( + { + "a": "foo", + "b": (lambda: "unsupported object"), + } + ) - assert in_memory_project.list_item_keys() == ["a"] + assert in_memory_project.list_item_keys() == ["a", "b"] def test_put_key_is_a_tuple(in_memory_project): diff --git a/skore/tests/unit/view/test_view_repository.py b/skore/tests/unit/view/test_view_repository.py index ed46d271d..87c21cea1 100644 --- a/skore/tests/unit/view/test_view_repository.py +++ b/skore/tests/unit/view/test_view_repository.py @@ -1,7 +1,7 @@ import pytest -from skore.persistence.in_memory_storage import InMemoryStorage -from skore.view.view import View -from skore.view.view_repository import ViewRepository +from skore.persistence.repository import ViewRepository +from skore.persistence.storage import InMemoryStorage +from skore.persistence.view.view import View @pytest.fixture