Skip to content

Commit

Permalink
Merge branch 'main' into enh-get-scikeras-working
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarust authored Oct 14, 2023
2 parents 101b90c + 41f71fd commit 08f5ba7
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 43 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Install dependencies
run: |
pip install .[docs,tests]
pip install black=="22.6.0" isort=="5.10.1" mypy=="1.0.0"
pip install black=="23.9.1" ruff=="0.0.292" mypy=="1.6.0"
pip uninstall --yes scikit-learn
if [ ${{ matrix.sklearn_version }} == "nightly" ];
then pip install --pre --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple scikit-learn;
Expand All @@ -72,8 +72,8 @@ jobs:
- name: Check black
run: black --check --diff .

- name: Check isort
run: isort --check --diff .
- name: Check ruff
run: ruff check --diff .

- name: Tests
env:
Expand Down
17 changes: 7 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@ repos:
- id: check-case-conflict
- id: check-merge-conflict
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.292
hooks:
- id: flake8
types: [file, python]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- id: ruff
args: ["--fix", "--show-source"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.1
rev: v1.6.0
hooks:
- id: mypy
args: [--config-file=pyproject.toml]
Expand Down
4 changes: 3 additions & 1 deletion examples/plot_custom_model_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@
display.figure_.savefig(plot_file_name)
model_card.add_plot(
**{
"Regression on California Housing dataset/Results/Partial Dependence Plots": plot_file_name
"Regression on California Housing dataset/Results/Partial Dependence Plots": (
plot_file_name
)
},
)

Expand Down
7 changes: 4 additions & 3 deletions examples/plot_tabular_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from tempfile import mkdtemp, mkstemp

import matplotlib.pyplot as plt
import pandas as pd
import sklearn
from sklearn.datasets import load_diabetes
from sklearn.linear_model import LinearRegression
Expand All @@ -42,7 +41,8 @@
# Train a Model
# =============
# To train a model, we need to convert our data first to vectors. We will use
# StandardScalar in our pipeline. We will fit a Linear Regression model with the outputs of the scalar.
# StandardScalar in our pipeline. We will fit a Linear Regression model with
# the outputs of the scalar.
model = Pipeline(
[
("scaler", StandardScaler()),
Expand Down Expand Up @@ -112,13 +112,14 @@
model_card_authors = "skops_user, lazarust"
citation_bibtex = "bibtex\n@inproceedings{...,year={2022}}"
model_card.add(
folded=False,
**{
"Model Card Authors": model_card_authors,
"Intended uses & limitations": limitations,
"Citation": citation_bibtex,
"Model description": model_description,
"Model description/Intended uses & limitations": limitations,
}
},
)

# %%
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ line-length = 88
target_version = ['py38', 'py39', 'py310', 'py311']
preview = true

[tool.isort]
profile = "black"
[tool.ruff]
# all rules can be found here: https://beta.ruff.rs/docs/rules/
select = ["E", "F", "W", "I"]

[tool.pytest.ini_options]
filterwarnings = [
Expand Down
15 changes: 9 additions & 6 deletions skops/card/_model_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,8 +1254,9 @@ def add_fairlearn_metric_frame(
description: str | None = None,
) -> Self:
"""
Add a :class:`fairlearn.metrics.MetricFrame` table to the model card. The table contains
the difference, group_ma, group_min, and ratio for each metric.
Add a :class:`fairlearn.metrics.MetricFrame` table to the model card.
The table contains the difference, group_ma, group_min, and ratio for
each metric.
Parameters
----------
Expand Down Expand Up @@ -1451,9 +1452,10 @@ def save(self, path: str | Path, copy_files: bool = False) -> None:
Filepath to save your card.
plot_path: str
Filepath to save the plots. Use this when saving the model card before creating the
repository. Without this path the README will have an absolute path to the plot that
won't exist in the repository.
Filepath to save the plots. Use this when saving the model card
before creating the repository. Without this path the README will
have an absolute path to the plot that won't exist in the
repository.
Notes
-----
Expand Down Expand Up @@ -1487,7 +1489,8 @@ def _iterate_key_section_content(
Parameters
----------
data : dict[str, Section]
The card data to iterate through. This is usually the sections and subsections.
The card data to iterate through. This is usually the sections and
subsections.
level : int, optional
The level of the section, by default 0. This keeps track of subsections.
Expand Down
27 changes: 18 additions & 9 deletions skops/card/_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ class Templates(Enum):
"Model Details/Model Description/Model type": CONTENT_PLACEHOLDER,
"Model Details/Model Description/Language(s) (NLP)": CONTENT_PLACEHOLDER,
"Model Details/Model Description/License": CONTENT_PLACEHOLDER,
"Model Details/Model Description/Finetuned from model [optional]": CONTENT_PLACEHOLDER,
"Model Details/Model Description/Resources for more information": CONTENT_PLACEHOLDER,
"Model Details/Model Description/Finetuned from model [optional]":
CONTENT_PLACEHOLDER,
"Model Details/Model Description/Resources for more information":
CONTENT_PLACEHOLDER,

"Uses": "",
# Address questions around how the model is intended to be used, including
Expand Down Expand Up @@ -102,8 +104,10 @@ class Templates(Enum):
"Training Details/Training Procedure [optional]": "",
# This relates heavily to the Technical Specifications. Content here should
# link to that section when it is relevant to the training procedure.
"Training Details/Training Procedure [optional]/Preprocessing": CONTENT_PLACEHOLDER,
"Training Details/Training Procedure [optional]/Speeds, Sizes, Times": CONTENT_PLACEHOLDER,
"Training Details/Training Procedure [optional]/Preprocessing":
CONTENT_PLACEHOLDER,
"Training Details/Training Procedure [optional]/Speeds, Sizes, Times":
CONTENT_PLACEHOLDER,
# This section provides information about throughput, start/end time,
# checkpoint size if relevant, etc.

Expand Down Expand Up @@ -137,10 +141,14 @@ class Templates(Enum):
"Environmental Impact/Carbon Emitted": CONTENT_PLACEHOLDER,

"Technical Specifications [optional]": "",
"Technical Specifications [optional]/Model Architecture and Objective": CONTENT_PLACEHOLDER,
"Technical Specifications [optional]/Compute Infrastructure": CONTENT_PLACEHOLDER,
"Technical Specifications [optional]/Compute Infrastructure/Hardware": CONTENT_PLACEHOLDER,
"Technical Specifications [optional]/Compute Infrastructure/Software": CONTENT_PLACEHOLDER,
"Technical Specifications [optional]/Model Architecture and Objective":
CONTENT_PLACEHOLDER,
"Technical Specifications [optional]/Compute Infrastructure":
CONTENT_PLACEHOLDER,
"Technical Specifications [optional]/Compute Infrastructure/Hardware":
CONTENT_PLACEHOLDER,
"Technical Specifications [optional]/Compute Infrastructure/Software":
CONTENT_PLACEHOLDER,

"Citation [optional]": "",
# If there is a paper or blog post introducing the model, the APA and Bibtex
Expand All @@ -155,7 +163,8 @@ class Templates(Enum):
"More Information [optional]": CONTENT_PLACEHOLDER,
"Model Card Authors [optional]": CONTENT_PLACEHOLDER,
"Model Card Contact": CONTENT_PLACEHOLDER,
"How to Get Started with the Model": f"""Use the code below to get started with the model.
"How to Get Started with the Model":
f"""Use the code below to get started with the model.
<details>
<summary> Click to expand </summary>
Expand Down
12 changes: 4 additions & 8 deletions skops/card/tests/test_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,14 +807,12 @@ def test_render_with_metadata(self, model_card):
model_card.metadata.foo = "something"
model_card.metadata.bar = "something else"
rendered = model_card.render()
expected = textwrap.dedent(
"""
expected = textwrap.dedent("""
---
foo: something
bar: something else
---
"""
).strip()
""").strip()
assert rendered.startswith(expected)


Expand Down Expand Up @@ -1362,13 +1360,11 @@ def test_card_repr_empty_card(self, meth):
model = fit_model()
card = Card(model, model_diagram=False, template=None)
result = meth(card)
expected = textwrap.dedent(
"""
expected = textwrap.dedent("""
Card(
model=LinearRegression(),
)
"""
).strip()
""").strip()
assert result == expected

@pytest.mark.parametrize("meth", [repr, str])
Expand Down
2 changes: 1 addition & 1 deletion skops/io/_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def isnamedtuple(self, t) -> bool:
f = getattr(t, "_fields", None)
if not isinstance(f, tuple):
return False
return all(type(n) == str for n in f)
return all(isinstance(n, str) for n in f)


def function_get_state(obj: Any, save_context: SaveContext) -> dict[str, Any]:
Expand Down

0 comments on commit 08f5ba7

Please sign in to comment.