Skip to content

Commit e617ba1

Browse files
committed
fix typeguard errors
1 parent b072a6d commit e617ba1

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

adaptive/learner/average_learner1D.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
from collections import defaultdict
44
from copy import deepcopy
55
from math import hypot
6-
from typing import Callable, DefaultDict, Dict, List, Optional, Sequence, Set, Tuple
6+
from typing import (
7+
Callable,
8+
DefaultDict,
9+
Dict,
10+
Iterable,
11+
List,
12+
Optional,
13+
Sequence,
14+
Set,
15+
Tuple,
16+
)
717

818
import numpy as np
919
import scipy.stats
@@ -356,7 +366,7 @@ def _update_losses_resampling(self, x: Real, real=True) -> None:
356366
if (b is not None) and right_loss_is_unknown:
357367
self.losses_combined[x, b] = float("inf")
358368

359-
def _calc_error_in_mean(self, ys: Sequence[Real], y_avg: Real, n: int) -> float:
369+
def _calc_error_in_mean(self, ys: Iterable[Real], y_avg: Real, n: int) -> float:
360370
variance_in_mean = sum((y - y_avg) ** 2 for y in ys) / (n - 1)
361371
t_student = scipy.stats.t.ppf(1 - self.alpha, df=n - 1)
362372
return t_student * (variance_in_mean / n) ** 0.5

adaptive/learner/base_learner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
from adaptive.utils import _RequireAttrsABCMeta, load, save
66

77

8-
def uses_nth_neighbors(n):
8+
def uses_nth_neighbors(n: int):
99
"""Decorator to specify how many neighboring intervals the loss function uses.
1010
1111
Wraps loss functions to indicate that they expect intervals together
1212
with ``n`` nearest neighbors
1313
1414
The loss function will then receive the data of the N nearest neighbors
15-
(``nth_neighbors``) aling with the data of the interval itself in a dict.
15+
(``nth_neighbors``) along with the data of the interval itself in a dict.
1616
The `~adaptive.Learner1D` will also make sure that the loss is updated
1717
whenever one of the ``nth_neighbors`` changes.
1818

adaptive/learner/learner1D.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ def _set_data(self, data: Dict[float, float]) -> None:
740740
def __getstate__(self):
741741
return (
742742
cloudpickle.dumps(self.function),
743-
self.bounds,
743+
tuple(self.bounds),
744744
self.loss_per_interval,
745745
dict(self.losses), # SortedDict cannot be pickled
746746
dict(self.losses_combined), # ItemSortedDict cannot be pickled

adaptive/tests/test_average_learner.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
from adaptive.runner import simple
88

99

10+
def f_unused(seed):
11+
raise NotImplementedError("This function shouldn't be used.")
12+
13+
1014
def test_only_returns_new_points():
11-
learner = AverageLearner(lambda x: x, atol=None, rtol=0.01)
15+
learner = AverageLearner(f_unused, atol=None, rtol=0.01)
1216

1317
# Only tell it n = 5...10
1418
for i in range(5, 10):
@@ -25,7 +29,7 @@ def test_only_returns_new_points():
2529

2630
@flaky.flaky(max_runs=5)
2731
def test_avg_std_and_npoints():
28-
learner = AverageLearner(lambda x: x, atol=None, rtol=0.01)
32+
learner = AverageLearner(f_unused, atol=None, rtol=0.01)
2933

3034
for i in range(300):
3135
# This will add 5000 points at random values of n.
@@ -63,7 +67,7 @@ def constant_function(seed):
6367

6468
def test_zero_mean():
6569
# see https://github.com/python-adaptive/adaptive/issues/275
66-
learner = AverageLearner(None, rtol=0.01)
70+
learner = AverageLearner(f_unused, rtol=0.01)
6771
learner.tell(0, -1)
6872
learner.tell(1, 1)
6973
learner.loss()

adaptive/tests/test_average_learner1d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def almost_equal_dicts(a, b):
1616

1717
def test_tell_many_at_point():
1818
f = generate_random_parametrization(noisy_peak)
19-
learner = AverageLearner1D(f, bounds=[-2, 2])
20-
control = AverageLearner1D(f, bounds=[-2, 2])
19+
learner = AverageLearner1D(f, bounds=(-2, 2))
20+
control = AverageLearner1D(f, bounds=(-2, 2))
2121
learner._recompute_losses_factor = 1
2222
control._recompute_losses_factor = 1
2323
simple_run(learner, 100)

0 commit comments

Comments
 (0)