Skip to content

Commit

Permalink
Update Python version requirement to 3.9 in accordance with NEP 29 (#418
Browse files Browse the repository at this point in the history
)

* Bump minimal Python to ≥3.8

* Drop support for 3.8
  • Loading branch information
basnijholt committed Apr 30, 2023
1 parent 0936a93 commit 6014918
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand Down
9 changes: 5 additions & 4 deletions adaptive/learner/average_learner1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import math
import sys
from collections import defaultdict
from collections.abc import Iterable, Sequence
from copy import deepcopy
from math import hypot
from typing import Callable, DefaultDict, Iterable, List, Sequence, Tuple
from typing import Callable

import numpy as np
import scipy.stats
Expand All @@ -25,8 +26,8 @@
except ModuleNotFoundError:
with_pandas = False

Point = Tuple[int, Real]
Points = List[Point]
Point = tuple[int, Real]
Points = list[Point]

__all__: list[str] = ["AverageLearner1D"]

Expand Down Expand Up @@ -504,7 +505,7 @@ def tell_many( # type: ignore[override]
)

# Create a mapping of points to a list of samples
mapping: DefaultDict[Real, DefaultDict[Int, Real]] = defaultdict(
mapping: defaultdict[Real, defaultdict[Int, Real]] = defaultdict(
lambda: defaultdict(dict)
)
for (seed, x), y in zip(xs, ys):
Expand Down
13 changes: 5 additions & 8 deletions adaptive/learner/balancing_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import itertools
import sys
from collections import defaultdict
from collections.abc import Iterable
from collections.abc import Iterable, Sequence
from contextlib import suppress
from functools import partial
from operator import itemgetter
from typing import Any, Callable, Dict, Sequence, Tuple, Union, cast
from typing import Any, Callable, Union, cast

import numpy as np

Expand All @@ -21,10 +21,7 @@
else:
from typing_extensions import TypeAlias

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
from typing import Literal

try:
import pandas
Expand All @@ -42,8 +39,8 @@ def dispatch(child_functions: list[Callable], arg: Any) -> Any:
STRATEGY_TYPE: TypeAlias = Literal["loss_improvements", "loss", "npoints", "cycle"]

CDIMS_TYPE: TypeAlias = Union[
Sequence[Dict[str, Any]],
Tuple[Sequence[str], Sequence[Tuple[Any, ...]]],
Sequence[dict[str, Any]],
tuple[Sequence[str], Sequence[tuple[Any, ...]]],
None,
]

Expand Down
4 changes: 2 additions & 2 deletions adaptive/learner/base_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import abc
from contextlib import suppress
from typing import TYPE_CHECKING, Any, Callable, Dict, TypeVar
from typing import TYPE_CHECKING, Any, Callable, TypeVar

import cloudpickle

Expand Down Expand Up @@ -66,7 +66,7 @@ def _wrapped(loss_per_interval):
return _wrapped


DataType = Dict[Any, Any]
DataType = dict[Any, Any]


class BaseLearner(abc.ABC):
Expand Down
4 changes: 2 additions & 2 deletions adaptive/learner/integrator_coeffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from collections import defaultdict
from fractions import Fraction
from functools import lru_cache
from functools import cache

import numpy as np
import scipy.linalg
Expand Down Expand Up @@ -143,7 +143,7 @@ def calc_V(x: np.ndarray, n: int) -> np.ndarray:
return np.array(V).T


@lru_cache(maxsize=None)
@cache
def _coefficients():
"""Compute the coefficients on demand, in order to avoid doing linear algebra on import."""
eps = np.spacing(1)
Expand Down
21 changes: 11 additions & 10 deletions adaptive/learner/learner1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import itertools
import math
import sys
from collections.abc import Sequence
from copy import copy, deepcopy
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Sequence, Tuple, Union
from typing import TYPE_CHECKING, Any, Callable, Optional, Union

import cloudpickle
import numpy as np
Expand Down Expand Up @@ -41,27 +42,27 @@
# -- types --

# Commonly used types
Interval: TypeAlias = Union[Tuple[float, float], Tuple[float, float, int]]
NeighborsType: TypeAlias = SortedDict[float, List[Optional[float]]]
Interval: TypeAlias = Union[tuple[float, float], tuple[float, float, int]]
NeighborsType: TypeAlias = SortedDict[float, list[Optional[float]]]

# Types for loss_per_interval functions
XsType0: TypeAlias = Tuple[float, float]
YsType0: TypeAlias = Union[Tuple[float, float], Tuple[np.ndarray, np.ndarray]]
XsType1: TypeAlias = Tuple[
XsType0: TypeAlias = tuple[float, float]
YsType0: TypeAlias = Union[tuple[float, float], tuple[np.ndarray, np.ndarray]]
XsType1: TypeAlias = tuple[
Optional[float], Optional[float], Optional[float], Optional[float]
]
YsType1: TypeAlias = Union[
Tuple[Optional[float], Optional[float], Optional[float], Optional[float]],
Tuple[
tuple[Optional[float], Optional[float], Optional[float], Optional[float]],
tuple[
Optional[np.ndarray],
Optional[np.ndarray],
Optional[np.ndarray],
Optional[np.ndarray],
],
]
XsTypeN: TypeAlias = Tuple[Optional[float], ...]
XsTypeN: TypeAlias = tuple[Optional[float], ...]
YsTypeN: TypeAlias = Union[
Tuple[Optional[float], ...], Tuple[Optional[np.ndarray], ...]
tuple[Optional[float], ...], tuple[Optional[np.ndarray], ...]
]


Expand Down
3 changes: 2 additions & 1 deletion adaptive/learner/learner2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import itertools
import warnings
from collections import OrderedDict
from collections.abc import Iterable
from copy import copy
from math import sqrt
from typing import Callable, Iterable
from typing import Callable

import cloudpickle
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion adaptive/learner/learnerND.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ def _get_iso(self, level=0.0, which="surface"):
vertices = [] # index -> (x,y,z)
faces_or_lines = [] # tuple of indices of the corner points

@functools.lru_cache()
@functools.lru_cache
def _get_vertex_index(a, b):
vertex_a = self.tri.vertices[a]
vertex_b = self.tri.vertices[b]
Expand Down
4 changes: 2 additions & 2 deletions adaptive/learner/sequence_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys
from copy import copy
from typing import Any, Tuple
from typing import Any

import cloudpickle
from sortedcontainers import SortedDict, SortedSet
Expand All @@ -28,7 +28,7 @@
else:
from typing_extensions import TypeAlias

PointType: TypeAlias = Tuple[Int, Any]
PointType: TypeAlias = tuple[Int, Any]


class _IgnoreFirstArgument:
Expand Down
7 changes: 1 addition & 6 deletions adaptive/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from contextlib import suppress
from datetime import datetime, timedelta
from importlib.util import find_spec
from typing import TYPE_CHECKING, Any, Callable, Optional, Union
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Union

import loky

Expand Down Expand Up @@ -46,11 +46,6 @@
else:
from typing_extensions import TypeAlias

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal


with_ipyparallel = find_spec("ipyparallel") is not None
with_distributed = find_spec("distributed") is not None
Expand Down
5 changes: 3 additions & 2 deletions adaptive/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import os
import pickle
import warnings
from collections.abc import Iterator, Sequence
from contextlib import contextmanager
from itertools import product
from typing import Any, Callable, Iterator, Sequence
from typing import Any, Callable

import cloudpickle

Expand Down Expand Up @@ -147,7 +148,7 @@ class SequentialExecutor(concurrent.Executor):
This executor is mainly for testing.
"""

def submit(self, fn: Callable, *args, **kwargs) -> concurrent.Future:
def submit(self, fn: Callable, *args, **kwargs) -> concurrent.Future: # type: ignore[override]
fut: concurrent.Future = concurrent.Future()
try:
fut.set_result(fn(*args, **kwargs))
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"environment_type": "conda",
"install_timeout": 600,
"show_commit_url": "https://github.com/python-adaptive/adaptive/commits/",
"pythons": ["3.7"],
"pythons": ["3.11"],
"conda_channels": ["conda-forge"],
"matrix": {
"numpy": ["1.13"],
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import nox


@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11"])
@nox.session(python=["3.9", "3.10", "3.11"])
@nox.parametrize("all_deps", [True, False])
def pytest(session, all_deps):
session.install(".[testing,other]" if all_deps else ".[testing]")
Expand Down
13 changes: 4 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ dynamic = ["version"]
description = "Parallel active learning of mathematical functions"
maintainers = [{ name = "Adaptive authors" }]
license = { text = "BSD" }
requires-python = ">=3.7"
requires-python = ">=3.9"
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: BSD License",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand All @@ -30,8 +28,6 @@ dependencies = [

[project.optional-dependencies]
other = [
"ipython; python_version > '3.8'",
"ipython<8.13; python_version <= '3.8'", # because https://github.com/ipython/ipython/issues/14053
"dill",
"distributed",
"ipyparallel>=6.2.5", # because of https://github.com/ipython/ipyparallel/issues/404
Expand All @@ -41,8 +37,7 @@ other = [
"pexpect; os_name != 'nt'",
]
notebook = [
"ipython; python_version > '3.8'",
"ipython<8.13; python_version <= '3.8'", # because https://github.com/ipython/ipython/issues/14053
"ipython",
"ipykernel>=4.8.0", # because https://github.com/ipython/ipykernel/issues/274 and https://github.com/ipython/ipykernel/issues/263
"jupyter_client>=5.2.2", # because https://github.com/jupyter/jupyter_client/pull/314
"holoviews>=1.9.1",
Expand Down Expand Up @@ -96,11 +91,11 @@ output = ".coverage.xml"

[tool.mypy]
ignore_missing_imports = true
python_version = "3.7"
python_version = "3.9"

[tool.ruff]
line-length = 150
target-version = "py37"
target-version = "py39"
select = ["B", "C", "E", "F", "W", "T", "B9", "I", "UP"]
ignore = [
"T20", # flake8-print
Expand Down

0 comments on commit 6014918

Please sign in to comment.