From fe06e6f2a4ba567941fde688360e26583736c78d Mon Sep 17 00:00:00 2001 From: kljk345 Date: Wed, 17 Jul 2024 09:37:49 +0100 Subject: [PATCH] Depreciate typing-extensions. Inference fix for side info smiles and predict.py --- optunaz/config/buildconfig.py | 3 +-- optunaz/config/optconfig.py | 3 +-- optunaz/descriptors.py | 3 +-- optunaz/predict.py | 30 ++++++++++----------- optunaz/utils/preprocessing/deduplicator.py | 3 +-- optunaz/utils/preprocessing/splitter.py | 3 +-- pyproject.toml | 1 - 7 files changed, 20 insertions(+), 26 deletions(-) diff --git a/optunaz/config/buildconfig.py b/optunaz/config/buildconfig.py index 411578b..25a1a19 100644 --- a/optunaz/config/buildconfig.py +++ b/optunaz/config/buildconfig.py @@ -1,6 +1,6 @@ import abc from dataclasses import dataclass, field -from typing import Optional, Union +from typing import Optional, Union, Literal import sklearn import sklearn.cross_decomposition @@ -11,7 +11,6 @@ import xgboost from apischema import schema from sklearn.base import BaseEstimator -from typing_extensions import Literal import optunaz from optunaz import algorithms diff --git a/optunaz/config/optconfig.py b/optunaz/config/optconfig.py index 2ebd157..f8b70fd 100644 --- a/optunaz/config/optconfig.py +++ b/optunaz/config/optconfig.py @@ -1,11 +1,10 @@ import logging from dataclasses import dataclass, field from enum import Enum -from typing import Union, Optional, List, Iterable, Type, Any +from typing import Union, Optional, List, Iterable, Type, Any, Literal, Annotated from apischema import schema, type_name, serialize from apischema.metadata import none_as_undefined, required -from typing_extensions import Literal, Annotated from optunaz.config import ( ModelMode, diff --git a/optunaz/descriptors.py b/optunaz/descriptors.py index e82d3b6..57cbdb0 100644 --- a/optunaz/descriptors.py +++ b/optunaz/descriptors.py @@ -4,7 +4,7 @@ import os import pathlib from dataclasses import dataclass, field -from typing import List, Union, Type, Optional, Any, Tuple, Dict +from typing import List, Union, Type, Optional, Any, Tuple, Dict, Literal, Annotated from functools import partial import apischema @@ -34,7 +34,6 @@ from jazzy.api import molecular_vector_from_smiles from jazzy.exception import JazzyError from sklearn import preprocessing -from typing_extensions import Literal, Annotated from joblib import Parallel, delayed, effective_n_jobs from optunaz.config import NameParameterDataclass from optunaz.utils import load_df_from_file diff --git a/optunaz/predict.py b/optunaz/predict.py index 8d05a49..6236016 100644 --- a/optunaz/predict.py +++ b/optunaz/predict.py @@ -45,6 +45,21 @@ def validate_uncertainty(args, model): raise UncertaintyError("Uncertainty not availble for this model") +def check_precomp_args(args): + try: + assert ( + args.input_precomputed_file is not None + ), "Must supply precomputed descriptor parameters" + assert ( + args.input_precomputed_input_column + ), "Must supply input column for precomputed descriptor" + assert ( + args.input_precomputed_response_column + ), "Must supply response column for precomputed descriptor" + except AssertionError as e: + raise PrecomputedError(e) + + def set_inference_params(args, desc): if hasattr(desc.parameters, "descriptor") and hasattr( desc.parameters.descriptor, "inference_parameters" @@ -62,21 +77,6 @@ def set_inference_params(args, desc): return False -def check_precomp_args(args): - try: - assert ( - args.input_precomputed_file is not None - ), "Must supply precomputed descriptor parameters" - assert ( - args.input_precomputed_input_column - ), "Must supply input column for precomputed descriptor" - assert ( - args.input_precomputed_response_column - ), "Must supply response column for precomputed descriptor" - except AssertionError as e: - raise PrecomputedError(e) - - def validate_set_precomputed(args, model): descriptor_str = model.descriptor.name if set_inference_params(args, model.descriptor): diff --git a/optunaz/utils/preprocessing/deduplicator.py b/optunaz/utils/preprocessing/deduplicator.py index 724ea68..a745e74 100644 --- a/optunaz/utils/preprocessing/deduplicator.py +++ b/optunaz/utils/preprocessing/deduplicator.py @@ -1,12 +1,11 @@ import abc from dataclasses import dataclass, field -from typing import Optional, Union, Any +from typing import Optional, Union, Any, Literal import pandas as pd from apischema import deserializer, serializer, schema, identity from apischema.conversions import Conversion from apischema.metadata import none_as_undefined -from typing_extensions import Literal # Python 3.7 class Deduplicator: diff --git a/optunaz/utils/preprocessing/splitter.py b/optunaz/utils/preprocessing/splitter.py index 3e71b9d..b208bba 100644 --- a/optunaz/utils/preprocessing/splitter.py +++ b/optunaz/utils/preprocessing/splitter.py @@ -1,6 +1,6 @@ import abc from dataclasses import dataclass, field -from typing import Optional, Iterator, Tuple, Union, Dict +from typing import Optional, Iterator, Tuple, Union, Dict, Literal, Annotated import numpy as np import sklearn @@ -13,7 +13,6 @@ PredefinedSplit, StratifiedGroupKFold, ) -from typing_extensions import Literal, Annotated # Python 3.7 class SklearnSplitter(abc.ABC): diff --git a/pyproject.toml b/pyproject.toml index 14e2f22..ce4fdc3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,6 @@ jsonpickle = "^2.0" xgboost = "^1.3" rdkit = ">=2023.3.1" scikit-learn = "1.4.0" -typing-extensions = ">=3.10, <5.0" apischema = "^0.17" chemprop = "1.6.1" descriptastorus = "^2.4" # Chemprop dependency, but chemprop does not install it itself.