From 407633d37d5d9df9a25189ab0905059842eef7f1 Mon Sep 17 00:00:00 2001 From: Marcel Arpogaus <38564291+MArpogaus@users.noreply.github.com> Date: Sun, 15 Sep 2024 14:24:51 +0200 Subject: [PATCH] fix: use python 3.8 compatible type annotations --- src/dvc_stage/loading.py | 7 ++++--- src/dvc_stage/utils.py | 6 +++--- src/dvc_stage/validating.py | 16 ++++++++-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/dvc_stage/loading.py b/src/dvc_stage/loading.py index 9d044eb..a1f77e3 100644 --- a/src/dvc_stage/loading.py +++ b/src/dvc_stage/loading.py @@ -4,7 +4,7 @@ # author : Marcel Arpogaus # # created : 2024-09-15 13:51:13 (Marcel Arpogaus) -# changed : 2024-09-15 13:53:53 (Marcel Arpogaus) +# changed : 2024-09-15 14:23:53 (Marcel Arpogaus) # %% Description ############################################################### """loading module.""" @@ -13,6 +13,7 @@ import fnmatch import logging import os +from typing import Union import pandas as pd from tqdm import tqdm @@ -81,13 +82,13 @@ def _get_data_key(path: str, key_map: dict) -> str: # %% public functions ########################################################## def load_data( format: str, - paths: str | list, + paths: Union[str, list], key_map: dict = None, import_from: str = None, quiet: bool = False, return_keys: list = False, **kwds: object, -) -> object | dict: +) -> Union[object, dict]: """Load data from one or more files. Executes substage "loading". Parameters diff --git a/src/dvc_stage/utils.py b/src/dvc_stage/utils.py index daef08b..322582b 100644 --- a/src/dvc_stage/utils.py +++ b/src/dvc_stage/utils.py @@ -4,7 +4,7 @@ # author : Marcel Arpogaus # # created : 2024-09-15 13:18:39 (Marcel Arpogaus) -# changed : 2024-09-15 13:25:58 (Marcel Arpogaus) +# changed : 2024-09-15 14:24:02 (Marcel Arpogaus) # %% Description ############################################################### """utils module.""" @@ -14,7 +14,7 @@ import importlib import logging import re -from typing import Any, Callable, Dict, List, Set, Tuple +from typing import Any, Callable, Dict, List, Set, Tuple, Union # %% globals ################################################################### __LOGGER__ = logging.getLogger(__name__) @@ -75,7 +75,7 @@ def flatten_dict( def get_deps( - path: str | List[str], params: Dict[str, Any] + path: Union[str, List[str]], params: Dict[str, Any] ) -> Tuple[List[str], Set[str]]: """Get dependencies given a path pattern and parameter values. diff --git a/src/dvc_stage/validating.py b/src/dvc_stage/validating.py index 149107f..fcee5e5 100644 --- a/src/dvc_stage/validating.py +++ b/src/dvc_stage/validating.py @@ -4,7 +4,7 @@ # author : Marcel Arpogaus # # created : 2024-09-15 14:05:05 (Marcel Arpogaus) -# changed : 2024-09-15 14:12:22 (Marcel Arpogaus) +# changed : 2024-09-15 14:30:56 (Marcel Arpogaus) # %% Description ############################################################### @@ -12,7 +12,7 @@ # %% imports ################################################################### import logging -from typing import Any, Dict, Union +from typing import Any, Dict, List, Union import numpy as np import pandas as pd @@ -66,8 +66,8 @@ def _apply_validation( import_from: str = None, reduction: str = "any", expected: bool = True, - include: list[str] = [], - exclude: list[str] = [], + include: List[str] = [], + exclude: List[str] = [], pass_key_to_fn: bool = False, **kwds: Dict[str, Any], ) -> None: @@ -93,9 +93,9 @@ def _apply_validation( returned in full. expected : bool The expected output of the validation. - include : list[str] + include : List[str] List of keys to include in the validation. If empty, all keys will be included. - exclude : list[str] + exclude : List[str] List of keys to exclude from the validation. pass_key_to_fn : bool Flag to indicate if the key should be passed to the validation function. @@ -222,14 +222,14 @@ def validate_pandera_schema( return True -def apply_validations(data: any, validations: list[dict]) -> None: +def apply_validations(data: any, validations: List[dict]) -> None: """Apply validations to input data. Entrypoint for validation substage. Parameters ---------- data : pandas.DataFrame or dict of pandas.DataFrame Input data. - validations : list[dict] + validations : List[dict] List of dictionaries containing validation parameters. """