Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 02b5064

Browse filesBrowse files
committed
Merge remote-tracking branch 'origin/main' into typeguard-4
2 parents 8b9faf8 + e0809ae commit 02b5064
Copy full SHA for 02b5064

29 files changed

+489
-271
lines changed

‎.github/workflows/coverage.yml

Copy file name to clipboardExpand all lines: .github/workflows/coverage.yml
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
with:
1414
python-version: 3.7
1515
- name: Install dependencies
16-
run: pip install nox codecov
16+
run: pip install nox
1717
- name: Test with nox
1818
run: nox -e coverage
19-
- name: Upload test coverage
20-
run: codecov -t ${{ secrets.CODECOV_TOKEN }} -f .coverage.xml
19+
- name: Upload coverage to Codecov
20+
uses: codecov/codecov-action@v3

‎.pre-commit-config.yaml

Copy file name to clipboardExpand all lines: .pre-commit-config.yaml
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repos:
1313
hooks:
1414
- id: black-jupyter
1515
- repo: https://github.com/charliermarsh/ruff-pre-commit
16-
rev: "v0.0.261"
16+
rev: "v0.0.262"
1717
hooks:
1818
- id: ruff
1919
args: ["--fix"]
@@ -25,3 +25,8 @@ repos:
2525
- id: nbqa
2626
args: ["ruff", "--fix", "--ignore=E402,B018,F704"]
2727
additional_dependencies: [jupytext, ruff]
28+
- repo: https://github.com/pre-commit/mirrors-mypy
29+
rev: "v1.2.0"
30+
hooks:
31+
- id: mypy
32+
exclude: ipynb_filter.py|docs/source/conf.py

‎adaptive/__init__.py

Copy file name to clipboardExpand all lines: adaptive/__init__.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@
5454
__all__.append("SKOptLearner")
5555

5656
# to avoid confusion with `notebook_extension` and `__version__`
57-
del _version # noqa: F821
58-
del notebook_integration # noqa: F821
57+
del _version # type: ignore[name-defined] # noqa: F821
58+
del notebook_integration # type: ignore[name-defined] # noqa: F821

‎adaptive/_version.py

Copy file name to clipboardExpand all lines: adaptive/_version.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is part of 'miniver': https://github.com/jbweston/miniver
22
#
3+
from __future__ import annotations
4+
35
import os
46
import subprocess
57
from collections import namedtuple
@@ -10,7 +12,7 @@
1012
Version = namedtuple("Version", ("release", "dev", "labels"))
1113

1214
# No public API
13-
__all__ = []
15+
__all__: list[str] = []
1416

1517
package_root = os.path.dirname(os.path.realpath(__file__))
1618
package_name = os.path.basename(package_root)

‎adaptive/learner/average_learner.py

Copy file name to clipboardExpand all lines: adaptive/learner/average_learner.py
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
from __future__ import annotations
22

33
from math import sqrt
4-
from numbers import Integral as Int
5-
from numbers import Real
64
from typing import Callable
75

86
import cloudpickle
97
import numpy as np
108

119
from adaptive.learner.base_learner import BaseLearner
1210
from adaptive.notebook_integration import ensure_holoviews
13-
from adaptive.types import Float
11+
from adaptive.types import Float, Int, Real
1412
from adaptive.utils import (
1513
assign_defaults,
1614
cache_latest,
@@ -88,7 +86,7 @@ def to_numpy(self):
8886
"""Data as NumPy array of size (npoints, 2) with seeds and values."""
8987
return np.array(sorted(self.data.items()))
9088

91-
def to_dataframe(
89+
def to_dataframe( # type: ignore[override]
9290
self,
9391
with_default_function_args: bool = True,
9492
function_prefix: str = "function.",
@@ -128,7 +126,7 @@ def to_dataframe(
128126
assign_defaults(self.function, df, function_prefix)
129127
return df
130128

131-
def load_dataframe(
129+
def load_dataframe( # type: ignore[override]
132130
self,
133131
df: pandas.DataFrame,
134132
with_default_function_args: bool = True,

‎adaptive/learner/average_learner1D.py

Copy file name to clipboardExpand all lines: adaptive/learner/average_learner1D.py
+18-19Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from collections import defaultdict
66
from copy import deepcopy
77
from math import hypot
8-
from numbers import Integral as Int
9-
from numbers import Real
108
from typing import Callable, DefaultDict, Iterable, List, Sequence, Tuple
119

1210
import numpy as np
@@ -16,6 +14,7 @@
1614

1715
from adaptive.learner.learner1D import Learner1D, _get_intervals
1816
from adaptive.notebook_integration import ensure_holoviews
17+
from adaptive.types import Int, Real
1918
from adaptive.utils import assign_defaults, partial_function_from_dataframe
2019

2120
try:
@@ -99,7 +98,7 @@ def __init__(
9998
if min_samples > max_samples:
10099
raise ValueError("max_samples should be larger than min_samples.")
101100

102-
super().__init__(function, bounds, loss_per_interval)
101+
super().__init__(function, bounds, loss_per_interval) # type: ignore[arg-type]
103102

104103
self.delta = delta
105104
self.alpha = alpha
@@ -110,7 +109,7 @@ def __init__(
110109

111110
# Contains all samples f(x) for each
112111
# point x in the form {x0: {0: f_0(x0), 1: f_1(x0), ...}, ...}
113-
self._data_samples = SortedDict()
112+
self._data_samples: SortedDict[float, dict[int, Real]] = SortedDict()
114113
# Contains the number of samples taken
115114
# at each point x in the form {x0: n0, x1: n1, ...}
116115
self._number_samples = SortedDict()
@@ -124,14 +123,14 @@ def __init__(
124123
# form {xi: ((xii-xi)^2 + (yii-yi)^2)^0.5, ...}
125124
self._distances: dict[Real, float] = decreasing_dict()
126125
# {xii: error[xii]/min(_distances[xi], _distances[xii], ...}
127-
self.rescaled_error: dict[Real, float] = decreasing_dict()
126+
self.rescaled_error: ItemSortedDict[Real, float] = decreasing_dict()
128127

129128
def new(self) -> AverageLearner1D:
130129
"""Create a copy of `~adaptive.AverageLearner1D` without the data."""
131130
return AverageLearner1D(
132131
self.function,
133132
self.bounds,
134-
self.loss_per_interval,
133+
self.loss_per_interval, # type: ignore[arg-type]
135134
self.delta,
136135
self.alpha,
137136
self.neighbor_sampling,
@@ -163,7 +162,7 @@ def to_numpy(self, mean: bool = False) -> np.ndarray:
163162
]
164163
)
165164

166-
def to_dataframe(
165+
def to_dataframe( # type: ignore[override]
167166
self,
168167
mean: bool = False,
169168
with_default_function_args: bool = True,
@@ -201,10 +200,10 @@ def to_dataframe(
201200
if not with_pandas:
202201
raise ImportError("pandas is not installed.")
203202
if mean:
204-
data = sorted(self.data.items())
203+
data: list[tuple[Real, Real]] = sorted(self.data.items())
205204
columns = [x_name, y_name]
206205
else:
207-
data = [
206+
data: list[tuple[int, Real, Real]] = [ # type: ignore[no-redef]
208207
(seed, x, y)
209208
for x, seed_y in sorted(self._data_samples.items())
210209
for seed, y in sorted(seed_y.items())
@@ -217,7 +216,7 @@ def to_dataframe(
217216
assign_defaults(self.function, df, function_prefix)
218217
return df
219218

220-
def load_dataframe(
219+
def load_dataframe( # type: ignore[override]
221220
self,
222221
df: pandas.DataFrame,
223222
with_default_function_args: bool = True,
@@ -257,7 +256,7 @@ def load_dataframe(
257256
self.function, df, function_prefix
258257
)
259258

260-
def ask(self, n: int, tell_pending: bool = True) -> tuple[Points, list[float]]:
259+
def ask(self, n: int, tell_pending: bool = True) -> tuple[Points, list[float]]: # type: ignore[override]
261260
"""Return 'n' points that are expected to maximally reduce the loss."""
262261
# If some point is undersampled, resample it
263262
if len(self._undersampled_points):
@@ -310,18 +309,18 @@ def _ask_for_new_point(self, n: int) -> tuple[Points, list[float]]:
310309
new point, since in general n << min_samples and this point will need
311310
to be resampled many more times"""
312311
points, (loss_improvement,) = self._ask_points_without_adding(1)
313-
points = [(seed, x) for seed, x in zip(range(n), n * points)]
312+
seed_points = [(seed, x) for seed, x in zip(range(n), n * points)]
314313
loss_improvements = [loss_improvement / n] * n
315-
return points, loss_improvements
314+
return seed_points, loss_improvements # type: ignore[return-value]
316315

317-
def tell_pending(self, seed_x: Point) -> None:
316+
def tell_pending(self, seed_x: Point) -> None: # type: ignore[override]
318317
_, x = seed_x
319318
self.pending_points.add(seed_x)
320319
if x not in self.data:
321320
self._update_neighbors(x, self.neighbors_combined)
322321
self._update_losses(x, real=False)
323322

324-
def tell(self, seed_x: Point, y: Real) -> None:
323+
def tell(self, seed_x: Point, y: Real) -> None: # type: ignore[override]
325324
seed, x = seed_x
326325
if y is None:
327326
raise TypeError(
@@ -492,7 +491,7 @@ def _calc_error_in_mean(self, ys: Iterable[Real], y_avg: Real, n: int) -> float:
492491
t_student = scipy.stats.t.ppf(1 - self.alpha, df=n - 1)
493492
return t_student * (variance_in_mean / n) ** 0.5
494493

495-
def tell_many(
494+
def tell_many( # type: ignore[override]
496495
self, xs: Points | np.ndarray, ys: Sequence[Real] | np.ndarray
497496
) -> None:
498497
# Check that all x are within the bounds
@@ -577,10 +576,10 @@ def tell_many_at_point(self, x: Real, seed_y_mapping: dict[int, Real]) -> None:
577576
self._update_interpolated_loss_in_interval(*interval)
578577
self._oldscale = deepcopy(self._scale)
579578

580-
def _get_data(self) -> dict[Real, dict[Int, Real]]:
579+
def _get_data(self) -> dict[Real, dict[Int, Real]]: # type: ignore[override]
581580
return self._data_samples
582581

583-
def _set_data(self, data: dict[Real, dict[Int, Real]]) -> None:
582+
def _set_data(self, data: dict[Real, dict[Int, Real]]) -> None: # type: ignore[override]
584583
if data:
585584
for x, samples in data.items():
586585
self.tell_many_at_point(x, samples)
@@ -615,7 +614,7 @@ def plot(self):
615614
return p.redim(x={"range": plot_bounds})
616615

617616

618-
def decreasing_dict() -> dict:
617+
def decreasing_dict() -> ItemSortedDict:
619618
"""This initialization orders the dictionary from large to small values"""
620619

621620
def sorting_rule(key, value):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.