Skip to content

Commit

Permalink
Fix old pep8 errors (#1244)
Browse files Browse the repository at this point in the history
* Create deleteme.md

* Delete deleteme.md

* Change permissions to read in slash-command-dispatch.yml

* Automated autopep8 fixes

* Change BaseException to Exception

* remove backslash

* remove backslashes

* remove backslashes

* Automated autopep8 fixes

* Fix E501

* Fix backslash

* add ignore imports for autopep8

* restore numpy import

* Automated autopep8 fixes

* Fix E402

* Automated autopep8 fixes

* fix parentheses

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
DRMPN and github-actions[bot] authored Feb 8, 2024
1 parent 5efd0fb commit 78a8924
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 61 deletions.
26 changes: 14 additions & 12 deletions examples/advanced/automl/tpot_vs_fedot.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
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
import numpy # NOQA

numpy.float = numpy.float64 # tmp patch before TPOT could fix this: https://github.com/EpistasisLab/tpot/issues/1281 # NOQA

from sklearn.ensemble import RandomForestClassifier # NOQA
from sklearn.metrics import roc_auc_score as roc_auc # NOQA
from sklearn.naive_bayes import BernoulliNB # NOQA
from sklearn.pipeline import make_pipeline # NOQA
from tpot.builtins import StackingEstimator # NOQA
from tpot.export_utils import set_param_recursive # NOQA

from fedot.core.pipelines.pipeline import Pipeline # NOQA
from fedot.core.pipelines.node import PipelineNode # NOQA
from fedot.core.data.data import InputData # NOQA


def run_tpot_vs_fedot_example(train_file_path: str, test_file_path: str):
Expand Down
7 changes: 5 additions & 2 deletions fedot/api/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ 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)
return (
timeout_not_set
or self.assumption_fit_spend_time
< 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def transform(self, input_data: InputData) -> OutputData:
features = input_data.features
with Parallel(n_jobs=self.n_jobs, prefer='processes') as parallel:
topological_features = parallel(delayed(self._extract_features)
(np.mean(features[i:i+2, ::self.stride], axis=0))
(np.mean(features[i:i + 2, ::self.stride], axis=0))
for i in range(0, features.shape[0], 2))
if len(topological_features) * 2 < features.shape[0]:
topological_features.append(topological_features[-1])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 BaseException:
except Exception:
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)
Expand Down
40 changes: 21 additions & 19 deletions test/unit/data/test_data_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,27 @@ def test_multivariate_time_series_splitting_correct():
assert np.allclose(test_series_data.target, np.array([16, 17, 18, 19]))


@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),
])
@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),
],
)
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)
Expand Down
29 changes: 12 additions & 17 deletions test/unit/pipelines/test_pipeline_node_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,48 +38,43 @@ def test_change_node(nodes, node_factory):
assert new_primary_node is not None
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)
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']
assert new_secondary_node.content['name'] \
in node_factory.graph_model_repository.get_operations(is_primary=False)
assert new_primary_node.content['name'] 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']
assert new_secondary_node.content['name'] in node_factory.graph_model_repository.get_operations(is_primary=False)


def test_get_intermediate_parent_node(nodes, node_factory):
_, _, secondary_node = nodes
new_intermediate_parent_node = node_factory.get_parent_node(secondary_node, is_primary=False)

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)
assert new_intermediate_parent_node.content['name'] 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]
assert new_intermediate_parent_node.content['name'] not in [
str(n.content['name']) for n in secondary_node.nodes_from]


def test_get_separate_parent_node(nodes, node_factory):
_, _, secondary_node = nodes
new_separate_parent_node = node_factory.get_parent_node(secondary_node, is_primary=True)

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)
assert new_separate_parent_node.content['name'] in node_factory.graph_model_repository.get_operations(
is_primary=True)
assert new_separate_parent_node.content['name'] != secondary_node.content['name']


def test_get_child_node(node_factory):
new_child_node = node_factory.get_node(is_primary=False)

assert new_child_node is not None
assert new_child_node.content['name'] \
in node_factory.graph_model_repository.get_operations(is_primary=False)
assert new_child_node.content['name'] in node_factory.graph_model_repository.get_operations(is_primary=False)


def test_get_primary_node(node_factory):
new_primary_node = node_factory.get_node(is_primary=True)

assert new_primary_node is not None
assert new_primary_node.content['name'] \
in node_factory.graph_model_repository.get_operations(is_primary=True)
assert new_primary_node.content['name'] in node_factory.graph_model_repository.get_operations(is_primary=True)
28 changes: 19 additions & 9 deletions test/unit/pipelines/test_pipeline_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
from fedot.core.pipelines.node import PipelineNode
from fedot.core.pipelines.pipeline import Pipeline
from fedot.core.pipelines.verification import (verify_pipeline)
from fedot.core.pipelines.verification_rules import has_correct_operations_for_task, has_final_operation_as_model, \
has_no_conflicts_in_decompose, has_no_conflicts_with_data_flow, has_no_data_flow_conflicts_in_ts_pipeline, \
has_primary_nodes, only_non_lagged_operations_are_primary, \
has_correct_data_sources, has_parent_contain_single_resample, has_no_conflicts_during_multitask, \
has_no_conflicts_after_class_decompose
from fedot.core.pipelines.verification_rules import (
has_correct_operations_for_task,
has_final_operation_as_model,
has_no_conflicts_in_decompose,
has_no_conflicts_with_data_flow,
has_no_data_flow_conflicts_in_ts_pipeline,
has_primary_nodes,
only_non_lagged_operations_are_primary,
has_correct_data_sources,
has_parent_contain_single_resample,
has_no_conflicts_during_multitask,
has_no_conflicts_after_class_decompose,
)
from fedot.core.repository.tasks import Task, TaskTypesEnum
from golem.core.dag.verification_rules import has_no_cycle

Expand Down Expand Up @@ -239,8 +247,8 @@ def test_ts_pipeline_with_incorrect_data_flow():
with pytest.raises(Exception) as exc:
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'
assert str(
exc.value) == f'{PIPELINE_ERROR_PREFIX} Pipeline has incorrect subgraph with wrong parent nodes combination'


def test_only_non_lagged_operations_are_primary():
Expand All @@ -257,8 +265,10 @@ def test_only_non_lagged_operations_are_primary():
with pytest.raises(Exception) as exc:
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'
assert (
str(exc.value)
== f"{PIPELINE_ERROR_PREFIX} Pipeline for forecasting has not non_lagged preprocessing in primary nodes"
)


def test_has_two_parents_for_decompose_operations():
Expand Down

0 comments on commit 78a8924

Please sign in to comment.