Skip to content

Commit

Permalink
Fix mypy errors
Browse files Browse the repository at this point in the history
Mark the parameters with a default value of None as optionals.
  • Loading branch information
e10e3 committed Jul 1, 2024
1 parent 6995f15 commit d21cba2
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion river/anomaly/lof.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion river/anomaly/sad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion river/bandit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion river/bandit/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion river/bandit/thompson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):
Expand Down
2 changes: 1 addition & 1 deletion river/bandit/ucb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion river/drift/binary/fhddm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down
2 changes: 1 addition & 1 deletion river/forest/aggregated_mondrian_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion river/linear_model/bayesian_lin_reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions river/neighbors/ann/swinn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion river/tree/mondrian/mondrian_tree_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down