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 .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Install dependencies
run: |
pip install .[docs,tests]
pip install black=="22.6.0" isort=="5.10.1" mypy=="0.981"
pip install black=="22.6.0" isort=="5.10.1" mypy=="1.0.0"
pip uninstall --yes scikit-learn
if [ ${{ matrix.sklearn_version }} == "nightly" ];
then pip install --pre --extra-index https://pypi.anaconda.org/scipy-wheels-nightly/simple scikit-learn;
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
rev: v1.0.0
hooks:
- id: mypy
args: [--config-file=pyproject.toml]
Expand Down
23 changes: 15 additions & 8 deletions skops/card/_model_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import re
import sys
import textwrap
import zipfile
from collections.abc import Mapping
Expand All @@ -19,6 +20,12 @@
from skops.io import load
from skops.utils.importutils import import_or_raise

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self
Comment on lines +23 to +26
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this another instance where mypy doesn't like it to be in fixes.py?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is indeed annoying.



# Repr attributes can be used to control the behavior of repr
aRepr = Repr()
aRepr.maxother = 79
Expand Down Expand Up @@ -506,7 +513,7 @@ def get_model(self) -> Any:
# model has changed, but at the moment we have no way of knowing that
return model

def add(self, **kwargs: str | Formattable) -> Card:
def add(self, **kwargs: str | Formattable) -> Self:
"""Add new section(s) to the model card.

Add one or multiple sections to the model card. The section names are
Expand Down Expand Up @@ -714,7 +721,7 @@ def add_model_plot(
self,
section: str | None = None,
description: str | None = None,
) -> Card:
) -> Self:
"""Add a model plot

Use sklearn model visualization to add create a diagram of the model.
Expand Down Expand Up @@ -784,7 +791,7 @@ def _add_model_plot(

def add_hyperparams(
self, section: str | None = None, description: str | None = None
) -> Card:
) -> Self:
"""Add the model's hyperparameters as a table

Parameters
Expand Down Expand Up @@ -862,7 +869,7 @@ def add_get_started_code(
description: str | None = None,
file_name: str | None = None,
model_format: Literal["pickle", "skops"] | None = None,
) -> Card:
) -> Self:
"""Add getting started code

This code can be copied by users to load the model and make predictions
Expand Down Expand Up @@ -960,7 +967,7 @@ def _add_get_started_code(

self._add_single(section, content)

def add_plot(self, *, folded=False, **kwargs: str) -> Card:
def add_plot(self, *, folded=False, **kwargs: str) -> Self:
"""Add plots to the model card.

The plot should be saved on the file system and the path passed as
Expand Down Expand Up @@ -995,7 +1002,7 @@ def add_plot(self, *, folded=False, **kwargs: str) -> Card:

def add_table(
self, *, folded: bool = False, **kwargs: dict["str", list[Any]]
) -> Card:
) -> Self:
"""Add a table to the model card.

Add a table to the model card. This can be especially useful when you
Expand Down Expand Up @@ -1050,7 +1057,7 @@ def add_metrics(
section: str | None = None,
description: str | None = None,
**kwargs: str | int | float,
) -> Card:
) -> Self:
"""Add metric values to the model card.

All metrics will be collected in, and then formatted to, a table.
Expand Down Expand Up @@ -1101,7 +1108,7 @@ def add_permutation_importances(
plot_file: str = "permutation_importances.png",
plot_name: str = "Permutation Importances",
overwrite: bool = False,
) -> "Card":
) -> Self:
"""Plots permutation importance and saves it to model card.

Parameters
Expand Down