Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ repos:
name: mypy skore-hub-project/
files: ^skore-hub-project/
args: [--config-file=skore-hub-project/pyproject.toml, skore-hub-project]
additional_dependencies: [skore, blake3, httpx, orjson, pydantic]
additional_dependencies: [skore, blake3, httpx, orjson, pandas-stubs, pydantic]
- id: mypy
pass_filenames: false
alias: mypy-skore-local-project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ numpy==2.2.6
# contourpy
# matplotlib
# pandas
# pandas-stubs
# scikit-learn
# scipy
# seaborn
Expand All @@ -124,6 +125,8 @@ pandas==2.3.3
# seaborn
# skore
# skrub
pandas-stubs==2.3.2.250926
# via skore-hub-project (skore-hub-project/pyproject.toml)
parso==0.8.5
# via jedi
pexpect==4.9.0
Expand Down Expand Up @@ -232,6 +235,8 @@ traitlets==5.14.3
# ipython
# ipywidgets
# matplotlib-inline
types-pytz==2025.2.0.20250809
# via pandas-stubs
typing-extensions==4.15.0
# via
# anyio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ numpy==2.2.6
# contourpy
# matplotlib
# pandas
# pandas-stubs
# scikit-learn
# scipy
# seaborn
Expand All @@ -124,6 +125,8 @@ pandas==2.3.3
# seaborn
# skore
# skrub
pandas-stubs==2.3.2.250926
# via skore-hub-project (skore-hub-project/pyproject.toml)
parso==0.8.5
# via jedi
pexpect==4.9.0
Expand Down Expand Up @@ -232,6 +235,8 @@ traitlets==5.14.3
# ipython
# ipywidgets
# matplotlib-inline
types-pytz==2025.2.0.20250809
# via pandas-stubs
typing-extensions==4.15.0
# via
# anyio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ numpy==2.3.4
# contourpy
# matplotlib
# pandas
# pandas-stubs
# scikit-learn
# scipy
# seaborn
Expand All @@ -121,6 +122,8 @@ pandas==2.3.3
# seaborn
# skore
# skrub
pandas-stubs==2.3.2.250926
# via skore-hub-project (skore-hub-project/pyproject.toml)
parso==0.8.5
# via jedi
pexpect==4.9.0
Expand Down Expand Up @@ -228,6 +231,8 @@ traitlets==5.14.3
# ipython
# ipywidgets
# matplotlib-inline
types-pytz==2025.2.0.20250809
# via pandas-stubs
typing-extensions==4.15.0
# via
# anyio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ numpy==2.3.4
# contourpy
# matplotlib
# pandas
# pandas-stubs
# scikit-learn
# scipy
# seaborn
Expand All @@ -121,6 +122,8 @@ pandas==2.3.3
# seaborn
# skore
# skrub
pandas-stubs==2.3.2.250926
# via skore-hub-project (skore-hub-project/pyproject.toml)
parso==0.8.5
# via jedi
pexpect==4.9.0
Expand Down Expand Up @@ -228,6 +231,8 @@ traitlets==5.14.3
# ipython
# ipywidgets
# matplotlib-inline
types-pytz==2025.2.0.20250809
# via pandas-stubs
typing-extensions==4.15.0
# via
# anyio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ numpy==2.3.4
# contourpy
# matplotlib
# pandas
# pandas-stubs
# scikit-learn
# scipy
# seaborn
Expand All @@ -121,6 +122,8 @@ pandas==2.3.3
# seaborn
# skore
# skrub
pandas-stubs==2.3.2.250926
# via skore-hub-project (skore-hub-project/pyproject.toml)
parso==0.8.5
# via jedi
pexpect==4.9.0
Expand Down Expand Up @@ -226,6 +229,8 @@ traitlets==5.14.3
# ipython
# ipywidgets
# matplotlib-inline
types-pytz==2025.2.0.20250809
# via pandas-stubs
typing-extensions==4.15.0
# via
# anyio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ numpy==2.3.4
# contourpy
# matplotlib
# pandas
# pandas-stubs
# scikit-learn
# scipy
# seaborn
Expand All @@ -121,6 +122,8 @@ pandas==2.3.3
# seaborn
# skore
# skrub
pandas-stubs==2.3.2.250926
# via skore-hub-project (skore-hub-project/pyproject.toml)
parso==0.8.5
# via jedi
pexpect==4.9.0
Expand Down Expand Up @@ -226,6 +229,8 @@ traitlets==5.14.3
# ipython
# ipywidgets
# matplotlib-inline
types-pytz==2025.2.0.20250809
# via pandas-stubs
typing-extensions==4.15.0
# via
# anyio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ numpy==2.3.4
# contourpy
# matplotlib
# pandas
# pandas-stubs
# scikit-learn
# scipy
# seaborn
Expand All @@ -121,6 +122,8 @@ pandas==2.3.3
# seaborn
# skore
# skrub
pandas-stubs==2.3.2.250926
# via skore-hub-project (skore-hub-project/pyproject.toml)
parso==0.8.5
# via jedi
pexpect==4.9.0
Expand Down Expand Up @@ -226,6 +229,8 @@ traitlets==5.14.3
# ipython
# ipywidgets
# matplotlib-inline
types-pytz==2025.2.0.20250809
# via pandas-stubs
typing-extensions==4.15.0
# via
# anywidget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ numpy==2.3.4
# contourpy
# matplotlib
# pandas
# pandas-stubs
# scikit-learn
# scipy
# seaborn
Expand All @@ -121,6 +122,8 @@ pandas==2.3.3
# seaborn
# skore
# skrub
pandas-stubs==2.3.2.250926
# via skore-hub-project (skore-hub-project/pyproject.toml)
parso==0.8.5
# via jedi
pexpect==4.9.0
Expand Down Expand Up @@ -226,6 +229,8 @@ traitlets==5.14.3
# ipython
# ipywidgets
# matplotlib-inline
types-pytz==2025.2.0.20250809
# via pandas-stubs
typing-extensions==4.15.0
# via
# anywidget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ numpy==2.3.4
# contourpy
# matplotlib
# pandas
# pandas-stubs
# scikit-learn
# scipy
# seaborn
Expand All @@ -121,6 +122,8 @@ pandas==2.3.3
# seaborn
# skore
# skrub
pandas-stubs==2.3.2.250926
# via skore-hub-project (skore-hub-project/pyproject.toml)
parso==0.8.5
# via jedi
pexpect==4.9.0
Expand Down Expand Up @@ -226,6 +229,8 @@ traitlets==5.14.3
# ipython
# ipywidgets
# matplotlib-inline
types-pytz==2025.2.0.20250809
# via pandas-stubs
typing-extensions==4.15.0
# via
# anywidget
Expand Down
2 changes: 2 additions & 0 deletions skore-hub-project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies = [

[project.optional-dependencies]
test = [
"pandas-stubs",
"pre-commit",
"pytest",
"pytest-cov",
Expand Down Expand Up @@ -109,6 +110,7 @@ convention = "numpy"

[tool.mypy]
exclude = ["hatch/", "tests/"]
strict = true

[[tool.mypy.overrides]]
follow_untyped_imports = true
Expand Down
3 changes: 2 additions & 1 deletion skore-hub-project/src/skore_hub_project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
from base64 import b64decode, b64encode
from collections.abc import Iterator
from contextlib import contextmanager

from rich.console import Console
Expand Down Expand Up @@ -45,7 +46,7 @@ def bytes_to_b64_str(literal: bytes) -> str:


@contextmanager
def switch_mpl_backend():
def switch_mpl_backend() -> Iterator[None]:
"""
Context-manager for switching ``matplotlib.backend`` to ``agg``.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
"""Definition of the payload used to associate feature importance media with report."""

from __future__ import annotations

from abc import ABC
from collections.abc import Callable
from functools import reduce
from typing import ClassVar, Literal, cast
from typing import TYPE_CHECKING, ClassVar, Literal, cast

import orjson
from orjson import OPT_NON_STR_KEYS, OPT_SERIALIZE_NUMPY, dumps

from skore_hub_project.artifact.media.media import Media, Report
from skore_hub_project.protocol import EstimatorReport
from skore_hub_project.protocol import Display, EstimatorReport

if TYPE_CHECKING:
from pandas import DataFrame


class FeatureImportance(Media[Report], ABC): # noqa: D101
Expand All @@ -18,20 +23,20 @@ class FeatureImportance(Media[Report], ABC): # noqa: D101
def content_to_upload(self) -> bytes | None: # noqa: D102
try:
function = cast(
Callable,
"Callable[..., Display | DataFrame]",
reduce(getattr, self.accessor.split("."), self.report),
)
except AttributeError:
return None

result = function()

if hasattr(result, "frame"):
if isinstance(result, Display):
result = result.frame()

return orjson.dumps(
return dumps(
result.fillna("NaN").to_dict(orient="tight"),
option=(orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY),
option=(OPT_NON_STR_KEYS | OPT_SERIALIZE_NUMPY),
)


Expand All @@ -55,9 +60,9 @@ def content_to_upload(self) -> bytes | None: # noqa: D102
and data_source == self.data_source
and scoring is None
):
return orjson.dumps(
return dumps(
obj.fillna("NaN").to_dict(orient="tight"),
option=(orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY),
option=(OPT_NON_STR_KEYS | OPT_SERIALIZE_NUMPY),
)

return None
Expand All @@ -77,7 +82,7 @@ class MeanDecreaseImpurity(FeatureImportance[EstimatorReport]): # noqa: D101
data_source: None = None


class Coefficients(FeatureImportance): # noqa: D101
class Coefficients(FeatureImportance[Report]): # noqa: D101
accessor: ClassVar[str] = "feature_importance.coefficients"
name: Literal["coefficients"] = "coefficients"
data_source: None = None
10 changes: 7 additions & 3 deletions skore-hub-project/src/skore_hub_project/artifact/media/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

from typing import Literal

from skore_hub_project.artifact.media.media import Media
from skore_hub_project.artifact.media.media import Media, Report


class EstimatorHtmlRepr(Media): # noqa: D101
class EstimatorHtmlRepr(Media[Report]): # noqa: D101
name: Literal["estimator_html_repr"] = "estimator_html_repr"
data_source: None = None
content_type: Literal["text/html"] = "text/html"

def content_to_upload(self) -> str: # noqa: D102
import sklearn.utils

return sklearn.utils.estimator_html_repr(self.report.estimator)
estimator_html_repr: str = sklearn.utils.estimator_html_repr(
self.report.estimator
)

return estimator_html_repr
Loading