Skip to content

Commit

Permalink
feat: update target version from python38 to python39
Browse files Browse the repository at this point in the history
  • Loading branch information
madtoinou committed Nov 8, 2024
1 parent c56a0e1 commit 78612a1
Show file tree
Hide file tree
Showing 104 changed files with 767 additions and 770 deletions.
3 changes: 2 additions & 1 deletion darts/ad/aggregators/aggregators.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from typing_extensions import Literal

from abc import ABC, abstractmethod
from typing import Optional, Sequence, Union
from collections.abc import Sequence
from typing import Optional, Union

from darts import TimeSeries
from darts.ad.utils import (
Expand Down
2 changes: 1 addition & 1 deletion darts/ad/aggregators/and_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
--------------
"""

from typing import Sequence
from collections.abc import Sequence

from darts import TimeSeries
from darts.ad.aggregators.aggregators import Aggregator
Expand Down
2 changes: 1 addition & 1 deletion darts/ad/aggregators/ensemble_sklearn_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
--------------------------------
"""

from typing import Sequence
from collections.abc import Sequence

import numpy as np
from sklearn.ensemble import BaseEnsemble
Expand Down
2 changes: 1 addition & 1 deletion darts/ad/aggregators/or_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-------------
"""

from typing import Sequence
from collections.abc import Sequence

from darts import TimeSeries
from darts.ad.aggregators.aggregators import Aggregator
Expand Down
17 changes: 7 additions & 10 deletions darts/ad/anomaly_model/anomaly_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@

import sys
from abc import ABC, abstractmethod
from typing import Dict, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Literal, Optional, Union

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self
try:
from typing import Literal
except ImportError:
from typing_extensions import Literal

from darts.ad.scorers.scorers import AnomalyScorer
from darts.ad.utils import (
Expand Down Expand Up @@ -130,10 +127,10 @@ def eval_metric(
metric: Literal["AUC_ROC", "AUC_PR"] = "AUC_ROC",
**kwargs,
) -> Union[
Dict[str, float],
Dict[str, Sequence[float]],
Sequence[Dict[str, float]],
Sequence[Dict[str, Sequence[float]]],
dict[str, float],
dict[str, Sequence[float]],
Sequence[dict[str, float]],
Sequence[dict[str, Sequence[float]]],
]:
"""Compute the accuracy of the anomaly scores computed by the model.
Expand Down Expand Up @@ -246,7 +243,7 @@ def show_anomalies(
self,
series: TimeSeries,
anomalies: TimeSeries = None,
predict_kwargs: Optional[Dict] = None,
predict_kwargs: Optional[dict] = None,
names_of_scorers: Union[str, Sequence[str]] = None,
title: str = None,
metric: Optional[Literal["AUC_ROC", "AUC_PR"]] = None,
Expand Down
15 changes: 6 additions & 9 deletions darts/ad/anomaly_model/filtering_am.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
"""

import sys
from typing import Dict, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Literal, Optional, Union

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self
try:
from typing import Literal
except ImportError:
from typing_extensions import Literal

from darts.ad.anomaly_model.anomaly_model import AnomalyModel
from darts.ad.scorers.scorers import AnomalyScorer
Expand Down Expand Up @@ -158,10 +155,10 @@ def eval_metric(
metric: Literal["AUC_ROC", "AUC_PR"] = "AUC_ROC",
**filter_kwargs,
) -> Union[
Dict[str, float],
Dict[str, Sequence[float]],
Sequence[Dict[str, float]],
Sequence[Dict[str, Sequence[float]]],
dict[str, float],
dict[str, Sequence[float]],
Sequence[dict[str, float]],
Sequence[dict[str, Sequence[float]]],
]:
"""Compute a metric for the anomaly scores computed by the model.
Expand Down
15 changes: 6 additions & 9 deletions darts/ad/anomaly_model/forecasting_am.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
# TODO:
# - put start default value to its minimal value (wait for the release of historical_forecast)
import sys
from typing import Dict, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Literal, Optional, Union

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self
try:
from typing import Literal
except ImportError:
from typing_extensions import Literal

import pandas as pd

Expand Down Expand Up @@ -346,10 +343,10 @@ def eval_metric(
enable_optimization: bool = True,
metric: Literal["AUC_ROC", "AUC_PR"] = "AUC_ROC",
) -> Union[
Dict[str, float],
Dict[str, Sequence[float]],
Sequence[Dict[str, float]],
Sequence[Dict[str, Sequence[float]]],
dict[str, float],
dict[str, Sequence[float]],
Sequence[dict[str, float]],
Sequence[dict[str, Sequence[float]]],
]:
"""Compute the accuracy of the anomaly scores computed by the model.
Expand Down
13 changes: 5 additions & 8 deletions darts/ad/detectors/detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@

import sys
from abc import ABC, abstractmethod
from typing import Any, List, Optional, Sequence, Tuple, Union
from collections.abc import Sequence
from typing import Any, Literal, Optional, Union

try:
from typing import Literal
except ImportError:
from typing_extensions import Literal
if sys.version_info >= (3, 11):
from typing import Self
else:
Expand Down Expand Up @@ -187,7 +184,7 @@ def _prepare_boundaries(
upper_bound_name: str,
lower_bound: Optional[Union[Sequence[float], float]] = None,
upper_bound: Optional[Union[Sequence[float], float]] = None,
) -> Tuple[List[Optional[float]], List[Optional[float]]]:
) -> tuple[list[Optional[float]], list[Optional[float]]]:
"""
Process the boundaries argument and perform some sanity checks
Expand Down Expand Up @@ -221,7 +218,7 @@ def _prepare_boundaries(
logger=logger,
)

def _prep_boundaries(boundaries) -> List[Optional[float]]:
def _prep_boundaries(boundaries) -> list[Optional[float]]:
"""Convert boundaries to List"""
return (
boundaries.tolist()
Expand Down Expand Up @@ -275,7 +272,7 @@ def _prep_boundaries(boundaries) -> List[Optional[float]]:
return lower_bound, upper_bound

@staticmethod
def _expand_threshold(series: TimeSeries, threshold: List[float]) -> List[float]:
def _expand_threshold(series: TimeSeries, threshold: list[float]) -> list[float]:
return threshold * series[0].width if len(threshold) == 1 else threshold

@property
Expand Down
3 changes: 2 additions & 1 deletion darts/ad/detectors/iqr_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
computed as distances from the IQR of historical data when the detector is fitted.
"""

from typing import Sequence, Union
from collections.abc import Sequence
from typing import Union

import numpy as np

Expand Down
3 changes: 2 additions & 1 deletion darts/ad/detectors/quantile_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
computed as quantiles of historical data when the detector is fitted.
"""

from typing import Optional, Sequence, Union
from collections.abc import Sequence
from typing import Optional, Union

import numpy as np

Expand Down
3 changes: 2 additions & 1 deletion darts/ad/detectors/threshold_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
identifies time points as anomalous when values are beyond the thresholds.
"""

from typing import Sequence, Union
from collections.abc import Sequence
from typing import Union

import numpy as np

Expand Down
3 changes: 2 additions & 1 deletion darts/ad/scorers/scorers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import copy
import sys
from abc import ABC, abstractmethod
from typing import Optional, Sequence, Union
from collections.abc import Sequence
from typing import Optional, Union

if sys.version_info >= (3, 11):
from typing import Self
Expand Down
2 changes: 1 addition & 1 deletion darts/ad/scorers/wasserstein_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
.. [1] https://en.wikipedia.org/wiki/Wasserstein_metric
"""

from typing import Sequence
from collections.abc import Sequence

import numpy as np
from scipy.stats import wasserstein_distance
Expand Down
3 changes: 2 additions & 1 deletion darts/ad/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# - add an option to visualize: "by window", "unique", "together"
# - create a normalize option in plot function (norm every anomaly score btw 1 and 0) -> to be seen on the same plot

from typing import Callable, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Callable, Optional, Union

try:
from typing import Literal
Expand Down
4 changes: 2 additions & 2 deletions darts/dataprocessing/dtw/_plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Tuple, Union
from typing import Union

import numpy as np
import xarray as xr
Expand Down Expand Up @@ -102,7 +102,7 @@ def plot_alignment(
new_plot: bool = False,
series1_y_offset: float = 0,
series2_y_offset: float = 0,
components: Union[Tuple[Union[str, int], Union[str, int]]] = (0, 0),
components: Union[tuple[Union[str, int], Union[str, int]]] = (0, 0),
args_line: dict = {},
args_series1: dict = {},
args_series2: dict = {},
Expand Down
3 changes: 1 addition & 2 deletions darts/dataprocessing/dtw/cost_matrix.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import array
from abc import ABC, abstractmethod
from itertools import repeat
from typing import Tuple

import numpy as np

from darts.dataprocessing.dtw.window import CRWindow, Window

Elem = Tuple[int, int]
Elem = tuple[int, int]


class CostMatrix(ABC):
Expand Down
11 changes: 5 additions & 6 deletions darts/dataprocessing/dtw/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import array
from abc import ABC, abstractmethod
from math import atan, tan
from typing import Tuple

import numpy as np

Expand Down Expand Up @@ -36,7 +35,7 @@ def __len__(self) -> int:
pass

@abstractmethod
def column_index(self, elem: Tuple[int, int]) -> int:
def column_index(self, elem: tuple[int, int]) -> int:
"""Gives the number of active grid cells before row element j, in column i.
Parameters
Expand Down Expand Up @@ -101,7 +100,7 @@ class NoWindow(Window):
def __len__(self):
return self.n * self.m + 1 # include (0,0) element

def column_index(self, elem: Tuple[int, int]):
def column_index(self, elem: tuple[int, int]):
return elem[1] - 1

def column_length(self, column: int) -> int:
Expand Down Expand Up @@ -215,7 +214,7 @@ def add_range(self, column: int, start: int, end: int):
self.column_ranges[start_idx] = start
self.column_ranges[end_idx] = end

def add(self, elem: Tuple[int, int]):
def add(self, elem: tuple[int, int]):
"""Marks a grid cell as active.
Parameters
Expand All @@ -230,7 +229,7 @@ def column_length(self, column: int) -> int:
start, end = self.column_ranges[column]
return gtz(end - start)

def column_index(self, elem: Tuple[int, int]) -> int:
def column_index(self, elem: tuple[int, int]) -> int:
i, j = elem

start, end = self.column_ranges[i]
Expand All @@ -239,7 +238,7 @@ def column_index(self, elem: Tuple[int, int]) -> int:
else:
return j - start

def __contains__(self, elem: Tuple[int, int]) -> bool:
def __contains__(self, elem: tuple[int, int]) -> bool:
i, j = elem
start, end = self.column_ranges[i]
return start <= j < end
Expand Down
Loading

0 comments on commit 78612a1

Please sign in to comment.