Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/autopep8.yml
Original file line number Diff line number Diff line change
@@ -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
32 changes: 27 additions & 5 deletions .github/workflows/example-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
17 changes: 8 additions & 9 deletions cases/dataset_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cases/time_series_gapfilling_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 9 additions & 11 deletions examples/advanced/automl/tpot_vs_fedot.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
32 changes: 16 additions & 16 deletions examples/advanced/time_series_forecasting/nemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions examples/simple/classification/classification_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion fedot/api/fedot_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion fedot/api/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion fedot/core/caching/pipelines_cache_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fedot/core/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions fedot/core/operations/data_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion fedot/core/operations/evaluation/evaluation_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions fedot/core/operations/operation_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class OperationParameters:
parameters: dict with parameters

"""

def __init__(self, **parameters):
self._parameters = parameters
self._changed_keys: list = []
Expand Down
2 changes: 2 additions & 0 deletions fedot/core/pipelines/automl_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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:
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)
Expand Down
Loading