Skip to content

Commit ffb9b13

Browse files
chore(all): Enforce PERF and PYI rules (#2101)
Fixes #2099.
1 parent 2936409 commit ffb9b13

File tree

13 files changed

+102
-62
lines changed

13 files changed

+102
-62
lines changed

skore-hub-project/pyproject.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,23 @@ exclude_also = [
8383
]
8484

8585
[tool.ruff.lint]
86-
select = ["E", "F", "UP", "B", "C4", "SIM", "T", "PT003", "PT014", "I", "D", "RUF010", "RUF015"]
86+
select = [
87+
"B",
88+
"C4",
89+
"T10",
90+
"T20",
91+
"PYI055", "PYI059",
92+
"PT003", "PT014",
93+
"SIM",
94+
"I",
95+
"PERF",
96+
"E",
97+
"D",
98+
"F",
99+
"UP",
100+
"RUF010", "RUF015",
101+
]
102+
ignore = ["PERF203"]
87103

88104
[tool.ruff.lint.pydocstyle]
89105
convention = "numpy"

skore-hub-project/src/skore_hub_project/artifact/media/media.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Report = TypeVar("Report", bound=(EstimatorReport | CrossValidationReport))
1212

1313

14-
class Media(Artifact, Generic[Report], ABC):
14+
class Media(Artifact, ABC, Generic[Report]):
1515
"""
1616
Payload used to associate a media with the report.
1717

skore-hub-project/src/skore_hub_project/metric/metric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def cast_to_float(value: Any) -> float | None:
2525
return None
2626

2727

28-
class Metric(BaseModel, Generic[Report], ABC):
28+
class Metric(BaseModel, ABC, Generic[Report]):
2929
"""
3030
Payload used to send a metric to ``hub``.
3131

skore-hub-project/src/skore_hub_project/report/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Report = TypeVar("Report", bound=(EstimatorReport | CrossValidationReport))
1616

1717

18-
class ReportPayload(BaseModel, Generic[Report], ABC):
18+
class ReportPayload(BaseModel, ABC, Generic[Report]):
1919
"""
2020
Payload used to send a report to ``hub``.
2121

skore-local-project/pyproject.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,23 @@ exclude_also = [
7474
]
7575

7676
[tool.ruff.lint]
77-
select = ["E", "F", "UP", "B", "C4", "SIM", "T", "PT003", "PT014", "I", "D", "RUF010", "RUF015"]
77+
select = [
78+
"B",
79+
"C4",
80+
"T10",
81+
"T20",
82+
"PYI055", "PYI059",
83+
"PT003", "PT014",
84+
"SIM",
85+
"I",
86+
"PERF",
87+
"E",
88+
"D",
89+
"F",
90+
"UP",
91+
"RUF010", "RUF015",
92+
]
93+
ignore = ["PERF203"]
7894

7995
[tool.ruff.lint.pydocstyle]
8096
convention = "numpy"

skore-local-project/src/skore_local_project/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def put(self, key: str, report: EstimatorReport | CrossValidationReport):
208208
if not isinstance(key, str):
209209
raise TypeError(f"Key must be a string (found '{type(key)}')")
210210

211-
Metadata: type[EstimatorReportMetadata] | type[CrossValidationReportMetadata]
211+
Metadata: type[EstimatorReportMetadata | CrossValidationReportMetadata]
212212

213213
if isinstance(report, EstimatorReport):
214214
Metadata = EstimatorReportMetadata

skore/pyproject.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,23 @@ exclude_also = [
135135
]
136136

137137
[tool.ruff.lint]
138-
select = ["E", "F", "UP", "B", "C4", "SIM", "T", "PT003", "PT014", "I", "D", "RUF010", "RUF015"]
138+
select = [
139+
"B",
140+
"C4",
141+
"T10",
142+
"T20",
143+
"PYI055", "PYI059",
144+
"PT003", "PT014",
145+
"SIM",
146+
"I",
147+
"PERF",
148+
"E",
149+
"D",
150+
"F",
151+
"UP",
152+
"RUF010", "RUF015",
153+
]
154+
ignore = ["PERF203"]
139155

140156
[tool.ruff.lint.pydocstyle]
141157
convention = "numpy"

skore/src/skore/_sklearn/_comparison/feature_importance_accessor.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,31 @@ def coefficients(self) -> FeatureImportanceDisplay:
5959
}
6060
)
6161

62-
coef_frames = []
6362
if self._parent._reports_type == "EstimatorReport":
64-
for reports_with_same_features in similar_reports.values():
65-
coef_frames.append(
66-
pd.DataFrame(
67-
{
68-
report_data["estimator_name"]: (
69-
report_data["report_obj"]
70-
.feature_importance.coefficients()
71-
.frame()
72-
.iloc[:, 0]
73-
)
74-
for report_data in reports_with_same_features
75-
},
76-
index=reports_with_same_features[-1]["feature_names"],
77-
)
63+
coef_frames = [
64+
pd.DataFrame(
65+
{
66+
report_data["estimator_name"]: (
67+
report_data["report_obj"]
68+
.feature_importance.coefficients()
69+
.frame()
70+
.iloc[:, 0]
71+
)
72+
for report_data in reports_with_same_features
73+
},
74+
index=reports_with_same_features[-1]["feature_names"],
7875
)
79-
76+
for reports_with_same_features in similar_reports.values()
77+
]
8078
elif self._parent._reports_type == "CrossValidationReport":
81-
for reports_with_same_features in similar_reports.values():
82-
for report_data in reports_with_same_features:
83-
coef_frames.append(
84-
report_data["report_obj"]
85-
.feature_importance.coefficients()
86-
.frame()
87-
.add_prefix(f"{report_data['estimator_name']}__")
88-
)
79+
coef_frames = [
80+
report_data["report_obj"]
81+
.feature_importance.coefficients()
82+
.frame()
83+
.add_prefix(f"{report_data['estimator_name']}__")
84+
for reports_with_same_features in similar_reports.values()
85+
for report_data in reports_with_same_features
86+
]
8987
else:
9088
raise TypeError(f"Unexpected report type: {self._parent._reports_type}")
9189

skore/src/skore/_sklearn/_estimator/report.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,11 @@ def cache_predictions(
294294
progress.update(task, total=total_iterations)
295295

296296
# do not mutate directly `self._cache` during the execution of Parallel
297-
results_to_cache = {}
297+
results_to_cache: dict[tuple[Any, ...], Any] = {}
298298
for results in generator:
299-
for key, value, is_cached in results:
300-
if not is_cached:
301-
results_to_cache[key] = value
299+
results_to_cache.update(
300+
(key, value) for key, value, is_cached in results if not is_cached
301+
)
302302
progress.update(task, advance=1, refresh=True)
303303

304304
if results_to_cache:

skore/src/skore/_sklearn/_plot/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ class HelpDisplayMixin:
194194

195195
def _get_attributes_for_help(self) -> list[str]:
196196
"""Get the attributes ending with '_' to display in help."""
197-
attributes = []
198-
for name in dir(self):
199-
if name.endswith("_") and not name.startswith("_"):
200-
attributes.append(f".{name}")
201-
return sorted(attributes)
197+
return sorted(
198+
f".{name}"
199+
for name in dir(self)
200+
if name.endswith("_") and not name.startswith("_")
201+
)
202202

203203
def _get_methods_for_help(self) -> list[tuple[str, Any]]:
204204
"""Get the public methods to display in help."""

0 commit comments

Comments
 (0)