Skip to content

Commit

Permalink
pre-commit: pyupgrade (#1352)
Browse files Browse the repository at this point in the history
Stop using deprecated type annotations and imports. Include ruff pyupgrade rules in pre-commit.
  • Loading branch information
dweindl authored Apr 5, 2024
1 parent 5879755 commit 321ee9d
Show file tree
Hide file tree
Showing 91 changed files with 439 additions and 412 deletions.
1 change: 0 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# pyPESTO documentation build configuration file, created by
# sphinx-quickstart on Mon Jul 30 08:30:38 2018.
Expand Down
6 changes: 3 additions & 3 deletions pypesto/C.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

from enum import Enum
from typing import Literal, Tuple, Union
from typing import Literal, Union

###############################################################################
# ENSEMBLE
Expand Down Expand Up @@ -307,8 +307,8 @@ class InnerParameterType(str, Enum):

LEN_RGB = 3 # number of elements in an RGB color
LEN_RGBA = 4 # number of elements in an RGBA color
RGB = Tuple[(float,) * LEN_RGB] # typing of an RGB color
RGBA = Tuple[(float,) * LEN_RGBA] # typing of an RGBA color
RGB = tuple[(float,) * LEN_RGB] # typing of an RGB color
RGBA = tuple[(float,) * LEN_RGBA] # typing of an RGBA color
RGB_RGBA = Union[RGB, RGBA] # typing of an RGB or RGBA color
RGBA_MIN = 0 # min value for an RGBA element
RGBA_MAX = 1 # max value for an RGBA element
Expand Down
8 changes: 4 additions & 4 deletions pypesto/ensemble/covariance_analysis.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

Expand Down Expand Up @@ -60,7 +60,7 @@ def get_spectral_decomposition_parameters(
only_identifiable_directions: bool = False,
cutoff_absolute_identifiable: float = 1e-16,
cutoff_relative_identifiable: float = 1e-16,
) -> Tuple[np.ndarray, np.ndarray]:
) -> tuple[np.ndarray, np.ndarray]:
"""
Compute the spectral decomposition of ensemble parameters.
Expand Down Expand Up @@ -128,7 +128,7 @@ def get_spectral_decomposition_predictions(
only_identifiable_directions: bool = False,
cutoff_absolute_identifiable: float = 1e-16,
cutoff_relative_identifiable: float = 1e-16,
) -> Tuple[np.ndarray, np.ndarray]:
) -> tuple[np.ndarray, np.ndarray]:
"""
Compute the spectral decomposition of ensemble predictions.
Expand Down Expand Up @@ -191,7 +191,7 @@ def get_spectral_decomposition_lowlevel(
only_identifiable_directions: bool = False,
cutoff_absolute_identifiable: float = 1e-16,
cutoff_relative_identifiable: float = 1e-16,
) -> Tuple[np.ndarray, np.ndarray]:
) -> tuple[np.ndarray, np.ndarray]:
"""
Compute the spectral decomposition of ensemble parameters or predictions.
Expand Down
14 changes: 7 additions & 7 deletions pypesto/ensemble/dimension_reduction.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Tuple, Union
from typing import Callable, Union

import numpy as np

Expand All @@ -11,7 +11,7 @@ def get_umap_representation_parameters(
n_components: int = 2,
normalize_data: bool = False,
**kwargs,
) -> Tuple:
) -> tuple:
"""
UMAP of parameter ensemble.
Expand Down Expand Up @@ -51,7 +51,7 @@ def get_umap_representation_predictions(
n_components: int = 2,
normalize_data: bool = False,
**kwargs,
) -> Tuple:
) -> tuple:
"""
UMAP of ensemble prediction.
Expand Down Expand Up @@ -97,7 +97,7 @@ def get_pca_representation_parameters(
n_components: int = 2,
rescale_data: bool = True,
rescaler: Union[Callable, None] = None,
) -> Tuple:
) -> tuple:
"""
PCA of parameter ensemble.
Expand Down Expand Up @@ -139,7 +139,7 @@ def get_pca_representation_predictions(
n_components: int = 2,
rescale_data: bool = True,
rescaler: Union[Callable, None] = None,
) -> Tuple:
) -> tuple:
"""
PCA of ensemble prediction.
Expand Down Expand Up @@ -188,7 +188,7 @@ def _get_umap_representation_lowlevel(
n_components: int = 2,
normalize_data: bool = False,
**kwargs,
) -> Tuple:
) -> tuple:
"""
Low level UMAP of parameter ensemble.
Expand Down Expand Up @@ -239,7 +239,7 @@ def _get_pca_representation_lowlevel(
n_components: int = 2,
rescale_data: bool = True,
rescaler: Union[Callable, None] = None,
) -> Tuple:
) -> tuple:
"""
Low level PCA of parameter ensemble.
Expand Down
13 changes: 7 additions & 6 deletions pypesto/ensemble/ensemble.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import logging
from collections.abc import Sequence
from functools import partial
from typing import TYPE_CHECKING, Any, Callable, Optional, Sequence, Union
from typing import TYPE_CHECKING, Any, Callable

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -67,7 +68,7 @@ class EnsemblePrediction:

def __init__(
self,
predictor: Optional[Callable[[Sequence], PredictionResult]] = None,
predictor: Callable[[Sequence], PredictionResult] | None = None,
prediction_id: str = None,
prediction_results: Sequence[PredictionResult] = None,
lower_bound: Sequence[np.ndarray] = None,
Expand Down Expand Up @@ -272,7 +273,7 @@ def _stack_outputs_sensi(ic: int) -> np.array:
# stack into one numpy array
return np.stack(output_sensi_list, axis=-1)

def _stack_weights(ic: int) -> Union[np.ndarray, None]:
def _stack_weights(ic: int) -> np.ndarray | None:
"""
Stack weights.
Expand Down Expand Up @@ -845,7 +846,7 @@ def _map_parameters_by_objective(
self,
predictor: Callable,
default_value: float = None,
) -> list[Union[int, float]]:
) -> list[int | float]:
"""
Create mapping for parameters from ensemble to predictor.
Expand Down Expand Up @@ -1079,7 +1080,7 @@ def check_identifiability(self) -> pd.DataFrame:


def entries_per_start(
fval_traces: list["np.ndarray"],
fval_traces: list[np.ndarray],
cutoff: float,
max_size: int,
max_per_start: int,
Expand Down Expand Up @@ -1168,7 +1169,7 @@ def get_vector_indices(
return sorted(candidates, key=lambda i: trace_start[i])[:n_vectors]


def get_percentile_label(percentile: Union[float, int, str]) -> str:
def get_percentile_label(percentile: float | int | str) -> str:
"""Convert a percentile to a label.
Labels for percentiles are used at different locations (e.g. ensemble
Expand Down
4 changes: 2 additions & 2 deletions pypesto/ensemble/task.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, Callable, List
from typing import Any, Callable

import numpy as np

Expand Down Expand Up @@ -32,7 +32,7 @@ def __init__(
self.vectors = vectors
self.id = id

def execute(self) -> List[Any]:
def execute(self) -> list[Any]:
"""Execute the task."""
logger.debug(f"Executing task {self.id}.")
results = []
Expand Down
3 changes: 2 additions & 1 deletion pypesto/ensemble/util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Ensemble utilities."""

import os
from collections.abc import Sequence
from pathlib import Path
from typing import Callable, Literal, Sequence, Union
from typing import Callable, Literal, Union

import h5py
import numpy as np
Expand Down
13 changes: 7 additions & 6 deletions pypesto/hierarchical/inner_calculator_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from __future__ import annotations

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

import numpy as np

Expand Down Expand Up @@ -89,9 +90,9 @@ class InnerCalculatorCollector(AmiciCalculator):
def __init__(
self,
data_types: set[str],
petab_problem: "petab.Problem",
petab_problem: petab.Problem,
model: AmiciModel,
edatas: list["amici.ExpData"],
edatas: list[amici.ExpData],
inner_options: dict,
):
super().__init__()
Expand All @@ -117,9 +118,9 @@ def initialize(self):

def construct_inner_calculators(
self,
petab_problem: "petab.Problem",
petab_problem: petab.Problem,
model: AmiciModel,
edatas: list["amici.ExpData"],
edatas: list[amici.ExpData],
inner_options: dict,
):
"""Construct inner calculators for each data type."""
Expand Down Expand Up @@ -217,7 +218,7 @@ def validate_options(self, inner_options: dict):

def _get_quantitative_data_mask(
self,
edatas: list["amici.ExpData"],
edatas: list[amici.ExpData],
) -> list[np.ndarray]:
# transform experimental data
edatas = [
Expand Down
2 changes: 1 addition & 1 deletion pypesto/hierarchical/ordinal/calculator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Definition of an optimal scaling calculator class."""

import copy
from typing import Sequence
from collections.abc import Sequence

import numpy as np

Expand Down
8 changes: 4 additions & 4 deletions pypesto/hierarchical/relative/calculator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

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

import numpy as np

Expand Down Expand Up @@ -46,7 +46,7 @@ class RelativeAmiciCalculator(AmiciCalculator):
def __init__(
self,
inner_problem: AmiciInnerProblem,
inner_solver: Optional[InnerSolver] = None,
inner_solver: InnerSolver | None = None,
):
"""Initialize the calculator from the given problem.
Expand Down Expand Up @@ -83,7 +83,7 @@ def __call__(
x_ids: Sequence[str],
parameter_mapping: ParameterMapping,
fim_for_hess: bool,
rdatas: list["amici.ReturnData"] = None,
rdatas: list[amici.ReturnData] = None,
):
"""Perform the actual AMICI call, with hierarchical optimization.
Expand Down Expand Up @@ -269,7 +269,7 @@ def calculate_directly(
x_ids: Sequence[str],
parameter_mapping: ParameterMapping,
fim_for_hess: bool,
rdatas: list["amici.ReturnData"] = None,
rdatas: list[amici.ReturnData] = None,
):
"""Calculate directly via solver calculate methods.
Expand Down
2 changes: 1 addition & 1 deletion pypesto/hierarchical/semiquantitative/calculator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import copy
from typing import Sequence
from collections.abc import Sequence

import numpy as np

Expand Down
3 changes: 2 additions & 1 deletion pypesto/history/amici.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Sequence
from pathlib import Path
from typing import Sequence, Union
from typing import Union

import numpy as np

Expand Down
3 changes: 2 additions & 1 deletion pypesto/history/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import numbers
import time
from abc import ABC, abstractmethod
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 pypesto/history/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import copy
import os
import time
from typing import Sequence, Union
from collections.abc import Sequence
from typing import Union

import numpy as np
import pandas as pd
Expand Down
2 changes: 1 addition & 1 deletion pypesto/history/generate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Generate a history from options and inputs."""

from collections.abc import Sequence
from pathlib import Path
from typing import Sequence

from ..C import SUFFIXES_CSV, SUFFIXES_HDF5
from .base import CountHistory, HistoryBase
Expand Down
3 changes: 2 additions & 1 deletion pypesto/history/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import contextlib
import time
from collections.abc import Sequence
from functools import wraps
from pathlib import Path
from typing import Sequence, Union
from typing import Union

import h5py
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion pypesto/history/memory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""In-memory history."""

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

import numpy as np

Expand Down
3 changes: 2 additions & 1 deletion pypesto/history/util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""History utility functions."""

import numbers
from collections.abc import Sequence
from functools import wraps
from typing import Sequence, Union
from typing import Union

import numpy as np

Expand Down
Loading

0 comments on commit 321ee9d

Please sign in to comment.