Skip to content

Commit 7f76093

Browse files
authored
Merge pull request #325 from python-adaptive/learner1d-type-hints
Learner1D type hints and add typeguard to pytest tests
2 parents 455c60c + b10e18d commit 7f76093

File tree

8 files changed

+150
-70
lines changed

8 files changed

+150
-70
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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

0 commit comments

Comments
 (0)