Skip to content

Commit cd2b5f0

Browse files
committed
Fix ruff issues: add docstrings, wrap long lines, use union isinstance
1 parent 265c71a commit cd2b5f0

4 files changed

Lines changed: 31 additions & 11 deletions

File tree

src/hyperactive/experiment/integrations/sktime_detector.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""Integration adapter for sktime detector experiments.
2+
3+
Provides `SktimeDetectorExperiment` which adapts sktime detector-style
4+
objects to the Hyperactive experiment interface.
5+
"""
6+
17
import numpy as np
28
from skbase.utils.dependencies import _check_soft_dependencies
39

@@ -118,16 +124,16 @@ def _evaluate(self, params):
118124
return res_float, {"results": results}
119125

120126
# Fallback: perform a manual cross-validation loop if `evaluate` is not present.
121-
from sklearn.base import clone as skl_clone
122127

123128
# Determine underlying metric function or sklearn-style scorer
124129
metric_func = getattr(self._scoring, "_metric_func", None)
125130
is_sklearn_scorer = False
126131
if metric_func is None:
127-
# If _scoring is a sklearn scorer callable that accepts (estimator, X, y)
128-
# we will call it directly with the fitted estimator.
132+
# If _scoring is a sklearn scorer callable that accepts
133+
# (estimator, X, y) we will call it directly with the fitted estimator.
129134
if callable(self._scoring):
130-
# heuristics: sklearn scorers produced by make_scorer take (estimator, X, y)
135+
# Heuristic: sklearn scorers produced by `make_scorer` take
136+
# arguments `(estimator, X, y)`.
131137
is_sklearn_scorer = True
132138
else:
133139
metric = metric_func
@@ -138,7 +144,7 @@ def _evaluate(self, params):
138144
for train_idx, test_idx in self._cv.split(self.y):
139145
X_train = None
140146
X_test = None
141-
if isinstance(self.y, (list, tuple)):
147+
if isinstance(self.y, list | tuple):
142148
y_train = [self.y[i] for i in train_idx]
143149
y_test = [self.y[i] for i in test_idx]
144150
else:
@@ -200,10 +206,10 @@ def _evaluate(self, params):
200206
return float(res_float), {"results": {"cv_scores": scores}}
201207

202208
def _safe_index(self, obj, idx):
203-
"""
204-
Safely index into `obj` using integer indices.
209+
"""Safely index into `obj` using integer indices.
205210
206-
Supports pandas objects with .iloc, numpy arrays/lists, and other indexable types.
211+
Supports pandas objects with ``.iloc``, numpy arrays/lists, and other
212+
indexable types.
207213
"""
208214
try:
209215
return obj.iloc[idx]
@@ -218,7 +224,11 @@ def _safe_index(self, obj, idx):
218224

219225
@classmethod
220226
def get_test_params(cls, parameter_set="default"):
221-
# Return testing parameter settings for the skbase object.
227+
"""Return testing parameter settings for the skbase object.
228+
229+
This returns a list or dict appropriate to construct test instances
230+
for this class. See the skbase test helpers for expected formats.
231+
"""
222232
if _check_soft_dependencies("sktime", severity="none"):
223233
try:
224234
from sktime.annotation.dummy import DummyDetector

src/hyperactive/experiment/integrations/tests/test_sktime_detector_experiment.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
"""Smoke tests for the sktime detector experiment integration."""
2+
3+
14
def test_sktime_detector_experiment_with_dummy():
5+
"""Run a minimal smoke test using sktime's DummyDetector (if available)."""
26
try:
37
from sktime.annotation.dummy import DummyDetector
48
from sktime.datasets import load_unit_test

src/hyperactive/integrations/sktime/_detector.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,12 @@ def get_test_params(cls, parameter_set="default"):
107107
"optimizer": GridSearchSk(param_grid={}),
108108
}
109109

110-
110+
111111
params_more = {
112112
"detector": DummyDetector() if DummyDetector is not None else None,
113-
"optimizer": GridSearchSk(param_grid={"strategy": ["most_frequent", "stratified"]}),
113+
"optimizer": GridSearchSk(
114+
param_grid={"strategy": ["most_frequent", "stratified"]}
115+
),
114116
"cv": 2,
115117
"scoring": None,
116118
"refit": False,

src/hyperactive/integrations/sktime/tests/test_detector_integration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
"""Basic import smoke tests for the sktime detector integration."""
2+
3+
14
def test_detector_integration_imports():
5+
"""Ensure the public integration symbols can be imported."""
26
from hyperactive.experiment.integrations import SktimeDetectorExperiment
37
from hyperactive.integrations.sktime import TSDetectorOptCv
48

0 commit comments

Comments
 (0)