Skip to content

Commit 9f90f42

Browse files
Change Dict and List typing to dict and list built-in types
1 parent 8c2574b commit 9f90f42

File tree

46 files changed

+205
-207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+205
-207
lines changed

frouros/callbacks/batch/permutation_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Permutation test batch callback module."""
22

33
import multiprocessing
4-
from typing import Any, Callable, Dict, List, Optional, Tuple
4+
from typing import Any, Callable, Optional, Tuple
55

66
import numpy as np # type: ignore
77

@@ -154,14 +154,14 @@ def _calculate_p_value( # pylint: disable=too-many-arguments
154154
X_ref: np.ndarray, # noqa: N803
155155
X_test: np.ndarray,
156156
statistic: Callable,
157-
statistic_args: Dict[str, Any],
157+
statistic_args: dict[str, Any],
158158
observed_statistic: float,
159159
num_permutations: int,
160160
num_jobs: int,
161161
conservative: bool,
162162
random_state: Optional[int],
163163
verbose: bool,
164-
) -> Tuple[List[float], float]:
164+
) -> Tuple[list[float], float]:
165165
permuted_statistic = permutation(
166166
X=X_ref,
167167
Y=X_test,

frouros/callbacks/streaming/history.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""History callback module."""
22

3-
from typing import Any, Dict, List, Optional, Union
3+
from typing import Any, Optional, Union
44

55
from frouros.callbacks.streaming.base import BaseCallbackStreaming
66
from frouros.utils.stats import BaseStat
@@ -46,18 +46,18 @@ def __init__( # noqa: D107
4646
name: Optional[str] = None,
4747
) -> None:
4848
super().__init__(name=name)
49-
self.additional_vars: List[str] = []
50-
self.history: Dict[str, List[Any]] = {
49+
self.additional_vars: list[str] = []
50+
self.history: dict[str, list[Any]] = {
5151
"value": [],
5252
"num_instances": [],
5353
"drift": [],
5454
}
5555

56-
def add_additional_vars(self, vars_: List[str]) -> None:
56+
def add_additional_vars(self, vars_: list[str]) -> None:
5757
"""Add additional variables to track.
5858
5959
:param vars_: list of variables
60-
:type vars_: List[str]
60+
:type vars_: list[str]
6161
"""
6262
self.additional_vars.extend(vars_)
6363
self.history = {**self.history, **{var: [] for var in self.additional_vars}}

frouros/datasets/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import tempfile
55
import urllib.parse
66
from pathlib import Path
7-
from typing import Any, List, Optional, Union
7+
from typing import Any, Optional, Union
88

99
import numpy as np # type: ignore
1010
import requests
@@ -22,13 +22,13 @@ class BaseDatasetDownload(abc.ABC):
2222

2323
def __init__(
2424
self,
25-
url: Union[str, List[str]],
25+
url: Union[str, list[str]],
2626
file_path: Optional[str] = None,
2727
) -> None:
2828
"""Init method.
2929
3030
:param url: url or url mirrors from where dataset will be downloaded
31-
:type url: Union[str, List[str]]
31+
:type url: Union[str, list[str]]
3232
:param file_path: file path for the downloaded file
3333
:type file_path: str
3434
"""
@@ -58,20 +58,20 @@ def file_path(self, value: Optional[Path]) -> None:
5858
self._file_path = value
5959

6060
@property
61-
def url(self) -> Union[str, List[str]]:
61+
def url(self) -> Union[str, list[str]]:
6262
"""URL property.
6363
6464
:return: URL from where dataset will be downloaded
65-
:rtype: Union[str, List[str]]
65+
:rtype: Union[str, list[str]]
6666
"""
6767
return self._url
6868

6969
@url.setter
70-
def url(self, value: Union[str, List[str]]) -> None:
70+
def url(self, value: Union[str, list[str]]) -> None:
7171
"""URL setter.
7272
7373
:param value: value to be set
74-
:type value: Union[str, List[str]]
74+
:type value: Union[str, list[str]]
7575
:raises InvalidURLError: Invalid URL exception
7676
"""
7777
urls = [value] if isinstance(value, str) else value

frouros/detectors/base.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Base detector module."""
22

33
import abc
4-
from typing import Any, Dict, List, Optional, Union
4+
from typing import Any, Optional, Union
55

66
import numpy as np # type: ignore
77

@@ -13,33 +13,33 @@ class BaseDetector(abc.ABC):
1313

1414
def __init__(
1515
self,
16-
callbacks: Optional[Union[BaseCallback, List[BaseCallback]]] = None,
16+
callbacks: Optional[Union[BaseCallback, list[BaseCallback]]] = None,
1717
) -> None:
1818
"""Init method.
1919
2020
:param callbacks: callbacks
21-
:type callbacks: Optional[Union[BaseCallback, List[Callback]]]
21+
:type callbacks: Optional[Union[BaseCallback, list[Callback]]]
2222
"""
2323
self.callbacks = callbacks # type: ignore
2424

2525
@property
26-
def callbacks(self) -> Optional[List[BaseCallback]]:
26+
def callbacks(self) -> Optional[list[BaseCallback]]:
2727
"""Callbacks property.
2828
2929
:return: callbacks
30-
:rtype: Optional[List[BaseCallback]]
30+
:rtype: Optional[list[BaseCallback]]
3131
"""
3232
return self._callbacks # type: ignore
3333

3434
@callbacks.setter
3535
def callbacks(
3636
self,
37-
value: Optional[Union[BaseCallback, List[BaseCallback]]],
37+
value: Optional[Union[BaseCallback, list[BaseCallback]]],
3838
) -> None:
3939
"""Callbacks setter.
4040
4141
:param value: value to be set
42-
:type value: Optional[Union[BaseCallback, List[Callback]]]
42+
:type value: Optional[Union[BaseCallback, list[Callback]]]
4343
:raises TypeError: Type error exception
4444
"""
4545
if value is not None:
@@ -58,7 +58,7 @@ def callbacks(
5858
def reset(self) -> None:
5959
"""Reset method."""
6060

61-
def _get_callbacks_logs(self) -> Dict[str, Any]:
61+
def _get_callbacks_logs(self) -> dict[str, Any]:
6262
logs = {
6363
callback.name: callback.logs for callback in self.callbacks # type: ignore
6464
}

frouros/detectors/concept_drift/base.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Base concept drift module."""
22

33
import abc
4-
from typing import Any, Dict, List, Optional, Union
4+
from typing import Any, Optional, Union
55

66
from frouros.callbacks import HistoryConceptDrift
77
from frouros.callbacks.streaming.base import BaseCallbackStreaming
@@ -66,7 +66,7 @@ def __init__(
6666
self,
6767
config: Optional[BaseConceptDriftConfig] = None,
6868
callbacks: Optional[
69-
Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]
69+
Union[BaseCallbackStreaming, list[BaseCallbackStreaming]]
7070
] = None,
7171
) -> None:
7272
"""Init method.
@@ -75,7 +75,7 @@ def __init__(
7575
:type config: Optional[BaseConceptDriftConfig]
7676
:param callbacks: callbacks
7777
:type callbacks: Optional[Union[BaseCallbackStreaming,
78-
List[BaseCallbackStreaming]]]
78+
list[BaseCallbackStreaming]]]
7979
"""
8080
check_callbacks(
8181
callbacks=callbacks,
@@ -99,20 +99,20 @@ def _set_additional_vars_callback(self) -> None:
9999
)
100100

101101
@property
102-
def additional_vars(self) -> Optional[Dict[str, Any]]:
102+
def additional_vars(self) -> Optional[dict[str, Any]]:
103103
"""Additional variables property.
104104
105105
:return: additional variables
106-
:rtype: Optional[Dict[str, Any]]
106+
:rtype: Optional[dict[str, Any]]
107107
"""
108108
return self._additional_vars
109109

110110
@additional_vars.setter
111-
def additional_vars(self, value: Optional[Dict[str, Any]]) -> None:
111+
def additional_vars(self, value: Optional[dict[str, Any]]) -> None:
112112
"""Additional variables setter.
113113
114114
:param value: value to be set
115-
:type value: Optional[Dict[str, Any]]
115+
:type value: Optional[dict[str, Any]]
116116
"""
117117
self._additional_vars = value if value is not None else {}
118118

@@ -171,21 +171,21 @@ def reset(self) -> None:
171171
callback.reset()
172172

173173
@property
174-
def status(self) -> Dict[str, bool]:
174+
def status(self) -> dict[str, bool]:
175175
"""Status property.
176176
177177
:return: status dict
178-
:rtype: Dict[str, bool]
178+
:rtype: dict[str, bool]
179179
"""
180180
return {"drift": self.drift}
181181

182-
def update(self, value: Union[int, float], **kwargs) -> Dict[str, Any]:
182+
def update(self, value: Union[int, float], **kwargs) -> dict[str, Any]:
183183
"""Update method.
184184
185185
:param value: value to update detector
186186
:type value: Union[int, float]
187187
:return: callbacks logs
188-
:rtype: Dict[str, Any]]
188+
:rtype: dict[str, Any]]
189189
"""
190190
for callback in self.callbacks: # type: ignore
191191
callback.on_update_start( # type: ignore
@@ -200,7 +200,7 @@ def update(self, value: Union[int, float], **kwargs) -> Dict[str, Any]:
200200
callbacks_logs = self._get_callbacks_logs()
201201
return callbacks_logs
202202

203-
def _get_callbacks_logs(self) -> Dict[str, Any]:
203+
def _get_callbacks_logs(self) -> dict[str, Any]:
204204
logs = {
205205
callback.name: callback.logs for callback in self.callbacks # type: ignore
206206
}

frouros/detectors/concept_drift/streaming/change_detection/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Base concept drift ChangeDetection based module."""
22

33
import abc
4-
from typing import List, Optional, Union
4+
from typing import Optional, Union
55

66
from frouros.callbacks.streaming.base import BaseCallbackStreaming
77
from frouros.detectors.concept_drift.streaming.base import (
@@ -142,7 +142,7 @@ class BaseCUSUM(BaseChangeDetection):
142142
:param config: configuration parameters, defaults to None
143143
:type config: Optional[BaseCUSUMConfig]
144144
:param callbacks: callbacks, defaults to None
145-
:type callbacks: Optional[Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]]
145+
:type callbacks: Optional[Union[BaseCallbackStreaming, list[BaseCallbackStreaming]]]
146146
""" # noqa: E501
147147

148148
config_type = BaseCUSUMConfig
@@ -151,7 +151,7 @@ def __init__( # noqa: D107
151151
self,
152152
config: Optional[BaseCUSUMConfig] = None,
153153
callbacks: Optional[
154-
Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]
154+
Union[BaseCallbackStreaming, list[BaseCallbackStreaming]]
155155
] = None,
156156
) -> None:
157157
super().__init__(

frouros/detectors/concept_drift/streaming/change_detection/bocd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import abc
44
import copy
5-
from typing import List, Union, Optional
5+
from typing import Union, Optional
66

77
import numpy as np # type: ignore
88
from scipy.special import logsumexp # type: ignore
@@ -185,7 +185,7 @@ class BOCD(BaseChangeDetection):
185185
:param config: configuration object of the detector, defaults to None. If None, the default configuration of :class:`BOCDConfig` is used.
186186
:type config: Optional[BOCDConfig]
187187
:param callbacks: callbacks, defaults to None
188-
:type callbacks: Optional[Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]]
188+
:type callbacks: Optional[Union[BaseCallbackStreaming, list[BaseCallbackStreaming]]]
189189
190190
:Note:
191191
Adapted from the implementation in https://github.com/gwgundersen/bocd.
@@ -219,7 +219,7 @@ def __init__( # noqa: D107
219219
self,
220220
config: Optional[BOCDConfig] = None,
221221
callbacks: Optional[
222-
Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]
222+
Union[BaseCallbackStreaming, list[BaseCallbackStreaming]]
223223
] = None,
224224
) -> None:
225225
super().__init__(

frouros/detectors/concept_drift/streaming/change_detection/cusum.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""CUSUM module."""
22

3-
from typing import Optional, Union, List
3+
from typing import Optional, Union
44

55
import numpy as np # type: ignore
66

@@ -47,7 +47,7 @@ class CUSUM(BaseCUSUM):
4747
:param config: configuration object of the detector, defaults to None. If None, the default configuration of :class:`CUSUMConfig` is used.
4848
:type config: Optional[CUSUMConfig]
4949
:param callbacks: callbacks, defaults to None
50-
:type callbacks: Optional[Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]]
50+
:type callbacks: Optional[Union[BaseCallbackStreaming, list[BaseCallbackStreaming]]]
5151
5252
:References:
5353
@@ -78,7 +78,7 @@ def __init__( # noqa: D107
7878
self,
7979
config: Optional[CUSUMConfig] = None,
8080
callbacks: Optional[
81-
Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]
81+
Union[BaseCallbackStreaming, list[BaseCallbackStreaming]]
8282
] = None,
8383
) -> None:
8484
super().__init__(

frouros/detectors/concept_drift/streaming/change_detection/geometric_moving_average.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Geometric Moving Average module."""
22

3-
from typing import Optional, List, Union
3+
from typing import Optional, Union
44

55
from frouros.callbacks.streaming.base import BaseCallbackStreaming
66
from frouros.detectors.concept_drift.streaming.change_detection.base import (
@@ -46,7 +46,7 @@ class GeometricMovingAverage(BaseCUSUM):
4646
:param config: configuration object of the detector, defaults to None. If None, the default configuration of :class:`GeometricMovingAverageConfig` is used.
4747
:type config: Optional[GeometricMovingAverageConfig]
4848
:param callbacks: callbacks, defaults to None
49-
:type callbacks: Optional[Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]]
49+
:type callbacks: Optional[Union[BaseCallbackStreaming, list[BaseCallbackStreaming]]]
5050
5151
:References:
5252
@@ -78,7 +78,7 @@ def __init__( # noqa: D107
7878
self,
7979
config: Optional[GeometricMovingAverageConfig] = None,
8080
callbacks: Optional[
81-
Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]
81+
Union[BaseCallbackStreaming, list[BaseCallbackStreaming]]
8282
] = None,
8383
) -> None:
8484
super().__init__(

frouros/detectors/concept_drift/streaming/change_detection/page_hinkley.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Page Hinkley module."""
22

3-
from typing import Optional, Union, List
3+
from typing import Optional, Union
44

55
from frouros.callbacks.streaming.base import BaseCallbackStreaming
66
from frouros.detectors.concept_drift.streaming.change_detection.base import (
@@ -50,7 +50,7 @@ class PageHinkley(BaseCUSUM):
5050
:param config: configuration object of the detector, defaults to None. If None, the default configuration of :class:`PageHinkleyConfig` is used.
5151
:type config: Optional[PageHinkleyConfig]
5252
:param callbacks: callbacks, defaults to None
53-
:type callbacks: Optional[Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]]
53+
:type callbacks: Optional[Union[BaseCallbackStreaming, list[BaseCallbackStreaming]]]
5454
5555
:References:
5656
@@ -81,7 +81,7 @@ def __init__( # noqa: D107
8181
self,
8282
config: Optional[PageHinkleyConfig] = None,
8383
callbacks: Optional[
84-
Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]
84+
Union[BaseCallbackStreaming, list[BaseCallbackStreaming]]
8585
] = None,
8686
) -> None:
8787
super().__init__(

0 commit comments

Comments
 (0)