-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use black to format pipeline code #4005
Changes from 9 commits
d522de0
6282de8
eb1dfe5
12473ba
c6d7d8b
0e5d8a7
06e420b
3dcd6ed
24a3dc9
5f5a9c8
3cb7c2a
7b31651
b081180
c261c7d
d47c9c2
b7ca934
f818f17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
black==23.1.0 | ||
catboost==1.1.1 | ||
category-encoders==2.5.1.post0 | ||
click==8.1.3 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from unittest.mock import patch | ||
|
||
import black | ||
import numpy as np | ||
import pandas as pd | ||
import pytest | ||
|
@@ -676,12 +677,12 @@ def __init__(self, random_arg=False, numpy_arg=[], random_seed=0): | |
parameters={"My Custom Estimator": {"numpy_arg": np.array([0])}}, | ||
) | ||
generated_pipeline_code = generate_pipeline_code(pipeline) | ||
assert ( | ||
generated_pipeline_code | ||
== "from evalml.pipelines.binary_classification_pipeline import BinaryClassificationPipeline\n" | ||
assert generated_pipeline_code == black.format_str( | ||
"from evalml.pipelines.binary_classification_pipeline import BinaryClassificationPipeline\n" | ||
"pipeline = BinaryClassificationPipeline(component_graph={'Imputer': ['Imputer', 'X', 'y'], 'My Custom Estimator': [CustomEstimator, 'Imputer.x', 'y']}, " | ||
"parameters={'Imputer':{'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'boolean_impute_strategy': 'most_frequent', 'categorical_fill_value': None, 'numeric_fill_value': None, 'boolean_fill_value': None}, " | ||
"'My Custom Estimator':{'random_arg': False, 'numpy_arg': array([0])}}, custom_name='Mock Binary Pipeline with Transformer', random_seed=0)" | ||
"'My Custom Estimator':{'random_arg': False, 'numpy_arg': array([0])}}, custom_name='Mock Binary Pipeline with Transformer', random_seed=0)", | ||
mode=black.Mode(target_versions={black.TargetVersion.PY39}, line_length=88), | ||
) | ||
|
||
pipeline = BinaryClassificationPipeline( | ||
|
@@ -690,37 +691,40 @@ def __init__(self, random_arg=False, numpy_arg=[], random_seed=0): | |
parameters={"My Custom Estimator": {"random_arg": Imputer()}}, | ||
) | ||
generated_pipeline_code = generate_pipeline_code(pipeline) | ||
assert ( | ||
generated_pipeline_code | ||
== "from evalml.pipelines.binary_classification_pipeline import BinaryClassificationPipeline\n" | ||
assert generated_pipeline_code == black.format_str( | ||
"from evalml.pipelines.binary_classification_pipeline import BinaryClassificationPipeline\n" | ||
"pipeline = BinaryClassificationPipeline(component_graph={'Imputer': ['Imputer', 'X', 'y'], 'My Custom Estimator': [CustomEstimator, 'Imputer.x', 'y']}, " | ||
"parameters={'Imputer':{'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'boolean_impute_strategy': 'most_frequent', 'categorical_fill_value': None, 'numeric_fill_value': None, 'boolean_fill_value': None}, " | ||
"'My Custom Estimator':{'random_arg': Imputer(categorical_impute_strategy='most_frequent', numeric_impute_strategy='mean', boolean_impute_strategy='most_frequent', categorical_fill_value=None, numeric_fill_value=None, boolean_fill_value=None), 'numpy_arg': []}}, " | ||
"custom_name='Mock Binary Pipeline with Transformer', random_seed=0)" | ||
"custom_name='Mock Binary Pipeline with Transformer', random_seed=0)", | ||
mode=black.Mode(target_versions={black.TargetVersion.PY39}, line_length=88), | ||
) | ||
|
||
|
||
def test_generate_code_pipeline(): | ||
binary_pipeline = BinaryClassificationPipeline( | ||
["Imputer", "Random Forest Classifier"], | ||
) | ||
expected_code = ( | ||
expected_code = black.format_str( | ||
"from evalml.pipelines.binary_classification_pipeline import BinaryClassificationPipeline\n" | ||
"pipeline = BinaryClassificationPipeline(component_graph={'Imputer': ['Imputer', 'X', 'y'], 'Random Forest Classifier': ['Random Forest Classifier', 'Imputer.x', 'y']}, " | ||
"parameters={'Imputer':{'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'boolean_impute_strategy': 'most_frequent', 'categorical_fill_value': None, 'numeric_fill_value': None, 'boolean_fill_value': None}, " | ||
"'Random Forest Classifier':{'n_estimators': 100, 'max_depth': 6, 'n_jobs': -1}}, random_seed=0)" | ||
"'Random Forest Classifier':{'n_estimators': 100, 'max_depth': 6, 'n_jobs': -1}}, random_seed=0)", | ||
mode=black.Mode(target_versions={black.TargetVersion.PY39}, line_length=88), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's what we have in our black config. Let me see how I can clean it up! |
||
) | ||
|
||
pipeline = generate_pipeline_code(binary_pipeline) | ||
assert expected_code == pipeline | ||
|
||
regression_pipeline = RegressionPipeline( | ||
["Imputer", "Random Forest Regressor"], | ||
custom_name="Mock Regression Pipeline", | ||
) | ||
expected_code = ( | ||
expected_code = black.format_str( | ||
"from evalml.pipelines.regression_pipeline import RegressionPipeline\n" | ||
"pipeline = RegressionPipeline(component_graph={'Imputer': ['Imputer', 'X', 'y'], 'Random Forest Regressor': ['Random Forest Regressor', 'Imputer.x', 'y']}, parameters={'Imputer':{'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'boolean_impute_strategy': 'most_frequent', 'categorical_fill_value': None, 'numeric_fill_value': None, 'boolean_fill_value': None}, " | ||
"'Random Forest Regressor':{'n_estimators': 100, 'max_depth': 6, 'n_jobs': -1}}, custom_name='Mock Regression Pipeline', random_seed=0)" | ||
"'Random Forest Regressor':{'n_estimators': 100, 'max_depth': 6, 'n_jobs': -1}}, custom_name='Mock Regression Pipeline', random_seed=0)", | ||
mode=black.Mode(target_versions={black.TargetVersion.PY39}, line_length=88), | ||
) | ||
pipeline = generate_pipeline_code(regression_pipeline) | ||
assert pipeline == expected_code | ||
|
@@ -733,11 +737,12 @@ def test_generate_code_pipeline(): | |
"Random Forest Regressor": {"n_estimators": 50}, | ||
}, | ||
) | ||
expected_code_params = ( | ||
expected_code_params = black.format_str( | ||
"from evalml.pipelines.regression_pipeline import RegressionPipeline\n" | ||
"pipeline = RegressionPipeline(component_graph={'Imputer': ['Imputer', 'X', 'y'], 'Random Forest Regressor': ['Random Forest Regressor', 'Imputer.x', 'y']}, " | ||
"parameters={'Imputer':{'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'most_frequent', 'boolean_impute_strategy': 'most_frequent', 'categorical_fill_value': None, 'numeric_fill_value': None, 'boolean_fill_value': None}, " | ||
"'Random Forest Regressor':{'n_estimators': 50, 'max_depth': 6, 'n_jobs': -1}}, custom_name='Mock Regression Pipeline', random_seed=0)" | ||
"'Random Forest Regressor':{'n_estimators': 50, 'max_depth': 6, 'n_jobs': -1}}, custom_name='Mock Regression Pipeline', random_seed=0)", | ||
mode=black.Mode(target_versions={black.TargetVersion.PY39}, line_length=88), | ||
) | ||
pipeline = generate_pipeline_code(regression_pipeline_with_params) | ||
assert pipeline == expected_code_params | ||
|
@@ -762,7 +767,7 @@ def test_generate_code_nonlinear_pipeline(): | |
component_graph=component_graph, | ||
custom_name=custom_name, | ||
) | ||
expected = ( | ||
expected = black.format_str( | ||
"from evalml.pipelines.binary_classification_pipeline import BinaryClassificationPipeline\n" | ||
"pipeline = BinaryClassificationPipeline(" | ||
"component_graph={'Imputer': ['Imputer', 'X', 'y'], " | ||
|
@@ -777,7 +782,8 @@ def test_generate_code_nonlinear_pipeline(): | |
"'Random Forest':{'n_estimators': 100, 'max_depth': 6, 'n_jobs': -1}, " | ||
"'Elastic Net':{'penalty': 'elasticnet', 'C': 1.0, 'l1_ratio': 0.15, 'n_jobs': -1, 'multi_class': 'auto', 'solver': 'saga'}, " | ||
"'Logistic Regression Classifier':{'penalty': 'l2', 'C': 1.0, 'n_jobs': -1, 'multi_class': 'auto', 'solver': 'lbfgs'}}, " | ||
"custom_name='Non Linear Binary Pipeline', random_seed=0)" | ||
"custom_name='Non Linear Binary Pipeline', random_seed=0)", | ||
mode=black.Mode(target_versions={black.TargetVersion.PY39}, line_length=88), | ||
) | ||
pipeline_code = generate_pipeline_code(pipeline) | ||
assert pipeline_code == expected | ||
|
@@ -818,10 +824,11 @@ def __init__(self, random_arg=False, random_seed=0): | |
mock_pipeline_with_custom_components = BinaryClassificationPipeline( | ||
[CustomTransformer, CustomEstimator], | ||
) | ||
expected_code = ( | ||
expected_code = black.format_str( | ||
"from evalml.pipelines.binary_classification_pipeline import BinaryClassificationPipeline\n" | ||
"pipeline = BinaryClassificationPipeline(component_graph={'My Custom Transformer': [CustomTransformer, 'X', 'y'], 'My Custom Estimator': [CustomEstimator, 'My Custom Transformer.x', 'y']}, " | ||
"parameters={'My Custom Estimator':{'random_arg': False}}, random_seed=0)" | ||
"parameters={'My Custom Estimator':{'random_arg': False}}, random_seed=0)", | ||
mode=black.Mode(target_versions={black.TargetVersion.PY39}, line_length=88), | ||
) | ||
pipeline = generate_pipeline_code(mock_pipeline_with_custom_components) | ||
assert pipeline == expected_code | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed for black.