|
3 | 3 | import collections.abc |
4 | 4 | import itertools |
5 | 5 | import math |
6 | | -import sys |
7 | | -from collections.abc import Sequence |
| 6 | +from collections.abc import Callable, Sequence |
8 | 7 | from copy import copy, deepcopy |
9 | | -from typing import TYPE_CHECKING, Any, Callable, Optional, Union |
| 8 | +from typing import TYPE_CHECKING, Any, TypeAlias |
10 | 9 |
|
11 | 10 | import cloudpickle |
12 | 11 | import numpy as np |
|
24 | 23 | partial_function_from_dataframe, |
25 | 24 | ) |
26 | 25 |
|
27 | | -if sys.version_info >= (3, 10): |
28 | | - from typing import TypeAlias |
29 | | -else: |
30 | | - from typing_extensions import TypeAlias |
31 | | - |
32 | | - |
33 | 26 | try: |
34 | 27 | import pandas |
35 | 28 |
|
|
42 | 35 | # -- types -- |
43 | 36 |
|
44 | 37 | # Commonly used types |
45 | | - Interval: TypeAlias = Union[tuple[float, float], tuple[float, float, int]] |
46 | | - NeighborsType: TypeAlias = SortedDict[float, list[Optional[float]]] |
| 38 | + Interval: TypeAlias = tuple[float, float] | tuple[float, float, int] |
| 39 | + NeighborsType: TypeAlias = SortedDict[float, list[float | None]] |
47 | 40 |
|
48 | 41 | # Types for loss_per_interval functions |
49 | 42 | XsType0: TypeAlias = tuple[float, float] |
50 | | - YsType0: TypeAlias = Union[tuple[float, float], tuple[np.ndarray, np.ndarray]] |
51 | | - XsType1: TypeAlias = tuple[ |
52 | | - Optional[float], Optional[float], Optional[float], Optional[float] |
53 | | - ] |
54 | | - YsType1: TypeAlias = Union[ |
55 | | - tuple[Optional[float], Optional[float], Optional[float], Optional[float]], |
56 | | - tuple[ |
57 | | - Optional[np.ndarray], |
58 | | - Optional[np.ndarray], |
59 | | - Optional[np.ndarray], |
60 | | - Optional[np.ndarray], |
61 | | - ], |
62 | | - ] |
63 | | - XsTypeN: TypeAlias = tuple[Optional[float], ...] |
64 | | - YsTypeN: TypeAlias = Union[ |
65 | | - tuple[Optional[float], ...], tuple[Optional[np.ndarray], ...] |
66 | | - ] |
| 43 | + YsType0: TypeAlias = tuple[float, float] | tuple[np.ndarray, np.ndarray] |
| 44 | + XsType1: TypeAlias = tuple[float | None, float | None, float | None, float | None] |
| 45 | + YsType1: TypeAlias = ( |
| 46 | + tuple[float | None, float | None, float | None, float | None] |
| 47 | + | tuple[ |
| 48 | + np.ndarray | None, np.ndarray | None, np.ndarray | None, np.ndarray | None |
| 49 | + ] |
| 50 | + ) |
| 51 | + XsTypeN: TypeAlias = tuple[float | None, ...] |
| 52 | + YsTypeN: TypeAlias = tuple[float | None, ...] | tuple[np.ndarray | None, ...] |
67 | 53 |
|
68 | 54 |
|
69 | 55 | __all__ = [ |
@@ -598,7 +584,7 @@ def tell(self, x: float, y: Float | Sequence[Float] | np.ndarray) -> None: |
598 | 584 | ) |
599 | 585 |
|
600 | 586 | # either it is a float/int, if not, try casting to a np.array |
601 | | - if not isinstance(y, (float, int)): |
| 587 | + if not isinstance(y, float | int): |
602 | 588 | y = np.asarray(y, dtype=float) |
603 | 589 |
|
604 | 590 | # Add point to the real data dict |
|
0 commit comments