diff --git a/.github/workflows/autopep8.yml b/.github/workflows/autopep8.yml new file mode 100644 index 0000000000..298462d624 --- /dev/null +++ b/.github/workflows/autopep8.yml @@ -0,0 +1,60 @@ +name: Format python code +on: push +jobs: + autopep8: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: autopep8 + id: autopep8 + uses: peter-evans/autopep8@v2 + with: + args: --exit-code --max-line-length 120 --recursive --in-place --aggressive --aggressive . + - name: Get Pull Request Number + id: pr + run: echo "::set-output name=pull_request_number::$(gh pr view --json number -q .number || echo "")" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Find Comment + uses: peter-evans/find-comment@v2 + id: fc + with: + issue-number: ${{ steps.pr.outputs.pull_request_number }} + comment-author: "github-actions[bot]" + - name: Create comment if autopep8 made NO changes + if: ${{ steps.fc.outputs.comment-id == '' && steps.autopep8.outputs.exit-code != 2}} + uses: peter-evans/create-or-update-comment@v3 + with: + issue-number: ${{ steps.pr.outputs.pull_request_number }} + body: | + Code has no PEP8 errors! + - name: Create comment if autopep8 made changes + if: ${{ steps.fc.outputs.comment-id == '' && steps.autopep8.outputs.exit-code == 2}} + uses: peter-evans/create-or-update-comment@v3 + with: + issue-number: ${{ steps.pr.outputs.pull_request_number }} + body: | + Code in this pull request contains PEP8 errors, please write the `/autopep8` command in the comments below to create pull request with automatic fixes. + - name: Update comment if NOT fixed + if: ${{ steps.fc.outputs.comment-id != '' && steps.autopep8.outputs.exit-code == 2}} + uses: peter-evans/create-or-update-comment@v3 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + edit-mode: replace + body: | + Code in this pull request **still** contains PEP8 errors, please write the `/autopep8` command in the comments below to create pull request with automatic fixes. + + ##### Comment last updated at ${{ github.event.head_commit.timestamp }} + - name: Update comment if fixed + if: ${{ steps.fc.outputs.comment-id != '' && steps.autopep8.outputs.exit-code != 2}} + uses: peter-evans/create-or-update-comment@v3 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + edit-mode: replace + body: | + All PEP8 errors has been fixed, thanks <3 + + ##### Comment last updated at ${{ github.event.head_commit.timestamp }} + - name: Fail if autopep8 made changes + if: steps.autopep8.outputs.exit-code == 2 + run: exit 1 diff --git a/.github/workflows/example-command.yml b/.github/workflows/example-command.yml index 815d8b2998..d2c732cfdb 100644 --- a/.github/workflows/example-command.yml +++ b/.github/workflows/example-command.yml @@ -6,10 +6,32 @@ jobs: example: runs-on: ubuntu-latest steps: - - name: Add reaction - uses: peter-evans/create-or-update-comment@v1 + - uses: actions/checkout@v4 + with: + repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} + ref: ${{ github.event.client_payload.pull_request.head.ref }} + - name: autopep8 + id: autopep8 + uses: peter-evans/autopep8@v2 + with: + args: --exit-code --max-line-length 120 --recursive --in-place --aggressive --aggressive . + - name: Create Pull Request + if: steps.autopep8.outputs.exit-code == 2 + id: cpr + uses: peter-evans/create-pull-request@v5 + with: + commit-message: autopep8 action fixes + title: Fixes by autopep8 action + body: This is an auto-generated PR with fixes by autopep8 in ${{ github.event.client_payload.pull_request.head.ref }}. + labels: autopep8, automated pr + assignees: ${{ github.actor }} + reviewers: ${{ github.actor }} + branch: autopep8-patches + - name: Create comment + if: steps.cpr.outputs.pull-request-url != '' + uses: peter-evans/create-or-update-comment@v3 with: - token: ${{ secrets.REPO_ACCESS_TOKEN }} repository: ${{ github.event.client_payload.github.payload.repository.full_name }} - comment-id: ${{ github.event.client_payload.github.payload.comment.id }} - reaction-type: hooray + issue-number: ${{ github.event.client_payload.github.payload.issue.number }} + body: | + Fixed PEP8 problems, please go to ${{ steps.cpr.outputs.pull-request-url }} and merge it. diff --git a/cases/dataset_preparation.py b/cases/dataset_preparation.py index 4a0a7b4c8e..b0b7a70ffe 100644 --- a/cases/dataset_preparation.py +++ b/cases/dataset_preparation.py @@ -8,24 +8,23 @@ def unpack_archived_data(archive_name: str): os.path.basename(archive_name) not in os.listdir(os.path.dirname(archive_path))): with tarfile.open(archive_path) as file: def is_within_directory(directory, target): - + abs_directory = os.path.abspath(directory) abs_target = os.path.abspath(target) - + prefix = os.path.commonprefix([abs_directory, abs_target]) - + return prefix == abs_directory - + def safe_extract(tar, path=".", members=None, *, numeric_owner=False): - + for member in tar.getmembers(): member_path = os.path.join(path, member.name) if not is_within_directory(path, member_path): raise Exception("Attempted Path Traversal in Tar File") - - tar.extractall(path, members, numeric_owner=numeric_owner) - - + + tar.extractall(path, members, numeric_owner=numeric_owner) + safe_extract(file, path=os.path.dirname(archive_path)) print('Unpacking finished') else: diff --git a/cases/time_series_gapfilling_case.py b/cases/time_series_gapfilling_case.py index a0b6cac28f..67c48cea36 100644 --- a/cases/time_series_gapfilling_case.py +++ b/cases/time_series_gapfilling_case.py @@ -80,7 +80,7 @@ def get_composite_pipeline(): node_linear_2 = PipelineNode('linear', nodes_from=[node_2]) node_final = PipelineNode('ridge', nodes_from=[node_linear_1, - node_linear_2]) + node_linear_2]) pipeline = Pipeline(node_final) return pipeline diff --git a/examples/advanced/automl/tpot_vs_fedot.py b/examples/advanced/automl/tpot_vs_fedot.py index ee311088bf..1090d6378c 100644 --- a/examples/advanced/automl/tpot_vs_fedot.py +++ b/examples/advanced/automl/tpot_vs_fedot.py @@ -1,18 +1,16 @@ +from fedot.core.data.data import InputData +from fedot.core.pipelines.node import PipelineNode +from fedot.core.pipelines.pipeline import Pipeline +from tpot.export_utils import set_param_recursive +from tpot.builtins import StackingEstimator +from sklearn.pipeline import make_pipeline +from sklearn.naive_bayes import BernoulliNB +from sklearn.metrics import roc_auc_score as roc_auc +from sklearn.ensemble import RandomForestClassifier import numpy numpy.float = numpy.float64 # tmp patch before TPOT could fix this: https://github.com/EpistasisLab/tpot/issues/1281 -from sklearn.ensemble import RandomForestClassifier -from sklearn.metrics import roc_auc_score as roc_auc -from sklearn.naive_bayes import BernoulliNB -from sklearn.pipeline import make_pipeline -from tpot.builtins import StackingEstimator -from tpot.export_utils import set_param_recursive - -from fedot.core.pipelines.pipeline import Pipeline -from fedot.core.pipelines.node import PipelineNode -from fedot.core.data.data import InputData - def run_tpot_vs_fedot_example(train_file_path: str, test_file_path: str): train_data = InputData.from_csv(train_file_path) diff --git a/examples/advanced/structural_analysis/structural_analysis_example.py b/examples/advanced/structural_analysis/structural_analysis_example.py index 1a58e5c0f7..6e65557184 100644 --- a/examples/advanced/structural_analysis/structural_analysis_example.py +++ b/examples/advanced/structural_analysis/structural_analysis_example.py @@ -31,6 +31,7 @@ class SAObjective(Objective): This objective has to evaluate pipeline in __call__ method and have 'metrics' field to identify which metrics are optimized. """ + def __init__(self, objective: Callable, quality_metrics: Dict[Any, Callable], diff --git a/examples/advanced/time_series_forecasting/nemo.py b/examples/advanced/time_series_forecasting/nemo.py index 0020f0124a..daeb1913f9 100644 --- a/examples/advanced/time_series_forecasting/nemo.py +++ b/examples/advanced/time_series_forecasting/nemo.py @@ -117,11 +117,11 @@ def return_working_pipeline(): pipeline = get_arima_pipeline() train_dataset = MultiModalData({ - 'arima': deepcopy(train_input), - }) + 'arima': deepcopy(train_input), +}) predict_dataset = MultiModalData({ - 'arima': deepcopy(predict_input), - }) + 'arima': deepcopy(predict_input), +}) pipeline.fit_from_scratch(train_dataset) predicted_values = pipeline.predict(predict_dataset) predicted_values = predicted_values.predict @@ -140,13 +140,13 @@ def return_working_pipeline(): # arima with nemo ensemble pipeline = return_working_pipeline() train_dataset = MultiModalData({ - 'lagged/1': deepcopy(train_input), - 'exog_ts': deepcopy(train_input_exog) - }) + 'lagged/1': deepcopy(train_input), + 'exog_ts': deepcopy(train_input_exog) +}) predict_dataset = MultiModalData({ - 'lagged/1': deepcopy(predict_input), - 'exog_ts': deepcopy(predict_input_exog) - }) + 'lagged/1': deepcopy(predict_input), + 'exog_ts': deepcopy(predict_input_exog) +}) pipeline.fit_from_scratch(train_dataset) predicted_values = pipeline.predict(predict_dataset).predict @@ -165,13 +165,13 @@ def return_working_pipeline(): # arima with nemo ensemble pipeline = get_arima_nemo_pipeline() train_dataset = MultiModalData({ - 'arima': deepcopy(train_input), - 'exog_ts': deepcopy(train_input_exog) - }) + 'arima': deepcopy(train_input), + 'exog_ts': deepcopy(train_input_exog) +}) predict_dataset = MultiModalData({ - 'arima': deepcopy(predict_input), - 'exog_ts': deepcopy(predict_input_exog) - }) + 'arima': deepcopy(predict_input), + 'exog_ts': deepcopy(predict_input_exog) +}) pipeline.fit_from_scratch(train_dataset) predicted_values = pipeline.predict(predict_dataset).predict diff --git a/examples/advanced/time_series_forecasting/prediction_intervals.py b/examples/advanced/time_series_forecasting/prediction_intervals.py index 90fc5ee14e..25d08d6e83 100644 --- a/examples/advanced/time_series_forecasting/prediction_intervals.py +++ b/examples/advanced/time_series_forecasting/prediction_intervals.py @@ -35,10 +35,10 @@ def build_pred_ints(start=5000, end=7000, horizon=200): task=task, data_type=DataTypesEnum.ts) model = Fedot(problem='ts_forecasting', - task_params=task.task_params, - timeout=3, - preset='ts', - show_progress=False) + task_params=task.task_params, + timeout=3, + preset='ts', + show_progress=False) model.fit(train_input) model.forecast() diff --git a/examples/simple/classification/classification_pipelines.py b/examples/simple/classification/classification_pipelines.py index e25dccd7fd..bfda0344a0 100644 --- a/examples/simple/classification/classification_pipelines.py +++ b/examples/simple/classification/classification_pipelines.py @@ -76,7 +76,7 @@ def classification_complex_pipeline(): first = PipelineNode(operation_type='rf') second = PipelineNode(operation_type='knn') final = PipelineNode(operation_type='logit', - nodes_from=[first, second]) + nodes_from=[first, second]) pipeline = Pipeline(final) @@ -128,8 +128,8 @@ def classification_svc_complex_pipeline(): svc_node_with_custom_params = PipelineNode('svc') svc_node_with_custom_params.parameters = dict(kernel='rbf', C=10, - gamma=1, cache_size=2000, - probability=True) + gamma=1, cache_size=2000, + probability=True) logit_secondary_node_2 = PipelineNode('logit', nodes_from=[svc_node_with_custom_params]) knn_primary_node = PipelineNode('knn') diff --git a/fedot/api/fedot_cli.py b/fedot/api/fedot_cli.py index bf4d5f8b0d..6d8323533a 100644 --- a/fedot/api/fedot_cli.py +++ b/fedot/api/fedot_cli.py @@ -61,7 +61,7 @@ def preprocess_keys(parameters: dict): for k, v in list(parameters.items()): if v is None: del parameters[k] - elif type(v) is not bool: + elif not isinstance(v, bool): try: parameters[k] = float(v) except Exception: diff --git a/fedot/api/time.py b/fedot/api/time.py index f62a954e08..4262cabfc4 100644 --- a/fedot/api/time.py +++ b/fedot/api/time.py @@ -39,7 +39,7 @@ def __define_timeouts_for_stages(self): def have_time_for_composing(self, pop_size: int, n_jobs: int) -> bool: timeout_not_set = self.timedelta_composing is None return timeout_not_set or self.assumption_fit_spend_time < \ - self.timedelta_composing * n_jobs / (pop_size * MIN_NUMBER_OF_GENERATIONS) + self.timedelta_composing * n_jobs / (pop_size * MIN_NUMBER_OF_GENERATIONS) def have_time_for_the_best_quality(self, n_jobs: int): timeout_not_set = self.timedelta_automl is None diff --git a/fedot/core/caching/pipelines_cache_db.py b/fedot/core/caching/pipelines_cache_db.py index 3226940cfd..d558bfea13 100644 --- a/fedot/core/caching/pipelines_cache_db.py +++ b/fedot/core/caching/pipelines_cache_db.py @@ -19,7 +19,8 @@ class OperationsCacheDB(BaseCacheDB): """ def __init__(self, cache_dir: Optional[str] = None): - super().__init__('operations', cache_dir, False, ['pipelines_hit', 'pipelines_total', 'nodes_hit', 'nodes_total']) + super().__init__('operations', cache_dir, False, [ + 'pipelines_hit', 'pipelines_total', 'nodes_hit', 'nodes_total']) self._init_db() @staticmethod diff --git a/fedot/core/data/data.py b/fedot/core/data/data.py index fc071d5a99..16a739d657 100644 --- a/fedot/core/data/data.py +++ b/fedot/core/data/data.py @@ -330,7 +330,7 @@ def from_image(images: Union[str, np.ndarray] = None, features = images target = labels - if type(images) is str: + if isinstance(images, str): # if upload from path if '*.jpeg' in images: # upload from folder of images diff --git a/fedot/core/operations/data_operation.py b/fedot/core/operations/data_operation.py index 644da061b2..525aa4f9c2 100644 --- a/fedot/core/operations/data_operation.py +++ b/fedot/core/operations/data_operation.py @@ -9,6 +9,7 @@ class DataOperation(Operation): Args: operation_type: name of the data operation """ + def __init__(self, operation_type: str): super().__init__(operation_type) self.operations_repo = OperationTypesRepository('data_operation') diff --git a/fedot/core/operations/evaluation/evaluation_interfaces.py b/fedot/core/operations/evaluation/evaluation_interfaces.py index 7a4fcaed95..5849ab3f17 100644 --- a/fedot/core/operations/evaluation/evaluation_interfaces.py +++ b/fedot/core/operations/evaluation/evaluation_interfaces.py @@ -119,7 +119,7 @@ def _convert_to_output(prediction, predict_data: InputData, Returns: prediction as :obj:`OutputData` """ - if type(prediction) is not OutputData: + if not isinstance(prediction, OutputData): # Wrap prediction as OutputData converted = OutputData(idx=predict_data.idx, features=predict_data.features, diff --git a/fedot/core/operations/evaluation/operation_implementations/data_operations/sklearn_transformations.py b/fedot/core/operations/evaluation/operation_implementations/data_operations/sklearn_transformations.py index b75e70076c..91acb1bdc9 100644 --- a/fedot/core/operations/evaluation/operation_implementations/data_operations/sklearn_transformations.py +++ b/fedot/core/operations/evaluation/operation_implementations/data_operations/sklearn_transformations.py @@ -72,7 +72,7 @@ def check_and_correct_params(self): parameter in PCA or not. And if not enough - fixes it """ n_components = self.params.get('n_components') - if type(n_components) == int: + if isinstance(n_components, int): if n_components > self.number_of_features: self.params.update(n_components=self.number_of_features) elif n_components == 'mle': @@ -127,6 +127,7 @@ class FastICAImplementation(ComponentAnalysisImplementation): Args: params: OperationParameters with the hyperparameters """ + def __init__(self, params: Optional[OperationParameters]): super().__init__(params) self.pca = FastICA(**self.params.to_dict()) diff --git a/fedot/core/operations/evaluation/operation_implementations/models/ts_implementations/statsmodels.py b/fedot/core/operations/evaluation/operation_implementations/models/ts_implementations/statsmodels.py index 4c659a775c..0982f9944e 100644 --- a/fedot/core/operations/evaluation/operation_implementations/models/ts_implementations/statsmodels.py +++ b/fedot/core/operations/evaluation/operation_implementations/models/ts_implementations/statsmodels.py @@ -261,7 +261,7 @@ def fit(self, input_data): error=self.params.get("error"), trend=self.params.get("trend"), seasonal=self.params.get("seasonal"), - damped_trend= self.params.get("damped_trend") if self.params.get("trend") else None, + damped_trend=self.params.get("damped_trend") if self.params.get("trend") else None, seasonal_periods=self.seasonal_periods ) self.model = self.model.fit(disp=False) diff --git a/fedot/core/operations/operation_parameters.py b/fedot/core/operations/operation_parameters.py index dc997937d3..1936c965ce 100644 --- a/fedot/core/operations/operation_parameters.py +++ b/fedot/core/operations/operation_parameters.py @@ -17,6 +17,7 @@ class OperationParameters: parameters: dict with parameters """ + def __init__(self, **parameters): self._parameters = parameters self._changed_keys: list = [] diff --git a/fedot/core/pipelines/automl_wrappers.py b/fedot/core/pipelines/automl_wrappers.py index f333b7e1b5..7a9d572ab6 100644 --- a/fedot/core/pipelines/automl_wrappers.py +++ b/fedot/core/pipelines/automl_wrappers.py @@ -5,6 +5,7 @@ class TPOTRegressionSerializationWrapper: """ Wrapper to serialize tpot algorithms. Can be used for classification, multioutput regression and time series forecasting""" + def __init__(self, estimators): self._estimators = estimators @@ -16,6 +17,7 @@ class H2OSerializationWrapper: """ Wrapper to serialize h2o algorithms. Can be used for classification, multioutput regression and time series forecasting. Unfortunately there are no support for all types of h2o pipelines (for this version)""" + def __init__(self, estimators): self._estimators = estimators diff --git a/fedot/core/pipelines/prediction_intervals/solvers/best_pipelines_quantiles.py b/fedot/core/pipelines/prediction_intervals/solvers/best_pipelines_quantiles.py index 8038a0b3d6..9311708465 100644 --- a/fedot/core/pipelines/prediction_intervals/solvers/best_pipelines_quantiles.py +++ b/fedot/core/pipelines/prediction_intervals/solvers/best_pipelines_quantiles.py @@ -10,11 +10,11 @@ def solver_best_pipelines_quantiles(train_input: InputData, - generation: List[Individual], - logger: LoggerAdapter, - horizon: int, - number_models: Union[int, str], - show_progress: bool): + generation: List[Individual], + logger: LoggerAdapter, + horizon: int, + number_models: Union[int, str], + show_progress: bool): """This function realizes 'best_pipelines_quantiles' method. Args: diff --git a/fedot/core/pipelines/prediction_intervals/solvers/mutation_of_best_pipeline.py b/fedot/core/pipelines/prediction_intervals/solvers/mutation_of_best_pipeline.py index 6270305fb1..92ee495ea8 100644 --- a/fedot/core/pipelines/prediction_intervals/solvers/mutation_of_best_pipeline.py +++ b/fedot/core/pipelines/prediction_intervals/solvers/mutation_of_best_pipeline.py @@ -75,7 +75,7 @@ def solver_mutation_of_best_pipeline(train_input: InputData, # TODO: create new approach to mutation generation: # mutate and fit in one try in get_mutations/get_different_mutations pipeline.fit(train_input) - except: + except BaseException: continue pred = out_of_sample_ts_forecast(pipeline=pipeline, input_data=train_input, horizon=horizon) metric_value = RMSE.get_value(pipeline=pipeline, reference_data=train_input, validation_blocks=2) diff --git a/fedot/core/pipelines/verification_rules.py b/fedot/core/pipelines/verification_rules.py index b36dfa46ef..14f30e004b 100644 --- a/fedot/core/pipelines/verification_rules.py +++ b/fedot/core/pipelines/verification_rules.py @@ -27,7 +27,7 @@ def has_final_operation_as_model(pipeline: Pipeline): """ Check if the operation in root node is model or not """ root_node = pipeline.root_node # TODO @YamLyubov refactor check for AtomizedModel (fix circular import) - if type(root_node.operation) is not Model and root_node.operation.operation_type != atomized_model_type(): + if not isinstance(root_node.operation, Model) and root_node.operation.operation_type != atomized_model_type(): raise ValueError(f'{ERROR_PREFIX} Root operation is not a model') return True @@ -347,7 +347,7 @@ def __check_decompose_parent_position(nodes_to_check: list): parents = decompose_node.nodes_from model_parent = parents[0] - if type(model_parent.operation) is not Model: + if not isinstance(model_parent.operation, Model): raise ValueError(f'{ERROR_PREFIX} For decompose operation Model as first parent is required') diff --git a/fedot/core/repository/pipeline_operation_repository.py b/fedot/core/repository/pipeline_operation_repository.py index 2a9c1ef0b9..b379dcb1e0 100644 --- a/fedot/core/repository/pipeline_operation_repository.py +++ b/fedot/core/repository/pipeline_operation_repository.py @@ -19,6 +19,7 @@ class PipelineOperationRepository(GraphOperationRepository): Args: operations_by_keys: available operations already splitted by keys """ + def __init__(self, operations_by_keys: Optional[Dict[str, List[str]]] = None): super().__init__() self.operations_by_keys = operations_by_keys or dict() diff --git a/fedot/preprocessing/data_type_check.py b/fedot/preprocessing/data_type_check.py index 0f349f2687..aa2ac8f7ac 100644 --- a/fedot/preprocessing/data_type_check.py +++ b/fedot/preprocessing/data_type_check.py @@ -3,6 +3,7 @@ def exclude_ts(preprocessing_function): """ Decorator for time series type checking """ + def wrapper(self, input_data, source_name, *args, **kwargs): if data_type_is_ts(input_data): return input_data @@ -12,6 +13,7 @@ def wrapper(self, input_data, source_name, *args, **kwargs): def exclude_multi_ts(preprocessing_function): """ Decorator for multi time series (not to be confused with multivariate ts) type checking """ + def wrapper(self, input_data, source_name, *args, **kwargs): if data_type_is_multi_ts(input_data): return input_data @@ -21,9 +23,9 @@ def wrapper(self, input_data, source_name, *args, **kwargs): def exclude_image(preprocessing_function): """ Decorator for image type checking """ + def wrapper(self, input_data, source_name, *args, **kwargs): if data_type_is_image(input_data): return input_data return preprocessing_function(self, input_data, source_name, *args, **kwargs) return wrapper - diff --git a/fedot/preprocessing/data_types.py b/fedot/preprocessing/data_types.py index 5f8b8557c0..1029d64be6 100644 --- a/fedot/preprocessing/data_types.py +++ b/fedot/preprocessing/data_types.py @@ -1,4 +1,5 @@ from __future__ import annotations +from typing import TYPE_CHECKING from copy import copy @@ -9,7 +10,6 @@ from fedot.core.repository.tasks import Task, TaskTypesEnum NoneType = type(None) -from typing import TYPE_CHECKING if TYPE_CHECKING: from fedot.core.data.data import InputData diff --git a/fedot/preprocessing/dummy_preprocessing.py b/fedot/preprocessing/dummy_preprocessing.py index b088938c6c..100b639ef1 100644 --- a/fedot/preprocessing/dummy_preprocessing.py +++ b/fedot/preprocessing/dummy_preprocessing.py @@ -26,17 +26,17 @@ def obligatory_prepare_for_fit(self, data: Union[InputData, MultiModalData]) -> return data def obligatory_prepare_for_predict(self, data: Union[InputData, MultiModalData]) -> Union[ - InputData, MultiModalData]: + InputData, MultiModalData]: BasePreprocessor.mark_as_preprocessed(data) return data def optional_prepare_for_fit(self, pipeline, data: Union[InputData, MultiModalData]) -> Union[ - InputData, MultiModalData]: + InputData, MultiModalData]: BasePreprocessor.mark_as_preprocessed(data, is_obligatory=False) return data def optional_prepare_for_predict(self, pipeline, data: Union[InputData, MultiModalData]) -> Union[ - InputData, MultiModalData]: + InputData, MultiModalData]: BasePreprocessor.mark_as_preprocessed(data, is_obligatory=False) return data @@ -50,16 +50,16 @@ def apply_inverse_target_encoding(self, column_to_transform: np.ndarray) -> np.n return column_to_transform def convert_indexes_for_fit(self, pipeline: 'Pipeline', data: Union[InputData, MultiModalData]) -> Union[ - InputData, MultiModalData]: + InputData, MultiModalData]: return data def convert_indexes_for_predict(self, pipeline, data: Union[InputData, MultiModalData]) -> Union[ - InputData, MultiModalData]: + InputData, MultiModalData]: return data def restore_index(self, input_data: InputData, result: OutputData) -> OutputData: return result def update_indices_for_time_series(self, test_data: Union[InputData, MultiModalData]) -> Union[ - InputData, MultiModalData]: + InputData, MultiModalData]: return test_data diff --git a/test/integration/api/test_main_api.py b/test/integration/api/test_main_api.py index a8ea407373..eb4d72ceb3 100644 --- a/test/integration/api/test_main_api.py +++ b/test/integration/api/test_main_api.py @@ -302,9 +302,9 @@ def test_api_check_data_correct(): string_data_input = ApiDataProcessor(task).define_data(features=path_to_train, target='target') array_data_input = ApiDataProcessor(task).define_data(features=x_train, target=x_test) fedot_data_input = ApiDataProcessor(task).define_data(features=train_data) - assert (not type(string_data_input) == InputData or - type(array_data_input) == InputData or - type(fedot_data_input) == InputData) + assert (not isinstance(string_data_input, InputData) or + isinstance(array_data_input, InputData) or + isinstance(fedot_data_input, InputData)) def test_api_check_multimodal_data_correct(): diff --git a/test/integration/classification/test_classification.py b/test/integration/classification/test_classification.py index 3ecd399fe0..68ac0ea244 100644 --- a/test/integration/classification/test_classification.py +++ b/test/integration/classification/test_classification.py @@ -32,7 +32,7 @@ def test_cnn_custom_class(): cnn_class = FedotCNNImplementation() assert cnn_class.params is not None - assert type(cnn_class) == FedotCNNImplementation + assert isinstance(cnn_class, FedotCNNImplementation) def test_image_classification_quality(): @@ -66,9 +66,9 @@ def test_cnn_methods(): prediction = predict_cnn(trained_model=model, predict_data=dataset_to_validate) - assert type(cnn_model) == tf.keras.Sequential + assert isinstance(cnn_model, tf.keras.Sequential) assert transform_flag is True assert cnn_model.input_shape[1:] == image_shape assert cnn_model.output_shape[1] == num_classes - assert type(prediction) == np.ndarray + assert isinstance(prediction, np.ndarray) assert check_predict_cnn_correct(model, dataset_to_validate) diff --git a/test/integration/composer/test_composer.py b/test/integration/composer/test_composer.py index a30d2a933b..f03723cc38 100644 --- a/test/integration/composer/test_composer.py +++ b/test/integration/composer/test_composer.py @@ -184,7 +184,7 @@ def test_multi_objective_composer(data_fixture, request): pipelines_evo_composed = composer.compose_pipeline(data=dataset_to_compose) pipelines_roc_auc = [] - assert type(pipelines_evo_composed) is list + assert isinstance(pipelines_evo_composed, list) assert len(composer.optimizer.objective.metrics) > 1 assert composer.optimizer.objective.is_multi_objective diff --git a/test/integration/data/test_data.py b/test/integration/data/test_data.py index ae455f67a7..5eb8d2d584 100644 --- a/test/integration/data/test_data.py +++ b/test/integration/data/test_data.py @@ -8,5 +8,5 @@ def test_data_from_image(): _, _, dataset_to_validate = get_image_classification_data() assert dataset_to_validate.data_type == DataTypesEnum.image - assert type(dataset_to_validate.features) == np.ndarray - assert type(dataset_to_validate.target) == np.ndarray + assert isinstance(dataset_to_validate.features, np.ndarray) + assert isinstance(dataset_to_validate.target, np.ndarray) diff --git a/test/integration/preprocessing/test_pipeline_preprocessing.py b/test/integration/preprocessing/test_pipeline_preprocessing.py index 9121cf2869..b1dcbaa2e0 100644 --- a/test/integration/preprocessing/test_pipeline_preprocessing.py +++ b/test/integration/preprocessing/test_pipeline_preprocessing.py @@ -17,7 +17,7 @@ def test_pipeline_has_dummy_preprocessor_with_disabled_preprocessing(): Tests pipeline with disabled input data preprocessing has dummy preprocessor """ pipeline = Pipeline(PipelineNode('ridge'), use_input_preprocessing=False) - assert type(pipeline.preprocessor) is DummyPreprocessor + assert isinstance(pipeline.preprocessor, DummyPreprocessor) def _assert_equal_data(data1: InputData, data2: InputData): diff --git a/test/integration/real_applications/test_heavy_models.py b/test/integration/real_applications/test_heavy_models.py index d38a590dfd..01e453bb7d 100644 --- a/test/integration/real_applications/test_heavy_models.py +++ b/test/integration/real_applications/test_heavy_models.py @@ -3,8 +3,6 @@ from fedot.core.pipelines.pipeline_builder import PipelineBuilder - - def test_cgru_forecasting(): horizon = 5 window_size = 200 diff --git a/test/sensitivity/test_sensitivity.py b/test/sensitivity/test_sensitivity.py index fb2a431221..8688c3896b 100644 --- a/test/sensitivity/test_sensitivity.py +++ b/test/sensitivity/test_sensitivity.py @@ -55,5 +55,5 @@ def test_multi_operations_analyze_analyze(analyze_method): test_data=test_data, path_to_save=result_dir).analyze(sample_size=1) # then - assert type(result) is list + assert isinstance(result, list) assert analyze_method.called diff --git a/test/unit/adapter/test_adapt_pipeline.py b/test/unit/adapter/test_adapt_pipeline.py index d35b347697..6bccbd8528 100644 --- a/test/unit/adapter/test_adapt_pipeline.py +++ b/test/unit/adapter/test_adapt_pipeline.py @@ -132,7 +132,7 @@ def test_pipelines_adapt_properly(pipeline): opt_graph = adapter.adapt(pipeline) - assert all(type(node) is OptNode for node in opt_graph.nodes) # checking strict type equality! + assert all(isinstance(node, OptNode) for node in opt_graph.nodes) # checking strict type equality! assert _check_nodes_references_correct(opt_graph) assert verifier(opt_graph) diff --git a/test/unit/api/test_api_builder.py b/test/unit/api/test_api_builder.py index a45ada82fc..44f7489a3c 100644 --- a/test/unit/api/test_api_builder.py +++ b/test/unit/api/test_api_builder.py @@ -53,8 +53,8 @@ def test_names_and_return_annotations_of_param_setters(fedot_builder_methods): def test_no_unexpected_method_names(fedot_builder_methods): methods = fedot_builder_methods unexpected_method_names = {func_name for func_name in methods.keys() if not ( - func_name.startswith('setup_') or - func_name in ['build'])} # add method names if needed. + func_name.startswith('setup_') or + func_name in ['build'])} # add method names if needed. assert not unexpected_method_names diff --git a/test/unit/data/test_data_split.py b/test/unit/data/test_data_split.py index b4f2b85cc7..f8a87f4d86 100644 --- a/test/unit/data/test_data_split.py +++ b/test/unit/data/test_data_split.py @@ -204,23 +204,23 @@ def test_multivariate_time_series_splitting_correct(): @pytest.mark.parametrize(('datas_funs', 'cv_folds', 'shuffle', 'stratify'), [ - # classification + stratify + shuffle + cv_folds - ([partial(get_tabular_classification_data, 100, 5)] * 3, 4, True, True), - # classification + shuffle + cv_folds - ([partial(get_tabular_classification_data, 100, 5)] * 3, 4, True, False), - # classification + cv_folds - ([partial(get_tabular_classification_data, 100, 5)] * 3, 4, False, False), - # classification + stratify + shuffle - ([partial(get_tabular_classification_data, 100, 5)] * 3, None, True, True), - # classification + shuffle - ([partial(get_tabular_classification_data, 100, 5)] * 3, None, True, False), - # classification - ([partial(get_tabular_classification_data, 100, 5)] * 3, None, False, False), - # timeseries + cv_folds - ([partial(get_ts_data_to_forecast, 10, 100)] * 3, 3, False, False), - # timeseries - ([partial(get_ts_data_to_forecast, 10, 100)] * 3, None, False, False), - ]) + # classification + stratify + shuffle + cv_folds + ([partial(get_tabular_classification_data, 100, 5)] * 3, 4, True, True), + # classification + shuffle + cv_folds + ([partial(get_tabular_classification_data, 100, 5)] * 3, 4, True, False), + # classification + cv_folds + ([partial(get_tabular_classification_data, 100, 5)] * 3, 4, False, False), + # classification + stratify + shuffle + ([partial(get_tabular_classification_data, 100, 5)] * 3, None, True, True), + # classification + shuffle + ([partial(get_tabular_classification_data, 100, 5)] * 3, None, True, False), + # classification + ([partial(get_tabular_classification_data, 100, 5)] * 3, None, False, False), + # timeseries + cv_folds + ([partial(get_ts_data_to_forecast, 10, 100)] * 3, 3, False, False), + # timeseries + ([partial(get_ts_data_to_forecast, 10, 100)] * 3, None, False, False), +]) def test_multimodal_data_splitting_is_correct(datas_funs, cv_folds, shuffle, stratify): mdata = MultiModalData({f'data_{i}': data_fun() for i, data_fun in enumerate(datas_funs)}) data_splitter = DataSourceSplitter(cv_folds=cv_folds, shuffle=shuffle, stratify=stratify) diff --git a/test/unit/pipelines/prediction_intervals/test_mutations.py b/test/unit/pipelines/prediction_intervals/test_mutations.py index 0237a985c8..ab1d5b2133 100644 --- a/test/unit/pipelines/prediction_intervals/test_mutations.py +++ b/test/unit/pipelines/prediction_intervals/test_mutations.py @@ -39,8 +39,8 @@ def check_uniqueness_mutations_structures(a: List[Individual]): def test_get_ts_mutation(params): for i in range(20): - assert type(get_ts_mutation(individual=params['individual'], - operations=params['operations'])) == Individual, f"mutation {i+1} failed." + assert isinstance(get_ts_mutation(individual=params['individual'], + operations=params['operations']), Individual), f"mutation {i+1} failed." def test_get_different_mutations(params): diff --git a/test/unit/pipelines/prediction_intervals/test_solver_mutations.py b/test/unit/pipelines/prediction_intervals/test_solver_mutations.py index e73e1473dc..071b1180f9 100644 --- a/test/unit/pipelines/prediction_intervals/test_solver_mutations.py +++ b/test/unit/pipelines/prediction_intervals/test_solver_mutations.py @@ -67,5 +67,5 @@ def test_solver_mutation_of_best_pipeline(params): elif x in [params_with_replacement, params_different]: prediction_length = len(res[0]) for y in res: - assert type(y) == np.ndarray, f"{x['message']} Wrong output of a mutation." + assert isinstance(y, np.ndarray), f"{x['message']} Wrong output of a mutation." assert len(y) == prediction_length, f"{x['message']} Wrong prediction length." diff --git a/test/unit/pipelines/test_pipeline.py b/test/unit/pipelines/test_pipeline.py index 2608e9338f..73245c6bed 100644 --- a/test/unit/pipelines/test_pipeline.py +++ b/test/unit/pipelines/test_pipeline.py @@ -375,7 +375,7 @@ def test_pipeline_fit_time_constraint(): except Exception as ex: received_ex = ex computation_time_first = test_pipeline_first.computation_time - assert type(received_ex) is TimeoutError + assert isinstance(received_ex, TimeoutError) comp_time_proc_with_first_constraint = (time.time() - process_start_time) time_constraint = datetime.timedelta(seconds=3) @@ -384,7 +384,7 @@ def test_pipeline_fit_time_constraint(): test_pipeline_first.fit(input_data=train_data, time_constraint=time_constraint) except Exception as ex: received_ex = ex - assert type(received_ex) is TimeoutError + assert isinstance(received_ex, TimeoutError) comp_time_proc_with_second_constraint = (time.time() - process_start_time) test_pipeline_second = pipeline_first() diff --git a/test/unit/pipelines/test_pipeline_node_factory.py b/test/unit/pipelines/test_pipeline_node_factory.py index 95caf7d98e..50d6d76b6a 100644 --- a/test/unit/pipelines/test_pipeline_node_factory.py +++ b/test/unit/pipelines/test_pipeline_node_factory.py @@ -39,12 +39,12 @@ def test_change_node(nodes, node_factory): assert new_secondary_node is not None assert new_intermediate_node is not None assert new_primary_node.content['name'] \ - in node_factory.graph_model_repository.get_operations(is_primary=True) + in node_factory.graph_model_repository.get_operations(is_primary=True) assert new_intermediate_node.content['name'] \ - in node_factory.graph_model_repository.get_operations(is_primary=False) and \ - new_intermediate_node.content['name'] != intermediate_node.content['name'] + in node_factory.graph_model_repository.get_operations(is_primary=False) and \ + new_intermediate_node.content['name'] != intermediate_node.content['name'] assert new_secondary_node.content['name'] \ - in node_factory.graph_model_repository.get_operations(is_primary=False) + in node_factory.graph_model_repository.get_operations(is_primary=False) def test_get_intermediate_parent_node(nodes, node_factory): @@ -53,10 +53,10 @@ def test_get_intermediate_parent_node(nodes, node_factory): assert new_intermediate_parent_node is not None assert new_intermediate_parent_node.content['name'] \ - in node_factory.graph_model_repository.get_operations(is_primary=False) + in node_factory.graph_model_repository.get_operations(is_primary=False) assert new_intermediate_parent_node.content['name'] != secondary_node.content['name'] assert new_intermediate_parent_node.content['name'] \ - not in [str(n.content['name']) for n in secondary_node.nodes_from] + not in [str(n.content['name']) for n in secondary_node.nodes_from] def test_get_separate_parent_node(nodes, node_factory): @@ -65,7 +65,7 @@ def test_get_separate_parent_node(nodes, node_factory): assert new_separate_parent_node is not None assert new_separate_parent_node.content['name'] \ - in node_factory.graph_model_repository.get_operations(is_primary=True) + in node_factory.graph_model_repository.get_operations(is_primary=True) assert new_separate_parent_node.content['name'] != secondary_node.content['name'] @@ -74,7 +74,7 @@ def test_get_child_node(node_factory): assert new_child_node is not None assert new_child_node.content['name'] \ - in node_factory.graph_model_repository.get_operations(is_primary=False) + in node_factory.graph_model_repository.get_operations(is_primary=False) def test_get_primary_node(node_factory): @@ -82,4 +82,4 @@ def test_get_primary_node(node_factory): assert new_primary_node is not None assert new_primary_node.content['name'] \ - in node_factory.graph_model_repository.get_operations(is_primary=True) + in node_factory.graph_model_repository.get_operations(is_primary=True) diff --git a/test/unit/pipelines/test_pipeline_verification.py b/test/unit/pipelines/test_pipeline_verification.py index 55562bbc49..b339995e00 100644 --- a/test/unit/pipelines/test_pipeline_verification.py +++ b/test/unit/pipelines/test_pipeline_verification.py @@ -241,7 +241,7 @@ def test_ts_pipeline_with_incorrect_data_flow(): assert has_no_data_flow_conflicts_in_ts_pipeline(incorrect_pipeline) assert str(exc.value) == \ - f'{PIPELINE_ERROR_PREFIX} Pipeline has incorrect subgraph with wrong parent nodes combination' + f'{PIPELINE_ERROR_PREFIX} Pipeline has incorrect subgraph with wrong parent nodes combination' else: assert False @@ -261,7 +261,7 @@ def test_only_non_lagged_operations_are_primary(): assert only_non_lagged_operations_are_primary(incorrect_pipeline) assert str(exc.value) == \ - f'{PIPELINE_ERROR_PREFIX} Pipeline for forecasting has not non_lagged preprocessing in primary nodes' + f'{PIPELINE_ERROR_PREFIX} Pipeline for forecasting has not non_lagged preprocessing in primary nodes' def test_has_two_parents_for_decompose_operations(): diff --git a/ugly_file.py b/ugly_file.py new file mode 100644 index 0000000000..9e3e346082 --- /dev/null +++ b/ugly_file.py @@ -0,0 +1,24 @@ +total = (first_variable + + second_variable - + third_variable) +def function( + arg_one, arg_two, + arg_three, arg_four): + return arg_one + +y = x ** 2 + 5 +z = (x + y) * (x - y) + +if x > 5 and x % 2 == 0: + print('x is larger than 5 and divisible by 2!') + +my_list = [ 1, 2, 3, ] + +print(x , y) + +var1 = 5 +var2 = 6 +some_long_var = 7 + +def func_name_good(): + pass