From d21cba21cf9ffb1dfcb384a71aca09f81d504918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Royer?= Date: Sat, 29 Jun 2024 00:22:40 +0200 Subject: [PATCH] Fix mypy errors Mark the parameters with a default value of None as optionals. --- river/anomaly/lof.py | 2 +- river/anomaly/sad.py | 2 +- river/bandit/base.py | 2 +- river/bandit/evaluate.py | 2 +- river/bandit/thompson.py | 2 +- river/bandit/ucb.py | 2 +- river/drift/binary/fhddm.py | 2 +- river/forest/aggregated_mondrian_forest.py | 2 +- river/linear_model/bayesian_lin_reg.py | 2 +- river/neighbors/ann/swinn.py | 8 ++++---- river/tree/mondrian/mondrian_tree_regressor.py | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/river/anomaly/lof.py b/river/anomaly/lof.py index ea6b3624fb..542d4a882f 100644 --- a/river/anomaly/lof.py +++ b/river/anomaly/lof.py @@ -253,7 +253,7 @@ class LocalOutlierFactor(anomaly.base.AnomalyDetector): def __init__( self, n_neighbors: int = 10, - distance_func: DistanceFunc = None, + distance_func: DistanceFunc | None = None, ): self.n_neighbors = n_neighbors self.x_list: list = [] diff --git a/river/anomaly/sad.py b/river/anomaly/sad.py index 68cc1835ee..9d6ff1e498 100644 --- a/river/anomaly/sad.py +++ b/river/anomaly/sad.py @@ -59,7 +59,7 @@ class StandardAbsoluteDeviation(anomaly.base.SupervisedAnomalyDetector): """ - def __init__(self, sub_stat: stats.base.Univariate = None): + def __init__(self, sub_stat: stats.base.Univariate | None = None): self.variance = stats.Var() self.sub_stat = sub_stat or stats.Mean() diff --git a/river/bandit/base.py b/river/bandit/base.py index 0359686cae..3453a7e152 100644 --- a/river/bandit/base.py +++ b/river/bandit/base.py @@ -162,7 +162,7 @@ class ContextualPolicy(Policy): def _pull(self, arm_ids: list[ArmID], context: dict) -> ArmID: # type: ignore[override] ... - def pull(self, arm_ids: list[ArmID], context: dict = None) -> ArmID: + def pull(self, arm_ids: list[ArmID], context: dict | None = None) -> ArmID: """Pull arm(s). This method is a generator that yields the arm(s) that should be pulled. During the burn-in diff --git a/river/bandit/evaluate.py b/river/bandit/evaluate.py index 466807d475..6baf22b19c 100644 --- a/river/bandit/evaluate.py +++ b/river/bandit/evaluate.py @@ -167,7 +167,7 @@ def evaluate( def evaluate_offline( policy: bandit.base.Policy, history: History | bandit.datasets.BanditDataset, - reward_stat: stats.base.Univariate = None, + reward_stat: stats.base.Univariate | None = None, ) -> tuple[stats.base.Univariate, int]: """Evaluate a policy on historical logs using replay. diff --git a/river/bandit/thompson.py b/river/bandit/thompson.py index 88df098b1c..03cf76a5d7 100644 --- a/river/bandit/thompson.py +++ b/river/bandit/thompson.py @@ -73,7 +73,7 @@ class ThompsonSampling(bandit.base.Policy): def __init__( self, - reward_obj: proba.base.Distribution = None, + reward_obj: proba.base.Distribution | None = None, burn_in=0, seed: int | None = None, ): diff --git a/river/bandit/ucb.py b/river/bandit/ucb.py index a31ae03a72..e79f40de51 100644 --- a/river/bandit/ucb.py +++ b/river/bandit/ucb.py @@ -75,7 +75,7 @@ def __init__( reward_obj=None, reward_scaler=None, burn_in=0, - seed: int = None, + seed: int | None = None, ): super().__init__( reward_obj=reward_obj, reward_scaler=reward_scaler, burn_in=burn_in diff --git a/river/drift/binary/fhddm.py b/river/drift/binary/fhddm.py index fe70e88e87..9fc1528ec5 100644 --- a/river/drift/binary/fhddm.py +++ b/river/drift/binary/fhddm.py @@ -66,7 +66,7 @@ class FHDDM(base.BinaryDriftAndWarningDetector): """ def __init__( - self, sliding_window_size: int = 100, confidence_level: float = 0.000001, short_window_size: int = None + self, sliding_window_size: int = 100, confidence_level: float = 0.000001, short_window_size: int | None = None ): super().__init__() diff --git a/river/forest/aggregated_mondrian_forest.py b/river/forest/aggregated_mondrian_forest.py index e062e15bb0..fc250a2734 100644 --- a/river/forest/aggregated_mondrian_forest.py +++ b/river/forest/aggregated_mondrian_forest.py @@ -275,7 +275,7 @@ def __init__( n_estimators: int = 10, step: float = 1.0, use_aggregation: bool = True, - seed: int = None, + seed: int | None = None, ): super().__init__( n_estimators=n_estimators, diff --git a/river/linear_model/bayesian_lin_reg.py b/river/linear_model/bayesian_lin_reg.py index 5370d64436..f95ce53f0c 100644 --- a/river/linear_model/bayesian_lin_reg.py +++ b/river/linear_model/bayesian_lin_reg.py @@ -109,7 +109,7 @@ class BayesianLinearRegression(base.Regressor): """ - def __init__(self, alpha=1, beta=1, smoothing: float = None): + def __init__(self, alpha=1, beta=1, smoothing: float | None = None): self.alpha = alpha self.beta = beta self.smoothing = smoothing diff --git a/river/neighbors/ann/swinn.py b/river/neighbors/ann/swinn.py index 5d71b0e2c7..e774f052f1 100644 --- a/river/neighbors/ann/swinn.py +++ b/river/neighbors/ann/swinn.py @@ -93,11 +93,11 @@ def __init__( dist_func: DistanceFunc | FunctionWrapper | None = None, maxlen: int = 1000, warm_up: int = 500, - max_candidates: int = None, + max_candidates: int | None = None, delta: float = 0.0001, prune_prob: float = 0.0, n_iters: int = 10, - seed: int = None, + seed: int | None = None, ): self.graph_k = graph_k if dist_func is None: @@ -203,7 +203,7 @@ def _safe_node_removal(self, nid: int): self._refine(affected) - def _refine(self, nodes: list[int] = None): + def _refine(self, nodes: list[int] | None = None): """Update the nearest neighbor graph to improve the edge distances. Parameters @@ -343,7 +343,7 @@ def _linear_scan(self, item, k): return None - def _search(self, item, k, epsilon: float = 0.1, seed: Vertex = None, exclude: set[int] | None = None) -> tuple[list, list]: + def _search(self, item, k, epsilon: float = 0.1, seed: Vertex | None = None, exclude: set[int] | None = None) -> tuple[list, list]: # Limiter for the distance bound distance_scale = 1 + epsilon # Distance threshold for early stops diff --git a/river/tree/mondrian/mondrian_tree_regressor.py b/river/tree/mondrian/mondrian_tree_regressor.py index 54258346bd..13b302de1e 100644 --- a/river/tree/mondrian/mondrian_tree_regressor.py +++ b/river/tree/mondrian/mondrian_tree_regressor.py @@ -42,7 +42,7 @@ def __init__( step: float = 0.1, use_aggregation: bool = True, iteration: int = 0, - seed: int = None, + seed: int | None = None, ): super().__init__( step=step,