Skip to content

Commit 6739265

Browse files
[MNT] Automated pre-commit hook update (#85)
* Automated `pre-commit` hook update * fixes --------- Co-authored-by: MatthewMiddlehurst <25731235+MatthewMiddlehurst@users.noreply.github.com> Co-authored-by: MatthewMiddlehurst <pfm15hbu@gmail.com>
1 parent 3b2dbbc commit 6739265

File tree

22 files changed

+12308
-12360
lines changed

22 files changed

+12308
-12360
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.6.0
3+
rev: v6.0.0
44
hooks:
55
- id: check-ast
66
- id: check-added-large-files
@@ -14,8 +14,6 @@ repos:
1414
- id: debug-statements
1515
- id: end-of-file-fixer
1616
- id: fix-byte-order-marker
17-
- id: fix-encoding-pragma
18-
args: ["--remove"]
1917
- id: name-tests-test
2018
args: ["--pytest-test-first"]
2119
- id: requirements-txt-fixer
@@ -28,39 +26,39 @@ repos:
2826
args: [ "--create", "--python-folders", "tsml" ]
2927

3028
- repo: https://github.com/astral-sh/ruff-pre-commit
31-
rev: v0.4.9
29+
rev: v0.12.9
3230
hooks:
3331
- id: ruff
3432
args: [ "--fix" ]
3533

3634
- repo: https://github.com/asottile/pyupgrade
37-
rev: v3.16.0
35+
rev: v3.20.0
3836
hooks:
3937
- id: pyupgrade
40-
args: [ "--py38-plus" ]
38+
args: [ "--py310-plus" ]
4139

4240
- repo: https://github.com/pycqa/isort
43-
rev: 5.13.2
41+
rev: 6.0.1
4442
hooks:
4543
- id: isort
4644
name: isort (python)
4745
args: [ "--profile=black", "--multi-line=3" ]
4846

4947
- repo: https://github.com/pycqa/flake8
50-
rev: 7.1.0
48+
rev: 7.3.0
5149
hooks:
5250
- id: flake8
5351
additional_dependencies: [ flake8-bugbear, flake8-print, Flake8-pyproject ]
5452
args: [ "--max-line-length=88", "--extend-ignore=E203" ]
5553

5654
- repo: https://github.com/psf/black
57-
rev: 24.4.2
55+
rev: 25.1.0
5856
hooks:
5957
- id: black
6058
language_version: python3
6159

6260
- repo: https://github.com/nbQA-dev/nbQA
63-
rev: 1.8.5
61+
rev: 1.9.1
6462
hooks:
6563
- id: nbqa-isort
6664
additional_dependencies: [ isort ]
@@ -73,7 +71,7 @@ repos:
7371
args: [ "--nbqa-dont-skip-bad-cells", "--extend-ignore=E402,E203", "--max-line-length=88" ]
7472

7573
- repo: https://github.com/mgedmin/check-manifest
76-
rev: "0.49"
74+
rev: "0.50"
7775
hooks:
7876
- id: check-manifest
7977
stages: [ manual ]

tsml/base.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
]
88

99
from abc import ABCMeta
10-
from typing import List, Tuple, Union
1110

1211
import numpy as np
1312
from numpy.random import RandomState
@@ -28,12 +27,12 @@ def _validate_data(
2827
y: object = "no_validation",
2928
reset: bool = True,
3029
**check_params,
31-
) -> Union[
32-
Tuple[np.ndarray, object],
33-
Tuple[List[np.ndarray], object],
34-
np.ndarray,
35-
List[np.ndarray],
36-
]:
30+
) -> (
31+
tuple[np.ndarray, object]
32+
| tuple[list[np.ndarray], object]
33+
| np.ndarray
34+
| list[np.ndarray]
35+
):
3736
"""Validate input data and set or check the `n_features_in_` attribute.
3837
3938
Uses the `scikit-learn` 1.2.1 `_validate_data` function as a base.
@@ -111,10 +110,10 @@ def _validate_data(
111110

112111
def _convert_X(
113112
self,
114-
X: Union[np.ndarray, List[np.ndarray]],
113+
X: np.ndarray | list[np.ndarray],
115114
pad_unequal: bool = False,
116115
concatenate_channels: bool = False,
117-
) -> Union[np.ndarray, List[np.ndarray]]:
116+
) -> np.ndarray | list[np.ndarray]:
118117
dtypes = _safe_tags(self)["X_types"]
119118

120119
if isinstance(X, np.ndarray) and X.ndim == 3:
@@ -191,7 +190,7 @@ def _convert_X(
191190

192191
raise ValueError("Unable to convert X, please check the estimator tags.")
193192

194-
def _check_n_features(self, X: Union[np.ndarray, List[np.ndarray]], reset: bool):
193+
def _check_n_features(self, X: np.ndarray | list[np.ndarray], reset: bool):
195194
"""Set the `n_features_in_` attribute, or check against it.
196195
197196
Uses the `scikit-learn` 1.2.1 `_check_n_features` function as a base.
@@ -251,9 +250,7 @@ def _more_tags(self) -> dict:
251250
return _DEFAULT_TAGS
252251

253252
@classmethod
254-
def get_test_params(
255-
cls, parameter_set: Union[str, None] = None
256-
) -> Union[dict, List[dict]]:
253+
def get_test_params(cls, parameter_set: str | None = None) -> dict | list[dict]:
257254
"""Return unit test parameter settings for the estimator.
258255
259256
Parameters
@@ -272,7 +269,7 @@ def get_test_params(
272269

273270

274271
def _clone_estimator(
275-
base_estimator: BaseEstimator, random_state: Union[None, int, RandomState] = None
272+
base_estimator: BaseEstimator, random_state: None | int | RandomState = None
276273
) -> BaseEstimator:
277274
"""Clone an estimator and set the random state if available."""
278275
estimator = clone(base_estimator)

tsml/compose/_channel_ensemble.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
__all__ = ["ChannelEnsembleClassifier", "ChannelEnsembleRegressor"]
99

1010
from abc import ABCMeta
11-
from typing import List, Union
1211

1312
import numpy as np
1413
from sklearn.base import ClassifierMixin, RegressorMixin
@@ -220,7 +219,7 @@ class ChannelEnsembleClassifier(ClassifierMixin, _BaseChannelEnsemble):
220219
def __init__(self, estimators, remainder="drop", random_state=None):
221220
super().__init__(estimators, remainder, random_state)
222221

223-
def fit(self, X: Union[np.ndarray, List[np.ndarray]], y: np.ndarray) -> object:
222+
def fit(self, X: np.ndarray | list[np.ndarray], y: np.ndarray) -> object:
224223
"""Fit the estimator to training data.
225224
226225
Parameters
@@ -268,7 +267,7 @@ def fit(self, X: Union[np.ndarray, List[np.ndarray]], y: np.ndarray) -> object:
268267
self.estimators_ = estimators_
269268
return self
270269

271-
def predict(self, X: Union[np.ndarray, List[np.ndarray]]) -> np.ndarray:
270+
def predict(self, X: np.ndarray | list[np.ndarray]) -> np.ndarray:
272271
"""Predicts labels for sequences in X.
273272
274273
Parameters
@@ -294,7 +293,7 @@ def predict(self, X: Union[np.ndarray, List[np.ndarray]]) -> np.ndarray:
294293
[self.classes_[int(np.argmax(prob))] for prob in self.predict_proba(X)]
295294
)
296295

297-
def predict_proba(self, X: Union[np.ndarray, List[np.ndarray]]) -> np.ndarray:
296+
def predict_proba(self, X: np.ndarray | list[np.ndarray]) -> np.ndarray:
298297
"""Predicts labels probabilities for sequences in X.
299298
300299
Parameters
@@ -334,9 +333,7 @@ def _more_tags(self) -> dict:
334333
}
335334

336335
@classmethod
337-
def get_test_params(
338-
cls, parameter_set: Union[str, None] = None
339-
) -> Union[dict, List[dict]]:
336+
def get_test_params(cls, parameter_set: str | None = None) -> dict | list[dict]:
340337
"""Return unit test parameter settings for the estimator.
341338
342339
Parameters
@@ -430,7 +427,7 @@ class ChannelEnsembleRegressor(RegressorMixin, _BaseChannelEnsemble):
430427
def __init__(self, estimators, remainder="drop", random_state=None):
431428
super().__init__(estimators, remainder, random_state)
432429

433-
def fit(self, X: Union[np.ndarray, List[np.ndarray]], y: np.ndarray) -> object:
430+
def fit(self, X: np.ndarray | list[np.ndarray], y: np.ndarray) -> object:
434431
"""Fit the estimator to training data.
435432
436433
Parameters
@@ -468,7 +465,7 @@ def fit(self, X: Union[np.ndarray, List[np.ndarray]], y: np.ndarray) -> object:
468465
self.estimators_ = estimators_
469466
return self
470467

471-
def predict(self, X: Union[np.ndarray, List[np.ndarray]]) -> np.ndarray:
468+
def predict(self, X: np.ndarray | list[np.ndarray]) -> np.ndarray:
472469
"""Predicts labels for sequences in X.
473470
474471
Parameters
@@ -501,9 +498,7 @@ def _more_tags(self) -> dict:
501498
return {"X_types": ["np_list", "3darray"], "equal_length_only": False}
502499

503500
@classmethod
504-
def get_test_params(
505-
cls, parameter_set: Union[str, None] = None
506-
) -> Union[dict, List[dict]]:
501+
def get_test_params(cls, parameter_set: str | None = None) -> dict | list[dict]:
507502
"""Return unit test parameter settings for the estimator.
508503
509504
Parameters

tsml/datasets/_data_io.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Data loading functions."""
22

33
import os
4-
from typing import Tuple, Union
54

65
import numpy as np
76

@@ -19,10 +18,10 @@
1918

2019
def load_from_ts_file(
2120
file_path: str,
22-
replace_missing_vals_with: Union[str, int, float] = "NaN",
23-
X_dtype: Union[None, type] = None,
24-
y_dtype: Union[None, type] = None,
25-
) -> Union[np.ndarray, list, Tuple[np.ndarray, np.ndarray], Tuple[list, np.ndarray]]:
21+
replace_missing_vals_with: str | int | float = "NaN",
22+
X_dtype: None | type = None,
23+
y_dtype: None | type = None,
24+
) -> np.ndarray | list | tuple[np.ndarray, np.ndarray] | tuple[list, np.ndarray]:
2625
"""Load data from a .ts file into a 3D numpy array or list of 2D numpy arrays.
2726
2827
If the data to be loaded is equal length, a 3D numpy array will be returned. If the
@@ -425,8 +424,8 @@ def load_from_ts_file(
425424

426425

427426
def load_minimal_chinatown(
428-
split: Union[None, str] = None
429-
) -> Tuple[np.ndarray, np.ndarray]:
427+
split: None | str = None,
428+
) -> tuple[np.ndarray, np.ndarray]:
430429
"""Load MinimalChinatown time series classification problem.
431430
432431
This is an equal length univariate time series classification problem. It is a
@@ -459,8 +458,8 @@ def load_minimal_chinatown(
459458

460459

461460
def load_unequal_minimal_chinatown(
462-
split: Union[None, str] = None
463-
) -> Tuple[list, np.ndarray]:
461+
split: None | str = None,
462+
) -> tuple[list, np.ndarray]:
464463
"""Load UnequalMinimalChinatown time series classification problem.
465464
466465
This is an unequal length univariate time series classification problem. It is a
@@ -495,8 +494,8 @@ def load_unequal_minimal_chinatown(
495494

496495

497496
def load_equal_minimal_japanese_vowels(
498-
split: Union[None, str] = None
499-
) -> Tuple[np.ndarray, np.ndarray]:
497+
split: None | str = None,
498+
) -> tuple[np.ndarray, np.ndarray]:
500499
"""Load the EqualMinimalJapaneseVowels time series classification problem.
501500
502501
This is an equal length multivariate time series classification problem. It is a
@@ -530,8 +529,8 @@ def load_equal_minimal_japanese_vowels(
530529

531530

532531
def load_minimal_japanese_vowels(
533-
split: Union[None, str] = None
534-
) -> Tuple[list, np.ndarray]:
532+
split: None | str = None,
533+
) -> tuple[list, np.ndarray]:
535534
"""Load the MinimalJapaneseVowels time series classification problem.
536535
537536
This is an unequal length multivariate time series classification problem. It is a
@@ -565,8 +564,8 @@ def load_minimal_japanese_vowels(
565564

566565

567566
def load_minimal_gas_prices(
568-
split: Union[None, str] = None
569-
) -> Tuple[np.ndarray, np.ndarray]:
567+
split: None | str = None,
568+
) -> tuple[np.ndarray, np.ndarray]:
570569
"""Load the MinimalGasPrices time series extrinsic regression problem.
571570
572571
This is an equal length univariate time series regression problem. It is a
@@ -596,8 +595,8 @@ def load_minimal_gas_prices(
596595

597596

598597
def load_unequal_minimal_gas_prices(
599-
split: Union[None, str] = None
600-
) -> Tuple[list, np.ndarray]:
598+
split: None | str = None,
599+
) -> tuple[list, np.ndarray]:
601600
"""Load the UnequalMinimalGasPrices time series extrinsic regression problem.
602601
603602
This is an unequal length univariate time series regression problem. It is a
@@ -629,8 +628,8 @@ def load_unequal_minimal_gas_prices(
629628

630629
def _load_provided_dataset(
631630
name: str,
632-
split: Union[None, str] = None,
633-
) -> Union[Tuple[np.ndarray, np.ndarray], Tuple[list, np.ndarray]]:
631+
split: None | str = None,
632+
) -> tuple[np.ndarray, np.ndarray] | tuple[list, np.ndarray]:
634633
"""Load baked in time series datasets.
635634
636635
Loads data from the provided tsml dataset files only.

0 commit comments

Comments
 (0)