Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ruff to 0.7.2 and target python to 3.9 #2589

Merged
merged 14 commits into from
Nov 11, 2024
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
- id: detect-private-key

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
rev: v0.7.2
hooks:
# try to fix what is possible
- id: ruff
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ but cannot always guarantee backwards compatibility. Changes that may **break co
- improved caching across `master` branch and its children
- fixed failing docker deployment
- removed `gradle` dependency in favor of native GitHub action plugins.
- Updated ruff to v0.7.2 and target-version to python39, also fixed various typos [#2589](https://github.com/unit8co/darts/pull/2589) by [Greg DeVosNouri](https://github.com/gdevos010) and [Antoine Madrona](https://github.com/madtoinou).

## [0.31.0](https://github.com/unit8co/darts/tree/0.31.0) (2024-10-13)

Expand Down Expand Up @@ -265,11 +266,11 @@ but cannot always guarantee backwards compatibility. Changes that may **break co
**Fixed**

- Fixed a bug when using `RegressionModel` with `lags=None`, some `lags_*covariates`, and the covariates starting after or at the same time as the first predictable time step; the lags were not extracted from the correct indices. [#2176](https://github.com/unit8co/darts/pull/2176) by [Dennis Bader](https://github.com/dennisbader).
- Fixed a bug when calling `window_transform` on a `TimeSeries` with a hierarchy. The hierarchy is now only preseved for single transformations applied to all components, or removed otherwise. [#2207](https://github.com/unit8co/darts/pull/2207) by [Antoine Madrona](https://github.com/madtoinou).
- Fixed a bug when calling `window_transform` on a `TimeSeries` with a hierarchy. The hierarchy is now only preserved for single transformations applied to all components, or removed otherwise. [#2207](https://github.com/unit8co/darts/pull/2207) by [Antoine Madrona](https://github.com/madtoinou).
- Fixed a bug in probabilistic `LinearRegressionModel.fit()`, where the `model` attribute was not pointing to all underlying estimators. [#2205](https://github.com/unit8co/darts/pull/2205) by [Antoine Madrona](https://github.com/madtoinou).
- Raise an error in `RegressionEsembleModel` when the `regression_model` was created with `multi_models=False` (not supported). [#2205](https://github.com/unit8co/darts/pull/2205) by [Antoine Madrona](https://github.com/madtoinou).
- Fixed a bug in `coefficient_of_variation()` with `intersect=True`, where the coefficient was not computed on the intersection. [#2202](https://github.com/unit8co/darts/pull/2202) by [Antoine Madrona](https://github.com/madtoinou).
- Fixed a bug in `gridsearch()` with `use_fitted_values=True`, where the model was not propely instantiated for sanity checks. [#2222](https://github.com/unit8co/darts/pull/2222) by [Antoine Madrona](https://github.com/madtoinou).
- Fixed a bug in `gridsearch()` with `use_fitted_values=True`, where the model was not properly instantiated for sanity checks. [#2222](https://github.com/unit8co/darts/pull/2222) by [Antoine Madrona](https://github.com/madtoinou).
- Fixed a bug in `TimeSeries.append/prepend_values()`, where the component names and the hierarchy were dropped. [#2237](https://github.com/unit8co/darts/pull/2237) by [Antoine Madrona](https://github.com/madtoinou).
- Fixed a bug in `get_multioutput_estimator()`, where the index of the estimator was incorrectly calculated. [#2246](https://github.com/unit8co/darts/pull/2246) by [Antoine Madrona](https://github.com/madtoinou).
- 🔴 Fixed a bug in `datetime_attribute_timeseries()`, where 1-indexed attributes were not properly handled. Also, 0-indexing is now enforced for all the generated encodings. [#2242](https://github.com/unit8co/darts/pull/2242) by [Antoine Madrona](https://github.com/madtoinou).
Expand Down
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
15 changes: 6 additions & 9 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 @@ -165,7 +162,7 @@ def fit_detect(
Returns
-------
Union[TimeSeries, Sequence[TimeSeries]]
Binary prediciton (1 if considered as an anomaly, 0 if not)
Binary prediction (1 if considered as an anomaly, 0 if not)
"""
self.fit(series)
return self.detect(series, name="series")
Expand All @@ -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
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -666,7 +667,7 @@ def _plot_series(series, ax_id, linewidth, label_name, **kwargs):
series
The series to plot.
ax_id
The axis the series will be ploted on.
The axis the series will be plotted on.
linewidth
Thickness of the line.
label_name
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
Loading