Skip to content

Commit

Permalink
Automated autopep8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jan 31, 2024
1 parent f0c4098 commit 37d7326
Show file tree
Hide file tree
Showing 41 changed files with 117 additions and 114 deletions.
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
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
1 change: 0 additions & 1 deletion fedot/api/api_utils/api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,3 @@ def transform(self, test_data: InputData, current_pipeline) -> InputData:
self.log.message(f'Data preprocessing runtime = {datetime.now() - start_time}')

return test_data

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/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,4 +531,4 @@ def _train_pipeline_on_full_dataset(self, recommendations: Optional[dict],
self.current_pipeline.fit(
full_train_not_preprocessed,
n_jobs=self.params.n_jobs
)
)
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 @@ -73,7 +73,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
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def predict_for_fit(self, input_data: InputData) -> OutputData:
shape = features.shape[0]

window = self._window(features)
mean_values = np.array([np.mean(features[-window-shape+i:i+1]) for i in range(shape)])
mean_values = np.array([np.mean(features[-window - shape + i:i + 1]) for i in range(shape)])

forecast = np.repeat(mean_values.reshape((-1, 1)), forecast_length, axis=1)

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
4 changes: 2 additions & 2 deletions fedot/core/pipelines/verification_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def has_final_operation_as_model(pipeline: Pipeline):
root_node = pipeline.root_node
if root_node.operation.operation_type == atomized_model_type():
has_final_operation_as_model(root_node.operation.pipeline)
elif type(root_node.operation) is not Model:
elif not isinstance(root_node.operation, Model):
raise ValueError(f'{ERROR_PREFIX} Root operation is not a model')
return True

Expand Down Expand Up @@ -323,7 +323,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')


Expand Down
3 changes: 2 additions & 1 deletion fedot/core/repository/metrics_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def has_value(cls, value):
return value in cls._value2member_map_


class QualityMetricsEnum(MetricsEnum): pass
class QualityMetricsEnum(MetricsEnum):
pass


class ComplexityMetricsEnum(MetricsEnum):
Expand Down
1 change: 1 addition & 0 deletions fedot/core/repository/pipeline_operation_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion fedot/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ def convert_memory_size(size_bytes):
integer_size_value = int(math.floor(math.log(size_bytes, 1024)))
byte_digit = math.pow(1024, integer_size_value)
size_in_digit_name = round(size_bytes / byte_digit, 2)
return "%s %s" % (size_in_digit_name, digit_name[integer_size_value])
return "%s %s" % (size_in_digit_name, digit_name[integer_size_value])
4 changes: 3 additions & 1 deletion fedot/preprocessing/data_type_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

6 changes: 3 additions & 3 deletions test/integration/api/test_main_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Loading

0 comments on commit 37d7326

Please sign in to comment.