From 69f8ad1fb6de5b80ee2782c151491e36816e44a1 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Wed, 21 Jun 2023 11:12:57 +0200 Subject: [PATCH] fix: RUF012 fixes across codebase --- junifer/markers/ets_rss.py | 4 +-- junifer/markers/falff/falff_base.py | 6 +++-- ...ossparcellation_functional_connectivity.py | 4 +-- .../functional_connectivity_base.py | 4 +-- junifer/markers/parcel_aggregation.py | 4 +-- junifer/markers/reho/reho_base.py | 6 +++-- junifer/markers/sphere_aggregation.py | 4 +-- .../markers/temporal_snr/temporal_snr_base.py | 4 +-- .../tests/test_pipeline_step_mixin.py | 26 +++++++++++-------- .../confounds/fmriprep_confound_remover.py | 14 ++++++++-- 10 files changed, 47 insertions(+), 29 deletions(-) diff --git a/junifer/markers/ets_rss.py b/junifer/markers/ets_rss.py index 971d017a3b..c573a057b5 100644 --- a/junifer/markers/ets_rss.py +++ b/junifer/markers/ets_rss.py @@ -6,7 +6,7 @@ # Synchon Mandal # License: AGPL -from typing import Any, Dict, List, Optional, Union +from typing import Any, ClassVar, Dict, List, Optional, Set, Union import numpy as np @@ -42,7 +42,7 @@ class RSSETSMarker(BaseMarker): """ - _DEPENDENCIES = {"nilearn"} + _DEPENDENCIES: ClassVar[Set[str]] = {"nilearn"} def __init__( self, diff --git a/junifer/markers/falff/falff_base.py b/junifer/markers/falff/falff_base.py index 3fa9c9c4c3..d50a1682fc 100644 --- a/junifer/markers/falff/falff_base.py +++ b/junifer/markers/falff/falff_base.py @@ -6,7 +6,7 @@ # License: AGPL from abc import abstractmethod -from typing import Dict, List, Optional +from typing import ClassVar, Dict, List, Optional, Union from ...utils.logging import raise_error from ..base import BaseMarker @@ -44,7 +44,9 @@ class ALFFBase(BaseMarker): """ - _EXT_DEPENDENCIES = [ + _EXT_DEPENDENCIES: ClassVar[ + List[Dict[str, Union[str, bool, List[str]]]] + ] = [ { "name": "afni", "optional": True, diff --git a/junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py b/junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py index c494987d44..95045109d3 100644 --- a/junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py +++ b/junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py @@ -4,7 +4,7 @@ # Kaustubh R. Patil # License: AGPL -from typing import Any, Dict, List, Optional, Union +from typing import Any, ClassVar, Dict, List, Optional, Set, Union import pandas as pd @@ -39,7 +39,7 @@ class CrossParcellationFC(BaseMarker): (default None). """ - _DEPENDENCIES = {"nilearn"} + _DEPENDENCIES: ClassVar[Set[str]] = {"nilearn"} def __init__( self, diff --git a/junifer/markers/functional_connectivity/functional_connectivity_base.py b/junifer/markers/functional_connectivity/functional_connectivity_base.py index d893baa3cf..3924e2db58 100644 --- a/junifer/markers/functional_connectivity/functional_connectivity_base.py +++ b/junifer/markers/functional_connectivity/functional_connectivity_base.py @@ -5,7 +5,7 @@ from abc import abstractmethod -from typing import Any, Dict, List, Optional, Union +from typing import Any, ClassVar, Dict, List, Optional, Set, Union from nilearn.connectome import ConnectivityMeasure from sklearn.covariance import EmpiricalCovariance @@ -42,7 +42,7 @@ class FunctionalConnectivityBase(BaseMarker): """ - _DEPENDENCIES = {"nilearn", "scikit-learn"} + _DEPENDENCIES: ClassVar[Set[str]] = {"nilearn", "scikit-learn"} def __init__( self, diff --git a/junifer/markers/parcel_aggregation.py b/junifer/markers/parcel_aggregation.py index 3cd3cae651..7c9042bd1f 100644 --- a/junifer/markers/parcel_aggregation.py +++ b/junifer/markers/parcel_aggregation.py @@ -4,7 +4,7 @@ # Synchon Mandal # License: AGPL -from typing import Any, Dict, List, Optional, Union +from typing import Any, ClassVar, Dict, List, Optional, Set, Union import numpy as np from nilearn.image import math_img, resample_to_img @@ -51,7 +51,7 @@ class ParcelAggregation(BaseMarker): None). """ - _DEPENDENCIES = {"nilearn", "numpy"} + _DEPENDENCIES: ClassVar[Set[str]] = {"nilearn", "numpy"} def __init__( self, diff --git a/junifer/markers/reho/reho_base.py b/junifer/markers/reho/reho_base.py index 49834ee5c9..717c5c593f 100644 --- a/junifer/markers/reho/reho_base.py +++ b/junifer/markers/reho/reho_base.py @@ -4,7 +4,7 @@ # License: AGPL -from typing import TYPE_CHECKING, Any, Dict, List, Optional +from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, Optional, Union from ...utils import logger, raise_error from ..base import BaseMarker @@ -29,7 +29,9 @@ class ReHoBase(BaseMarker): """ - _EXT_DEPENDENCIES = [ + _EXT_DEPENDENCIES: ClassVar[ + List[Dict[str, Union[str, bool, List[str]]]] + ] = [ { "name": "afni", "optional": True, diff --git a/junifer/markers/sphere_aggregation.py b/junifer/markers/sphere_aggregation.py index 8aad154ec0..a5d9d5dd97 100644 --- a/junifer/markers/sphere_aggregation.py +++ b/junifer/markers/sphere_aggregation.py @@ -4,7 +4,7 @@ # Synchon Mandal # License: AGPL -from typing import Any, Dict, List, Optional, Union +from typing import Any, ClassVar, Dict, List, Optional, Set, Union from ..api.decorators import register_marker from ..data import get_mask, load_coordinates @@ -57,7 +57,7 @@ class SphereAggregation(BaseMarker): """ - _DEPENDENCIES = {"nilearn", "numpy"} + _DEPENDENCIES: ClassVar[Set[str]] = {"nilearn", "numpy"} def __init__( self, diff --git a/junifer/markers/temporal_snr/temporal_snr_base.py b/junifer/markers/temporal_snr/temporal_snr_base.py index 3809d0fad0..3972c97cbc 100644 --- a/junifer/markers/temporal_snr/temporal_snr_base.py +++ b/junifer/markers/temporal_snr/temporal_snr_base.py @@ -5,7 +5,7 @@ from abc import abstractmethod -from typing import Any, Dict, List, Optional, Union +from typing import Any, ClassVar, Dict, List, Optional, Set, Union from nilearn import image as nimg @@ -34,7 +34,7 @@ class TemporalSNRBase(BaseMarker): """ - _DEPENDENCIES = {"nilearn"} + _DEPENDENCIES: ClassVar[Set[str]] = {"nilearn"} def __init__( self, diff --git a/junifer/pipeline/tests/test_pipeline_step_mixin.py b/junifer/pipeline/tests/test_pipeline_step_mixin.py index e877bd9074..6afccf1133 100644 --- a/junifer/pipeline/tests/test_pipeline_step_mixin.py +++ b/junifer/pipeline/tests/test_pipeline_step_mixin.py @@ -5,7 +5,7 @@ # License: AGPL import warnings -from typing import Dict, List +from typing import ClassVar, Dict, List, Set, Union import pytest @@ -30,7 +30,7 @@ def test_pipeline_step_mixin_validate_correct_dependencies() -> None: class CorrectMixer(PipelineStepMixin): """Test class for validation.""" - _DEPENDENCIES = {"setuptools"} + _DEPENDENCIES: ClassVar[Set[str]] = {"setuptools"} def validate_input(self, input: List[str]) -> List[str]: return input @@ -51,7 +51,7 @@ def test_pipeline_step_mixin_validate_incorrect_dependencies() -> None: class IncorrectMixer(PipelineStepMixin): """Test class for validation.""" - _DEPENDENCIES = {"foobar"} + _DEPENDENCIES: ClassVar[Set[str]] = {"foobar"} def validate_input(self, input: List[str]) -> List[str]: return input @@ -76,7 +76,9 @@ def test_pipeline_step_mixin_validate_correct_ext_dependencies() -> None: class CorrectMixer(PipelineStepMixin): """Test class for validation.""" - _EXT_DEPENDENCIES = [{"name": "afni", "optional": False}] + _EXT_DEPENDENCIES: ClassVar[List[Dict[str, Union[str, bool]]]] = [ + {"name": "afni", "optional": False} + ] def validate_input(self, input: List[str]) -> List[str]: return input @@ -100,9 +102,9 @@ def test_pipeline_step_mixin_validate_ext_deps_correct_commands() -> None: class CorrectMixer(PipelineStepMixin): """Test class for validation.""" - _EXT_DEPENDENCIES = [ - {"name": "afni", "optional": False, "commands": ["3dReHo"]} - ] + _EXT_DEPENDENCIES: ClassVar[ + List[Dict[str, Union[str, bool, List[str]]]] + ] = [{"name": "afni", "optional": False, "commands": ["3dReHo"]}] def validate_input(self, input: List[str]) -> List[str]: return input @@ -128,9 +130,9 @@ def test_pipeline_step_mixin_validate_ext_deps_incorrect_commands() -> None: class CorrectMixer(PipelineStepMixin): """Test class for validation.""" - _EXT_DEPENDENCIES = [ - {"name": "afni", "optional": False, "commands": ["3d"]} - ] + _EXT_DEPENDENCIES: ClassVar[ + List[Dict[str, Union[str, bool, List[str]]]] + ] = [{"name": "afni", "optional": False, "commands": ["3d"]}] def validate_input(self, input: List[str]) -> List[str]: return input @@ -152,7 +154,9 @@ def test_pipeline_step_mixin_validate_incorrect_ext_dependencies() -> None: class IncorrectMixer(PipelineStepMixin): """Test class for validation.""" - _EXT_DEPENDENCIES = [{"name": "foobar", "optional": True}] + _EXT_DEPENDENCIES: ClassVar[List[Dict[str, Union[str, bool]]]] = [ + {"name": "foobar", "optional": True} + ] def validate_input(self, input: List[str]) -> List[str]: return input diff --git a/junifer/preprocess/confounds/fmriprep_confound_remover.py b/junifer/preprocess/confounds/fmriprep_confound_remover.py index 4d19d42bdb..dc14e2ce8b 100644 --- a/junifer/preprocess/confounds/fmriprep_confound_remover.py +++ b/junifer/preprocess/confounds/fmriprep_confound_remover.py @@ -5,7 +5,17 @@ # Synchon Mandal # License: AGPL -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union +from typing import ( + TYPE_CHECKING, + Any, + ClassVar, + Dict, + List, + Optional, + Set, + Tuple, + Union, +) import numpy as np import pandas as pd @@ -141,7 +151,7 @@ class fMRIPrepConfoundRemover(BasePreprocessor): """ - _DEPENDENCIES = {"numpy", "nilearn"} + _DEPENDENCIES: ClassVar[Set[str]] = {"numpy", "nilearn"} def __init__( self,