Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNT] Add typecheck workflow using mypy #2092

Merged
merged 6 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/pr_typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: PR Typecheck

on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- "aeon/**"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
typecheck:
# run the code coverage job if a PR has the '' label
if: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'run typecheck test') }}
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install aeon, dependencies and mypy
uses: nick-fields/retry@v3
with:
timeout_minutes: 30
max_attempts: 3
command: python -m pip install .[all_extras,unstable_extras,dev] mypy

- name: Show dependencies
run: python -m pip list

- name: Run mypy typecheck
run: mypy aeon/
4 changes: 3 additions & 1 deletion aeon/classification/distance_based/_proximity_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
The Proximity Forest is an ensemble of Proximity Trees.
"""

from typing import Optional

__all__ = ["ProximityForest"]

from typing import Union
Expand Down Expand Up @@ -87,7 +89,7 @@ def __init__(
self,
n_trees=100,
n_splitters: int = 5,
max_depth: int = None,
max_depth: Optional[int] = None,
min_samples_split: int = 2,
random_state: Union[int, np.random.RandomState, None] = None,
n_jobs: int = 1,
Expand Down
4 changes: 2 additions & 2 deletions aeon/classification/distance_based/_proximity_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
aeon distances.
"""

from typing import Union
from typing import Optional, Union

import numpy as np
from numba import njit
Expand Down Expand Up @@ -118,7 +118,7 @@ class ProximityTree(BaseClassifier):
def __init__(
self,
n_splitters: int = 5,
max_depth: int = None,
max_depth: Optional[int] = None,
min_samples_split: int = 2,
random_state: Union[int, np.random.RandomState, None] = None,
) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
distances in aeon.distances.
"""

from typing import Optional

__maintainer__ = []
__all__ = ["KNeighborsTimeSeriesClassifier"]

Expand Down Expand Up @@ -72,7 +74,7 @@ class KNeighborsTimeSeriesClassifier(BaseClassifier):
def __init__(
self,
distance: Union[str, Callable] = "dtw",
distance_params: dict = None,
distance_params: Optional[dict] = None,
n_neighbors: int = 1,
weights: Union[str, Callable] = "uniform",
n_jobs: int = 1,
Expand Down
4 changes: 3 additions & 1 deletion aeon/classification/shapelet_based/_sast.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Pipeline classifier using the SAST transformer and an sklearn classifier.
"""

from typing import Optional

__maintainer__ = ["TonyBagnall"]
__all__ = ["SASTClassifier"]

Expand Down Expand Up @@ -69,7 +71,7 @@ def __init__(
length_list=None,
stride: int = 1,
nb_inst_per_class: int = 1,
seed: int = None,
seed: Optional[int] = None,
classifier=None,
n_jobs: int = -1,
) -> None:
Expand Down
8 changes: 5 additions & 3 deletions aeon/clustering/_clara.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Time series kmedoids."""

from typing import Optional

__maintainer__ = []

from typing import Callable, Union
Expand Down Expand Up @@ -118,14 +120,14 @@ def __init__(
n_clusters: int = 8,
init_algorithm: Union[str, np.ndarray] = "random",
distance: Union[str, Callable] = "msm",
n_samples: int = None,
n_samples: Optional[int] = None,
n_sampling_iters: int = 10,
n_init: int = 1,
max_iter: int = 300,
tol: float = 1e-6,
verbose: bool = False,
random_state: Union[int, RandomState] = None,
distance_params: dict = None,
random_state: Optional[Union[int, RandomState]] = None,
distance_params: Optional[dict] = None,
):
self.init_algorithm = init_algorithm
self.distance = distance
Expand Down
8 changes: 5 additions & 3 deletions aeon/clustering/_clarans.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Time series kmedoids."""

from typing import Optional

__maintainer__ = []

import math
Expand Down Expand Up @@ -104,11 +106,11 @@ def __init__(
n_clusters: int = 8,
init_algorithm: Union[str, np.ndarray] = "random",
distance: Union[str, Callable] = "msm",
max_neighbours: int = None,
max_neighbours: Optional[int] = None,
n_init: int = 10,
verbose: bool = False,
random_state: Union[int, RandomState] = None,
distance_params: dict = None,
random_state: Optional[Union[int, RandomState]] = None,
distance_params: Optional[dict] = None,
):
self.max_neighbours = max_neighbours

Expand Down
10 changes: 6 additions & 4 deletions aeon/clustering/_k_means.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Time series kmeans."""

from typing import Optional

__maintainer__ = []

from typing import Callable, Union
Expand Down Expand Up @@ -163,11 +165,11 @@ def __init__(
max_iter: int = 300,
tol: float = 1e-6,
verbose: bool = False,
random_state: Union[int, RandomState] = None,
random_state: Optional[Union[int, RandomState]] = None,
averaging_method: Union[str, Callable[[np.ndarray], np.ndarray]] = "ba",
distance_params: dict = None,
average_params: dict = None,
init_algorithm: Union[str, np.ndarray] = None,
distance_params: Optional[dict] = None,
average_params: Optional[dict] = None,
init_algorithm: Optional[Union[str, np.ndarray]] = None,
):
self.init = init
self.init_algorithm = init_algorithm
Expand Down
6 changes: 4 additions & 2 deletions aeon/clustering/_k_medoids.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Time series kmedoids."""

from typing import Optional

__maintainer__ = []

import warnings
Expand Down Expand Up @@ -157,8 +159,8 @@ def __init__(
max_iter: int = 300,
tol: float = 1e-6,
verbose: bool = False,
random_state: Union[int, RandomState] = None,
distance_params: dict = None,
random_state: Optional[Union[int, RandomState]] = None,
distance_params: Optional[dict] = None,
):
self.init_algorithm = init_algorithm
self.distance = distance
Expand Down
4 changes: 2 additions & 2 deletions aeon/clustering/_k_shape.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Time series kshapes."""

from typing import Union
from typing import Optional, Union

import numpy as np
from numpy.random import RandomState
Expand Down Expand Up @@ -82,7 +82,7 @@ def __init__(
max_iter: int = 300,
tol: float = 1e-4,
verbose: bool = False,
random_state: Union[int, RandomState] = None,
random_state: Optional[Union[int, RandomState]] = None,
):
self.init_algorithm = init_algorithm
self.n_init = n_init
Expand Down
4 changes: 2 additions & 2 deletions aeon/clustering/_k_shapes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Time series kshapes."""

from typing import Union
from typing import Optional, Union

import numpy as np
from deprecated.sphinx import deprecated
Expand Down Expand Up @@ -83,7 +83,7 @@ def __init__(
max_iter: int = 300,
tol: float = 1e-4,
verbose: bool = False,
random_state: Union[int, RandomState] = None,
random_state: Optional[Union[int, RandomState]] = None,
):
self.init_algorithm = init_algorithm
self.n_init = n_init
Expand Down
4 changes: 2 additions & 2 deletions aeon/clustering/_kernel_k_means.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Time series kernel kmeans."""

from typing import Union
from typing import Optional, Union

import numpy as np
from numpy.random import RandomState
Expand Down Expand Up @@ -99,7 +99,7 @@ def __init__(
kernel_params: Union[dict, None] = None,
verbose: bool = False,
n_jobs: Union[int, None] = None,
random_state: Union[int, RandomState] = None,
random_state: Optional[Union[int, RandomState]] = None,
):
self.kernel = kernel
self.n_init = n_init
Expand Down
4 changes: 3 additions & 1 deletion aeon/clustering/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Base class for clustering."""

from typing import Optional

__maintainer__ = []
__all__ = ["BaseClusterer"]

Expand All @@ -22,7 +24,7 @@ class BaseClusterer(BaseCollectionEstimator, ABC):
Number of clusters for model.
"""

def __init__(self, n_clusters: int = None):
def __init__(self, n_clusters: Optional[int] = None):
self.n_clusters = n_clusters
# required for compatibility with some sklearn interfaces e.g.
# CalibratedClassifierCV
Expand Down
4 changes: 3 additions & 1 deletion aeon/datasets/_data_loaders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Dataset loading functions."""

from typing import Optional

__all__ = [ # Load functions
"load_from_tsfile",
"load_from_tsf_file",
Expand Down Expand Up @@ -680,7 +682,7 @@ def load_from_tsv_file(full_file_path_and_name):
def _convert_tsf_to_hierarchical(
data: pd.DataFrame,
metadata,
freq: str = None,
freq: Optional[str] = None,
value_column_name: str = "series_value",
) -> pd.DataFrame:
"""Convert the data from default_tsf to pd_multiindex_hier.
Expand Down
4 changes: 3 additions & 1 deletion aeon/regression/distance_based/_time_series_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
It can also be used with callables, or aeon (pairwise transformer) estimators.
"""

from typing import Optional

__maintainer__ = []
__all__ = ["KNeighborsTimeSeriesRegressor"]

Expand Down Expand Up @@ -72,7 +74,7 @@ class KNeighborsTimeSeriesRegressor(BaseRegressor):
def __init__(
self,
distance: Union[str, Callable] = "dtw",
distance_params: dict = None,
distance_params: Optional[dict] = None,
n_neighbors: int = 1,
weights: Union[str, Callable] = "uniform",
n_jobs: int = 1,
Expand Down
3 changes: 2 additions & 1 deletion aeon/segmentation/_ggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import logging
import math
from dataclasses import dataclass, field
from typing import Optional

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -457,7 +458,7 @@ def __init__(
lamb: float = 1.0,
max_shuffles: int = 250,
verbose: bool = False,
random_state: int = None,
random_state: Optional[int] = None,
):
self.k_max = k_max
self.lamb = lamb
Expand Down
3 changes: 2 additions & 1 deletion aeon/segmentation/_hmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

import warnings
from typing import Optional

import numpy as np
from scipy.stats import norm
Expand Down Expand Up @@ -137,7 +138,7 @@ def __init__(
self,
emission_funcs: list,
transition_prob_mat: np.ndarray,
initial_probs: np.ndarray = None,
initial_probs: Optional[np.ndarray] = None,
):
self.initial_probs = initial_probs
self.emission_funcs = emission_funcs
Expand Down
10 changes: 6 additions & 4 deletions aeon/similarity_search/matrix_profiles/stomp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Implementation of stomp for euclidean and squared euclidean distance profile."""

from typing import Optional

__maintainer__ = ["baraline"]


Expand Down Expand Up @@ -29,7 +31,7 @@ def stomp_euclidean_matrix_profile(
k: int = 1,
threshold: float = np.inf,
inverse_distance: bool = False,
exclusion_size: int = None,
exclusion_size: Optional[int] = None,
):
"""
Compute a euclidean euclidean matrix profile using STOMP [1]_.
Expand Down Expand Up @@ -109,7 +111,7 @@ def stomp_squared_matrix_profile(
k: int = 1,
threshold: float = np.inf,
inverse_distance: bool = False,
exclusion_size: int = None,
exclusion_size: Optional[int] = None,
):
"""
Compute a squared euclidean matrix profile using STOMP [1]_.
Expand Down Expand Up @@ -198,7 +200,7 @@ def stomp_normalized_euclidean_matrix_profile(
k: int = 1,
threshold: float = np.inf,
inverse_distance: bool = False,
exclusion_size: int = None,
exclusion_size: Optional[int] = None,
):
"""
Compute a euclidean matrix profile using STOMP [1]_.
Expand Down Expand Up @@ -296,7 +298,7 @@ def stomp_normalized_squared_matrix_profile(
k: int = 1,
threshold: float = np.inf,
inverse_distance: bool = False,
exclusion_size: int = None,
exclusion_size: Optional[int] = None,
):
"""
Compute a squared euclidean matrix profile using STOMP [1]_.
Expand Down
Loading