Skip to content

Commit 41f71fd

Browse files
authored
MNT update linters and use ruff (#397)
1 parent 98541de commit 41f71fd

File tree

9 files changed

+52
-43
lines changed

9 files changed

+52
-43
lines changed

.github/workflows/build-test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: Install dependencies
5656
run: |
5757
pip install .[docs,tests]
58-
pip install black=="22.6.0" isort=="5.10.1" mypy=="1.0.0"
58+
pip install black=="23.9.1" ruff=="0.0.292" mypy=="1.6.0"
5959
pip uninstall --yes scikit-learn
6060
if [ ${{ matrix.sklearn_version }} == "nightly" ];
6161
then pip install --pre --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple scikit-learn;
@@ -72,8 +72,8 @@ jobs:
7272
- name: Check black
7373
run: black --check --diff .
7474

75-
- name: Check isort
76-
run: isort --check --diff .
75+
- name: Check ruff
76+
run: ruff check --diff .
7777

7878
- name: Tests
7979
env:

.pre-commit-config.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@ repos:
1010
- id: check-case-conflict
1111
- id: check-merge-conflict
1212
- repo: https://github.com/psf/black
13-
rev: 23.1.0
13+
rev: 23.9.1
1414
hooks:
1515
- id: black
16-
- repo: https://github.com/pycqa/flake8
17-
rev: 6.0.0
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
# Ruff version.
18+
rev: v0.0.292
1819
hooks:
19-
- id: flake8
20-
types: [file, python]
21-
- repo: https://github.com/PyCQA/isort
22-
rev: 5.12.0
23-
hooks:
24-
- id: isort
20+
- id: ruff
21+
args: ["--fix", "--show-source"]
2522
- repo: https://github.com/pre-commit/mirrors-mypy
26-
rev: v1.0.1
23+
rev: v1.6.0
2724
hooks:
2825
- id: mypy
2926
args: [--config-file=pyproject.toml]

examples/plot_custom_model_card.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@
163163
display.figure_.savefig(plot_file_name)
164164
model_card.add_plot(
165165
**{
166-
"Regression on California Housing dataset/Results/Partial Dependence Plots": plot_file_name
166+
"Regression on California Housing dataset/Results/Partial Dependence Plots": (
167+
plot_file_name
168+
)
167169
},
168170
)
169171

examples/plot_tabular_regression.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from tempfile import mkdtemp, mkstemp
1717

1818
import matplotlib.pyplot as plt
19-
import pandas as pd
2019
import sklearn
2120
from sklearn.datasets import load_diabetes
2221
from sklearn.linear_model import LinearRegression
@@ -42,7 +41,8 @@
4241
# Train a Model
4342
# =============
4443
# To train a model, we need to convert our data first to vectors. We will use
45-
# StandardScalar in our pipeline. We will fit a Linear Regression model with the outputs of the scalar.
44+
# StandardScalar in our pipeline. We will fit a Linear Regression model with
45+
# the outputs of the scalar.
4646
model = Pipeline(
4747
[
4848
("scaler", StandardScaler()),
@@ -112,13 +112,14 @@
112112
model_card_authors = "skops_user, lazarust"
113113
citation_bibtex = "bibtex\n@inproceedings{...,year={2022}}"
114114
model_card.add(
115+
folded=False,
115116
**{
116117
"Model Card Authors": model_card_authors,
117118
"Intended uses & limitations": limitations,
118119
"Citation": citation_bibtex,
119120
"Model description": model_description,
120121
"Model description/Intended uses & limitations": limitations,
121-
}
122+
},
122123
)
123124

124125
# %%

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ line-length = 88
33
target_version = ['py38', 'py39', 'py310', 'py311']
44
preview = true
55

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

910
[tool.pytest.ini_options]
1011
filterwarnings = [

skops/card/_model_card.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,8 +1254,9 @@ def add_fairlearn_metric_frame(
12541254
description: str | None = None,
12551255
) -> Self:
12561256
"""
1257-
Add a :class:`fairlearn.metrics.MetricFrame` table to the model card. The table contains
1258-
the difference, group_ma, group_min, and ratio for each metric.
1257+
Add a :class:`fairlearn.metrics.MetricFrame` table to the model card.
1258+
The table contains the difference, group_ma, group_min, and ratio for
1259+
each metric.
12591260
12601261
Parameters
12611262
----------
@@ -1451,9 +1452,10 @@ def save(self, path: str | Path, copy_files: bool = False) -> None:
14511452
Filepath to save your card.
14521453
14531454
plot_path: str
1454-
Filepath to save the plots. Use this when saving the model card before creating the
1455-
repository. Without this path the README will have an absolute path to the plot that
1456-
won't exist in the repository.
1455+
Filepath to save the plots. Use this when saving the model card
1456+
before creating the repository. Without this path the README will
1457+
have an absolute path to the plot that won't exist in the
1458+
repository.
14571459
14581460
Notes
14591461
-----
@@ -1487,7 +1489,8 @@ def _iterate_key_section_content(
14871489
Parameters
14881490
----------
14891491
data : dict[str, Section]
1490-
The card data to iterate through. This is usually the sections and subsections.
1492+
The card data to iterate through. This is usually the sections and
1493+
subsections.
14911494
14921495
level : int, optional
14931496
The level of the section, by default 0. This keeps track of subsections.

skops/card/_templates.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ class Templates(Enum):
6767
"Model Details/Model Description/Model type": CONTENT_PLACEHOLDER,
6868
"Model Details/Model Description/Language(s) (NLP)": CONTENT_PLACEHOLDER,
6969
"Model Details/Model Description/License": CONTENT_PLACEHOLDER,
70-
"Model Details/Model Description/Finetuned from model [optional]": CONTENT_PLACEHOLDER,
71-
"Model Details/Model Description/Resources for more information": CONTENT_PLACEHOLDER,
70+
"Model Details/Model Description/Finetuned from model [optional]":
71+
CONTENT_PLACEHOLDER,
72+
"Model Details/Model Description/Resources for more information":
73+
CONTENT_PLACEHOLDER,
7274

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

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

139143
"Technical Specifications [optional]": "",
140-
"Technical Specifications [optional]/Model Architecture and Objective": CONTENT_PLACEHOLDER,
141-
"Technical Specifications [optional]/Compute Infrastructure": CONTENT_PLACEHOLDER,
142-
"Technical Specifications [optional]/Compute Infrastructure/Hardware": CONTENT_PLACEHOLDER,
143-
"Technical Specifications [optional]/Compute Infrastructure/Software": CONTENT_PLACEHOLDER,
144+
"Technical Specifications [optional]/Model Architecture and Objective":
145+
CONTENT_PLACEHOLDER,
146+
"Technical Specifications [optional]/Compute Infrastructure":
147+
CONTENT_PLACEHOLDER,
148+
"Technical Specifications [optional]/Compute Infrastructure/Hardware":
149+
CONTENT_PLACEHOLDER,
150+
"Technical Specifications [optional]/Compute Infrastructure/Software":
151+
CONTENT_PLACEHOLDER,
144152

145153
"Citation [optional]": "",
146154
# If there is a paper or blog post introducing the model, the APA and Bibtex
@@ -155,7 +163,8 @@ class Templates(Enum):
155163
"More Information [optional]": CONTENT_PLACEHOLDER,
156164
"Model Card Authors [optional]": CONTENT_PLACEHOLDER,
157165
"Model Card Contact": CONTENT_PLACEHOLDER,
158-
"How to Get Started with the Model": f"""Use the code below to get started with the model.
166+
"How to Get Started with the Model":
167+
f"""Use the code below to get started with the model.
159168
160169
<details>
161170
<summary> Click to expand </summary>

skops/card/tests/test_card.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -807,14 +807,12 @@ def test_render_with_metadata(self, model_card):
807807
model_card.metadata.foo = "something"
808808
model_card.metadata.bar = "something else"
809809
rendered = model_card.render()
810-
expected = textwrap.dedent(
811-
"""
810+
expected = textwrap.dedent("""
812811
---
813812
foo: something
814813
bar: something else
815814
---
816-
"""
817-
).strip()
815+
""").strip()
818816
assert rendered.startswith(expected)
819817

820818

@@ -1362,13 +1360,11 @@ def test_card_repr_empty_card(self, meth):
13621360
model = fit_model()
13631361
card = Card(model, model_diagram=False, template=None)
13641362
result = meth(card)
1365-
expected = textwrap.dedent(
1366-
"""
1363+
expected = textwrap.dedent("""
13671364
Card(
13681365
model=LinearRegression(),
13691366
)
1370-
"""
1371-
).strip()
1367+
""").strip()
13721368
assert result == expected
13731369

13741370
@pytest.mark.parametrize("meth", [repr, str])

skops/io/_general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def isnamedtuple(self, t) -> bool:
191191
f = getattr(t, "_fields", None)
192192
if not isinstance(f, tuple):
193193
return False
194-
return all(type(n) == str for n in f)
194+
return all(isinstance(n, str) for n in f)
195195

196196

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

0 commit comments

Comments
 (0)