Skip to content
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

Address loading in pipeline that uses unloaded custom objective class code #113

Merged
merged 30 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1cebf6b
catch exception when user wants to access unloaded class
angela97lin Oct 3, 2019
35a83d1
linting
angela97lin Oct 3, 2019
72c4ed6
Merge branch 'master' into cloudpickle
angela97lin Oct 3, 2019
6aceee5
removing unnecessary return?
angela97lin Oct 3, 2019
7454ee2
updating exception message
angela97lin Oct 8, 2019
b518c19
Merge branch 'master' into cloudpickle
angela97lin Oct 10, 2019
161206b
Merge branch 'master' into cloudpickle
angela97lin Oct 11, 2019
1e78931
using cp
angela97lin Oct 14, 2019
ecaca19
cleanup names
angela97lin Oct 14, 2019
9a1d5cc
Merge branch 'master' into cloudpickle
angela97lin Oct 14, 2019
d4e65f7
linting
angela97lin Oct 14, 2019
0cd7343
remove pkl file
angela97lin Oct 14, 2019
cce225b
removing unnecessary pyfixture
angela97lin Oct 15, 2019
27003f4
removing import
angela97lin Oct 15, 2019
eacad82
Merge branch 'master' into cloudpickle
angela97lin Oct 17, 2019
e7a0fbd
removing path_management fixture
angela97lin Oct 17, 2019
241cc65
Merge branch 'master' into cloudpickle
angela97lin Oct 17, 2019
6058bc1
obj -> str for python 3.5
angela97lin Oct 17, 2019
6bdf75e
Merge branch 'cloudpickle' of github.com:FeatureLabs/evalml into clou…
angela97lin Oct 17, 2019
491c040
linting
angela97lin Oct 17, 2019
488859f
updating requirements.txt for cloudpickle
angela97lin Oct 17, 2019
b93b049
Merge branch 'master' into cloudpickle
angela97lin Oct 18, 2019
c11e833
checking class not loaded in beforehand
angela97lin Oct 21, 2019
83c8bd5
Merge branch 'master' into cloudpickle
angela97lin Oct 21, 2019
5c1ae8c
fixing commented out + flake8
angela97lin Oct 22, 2019
1e8540d
Merge branch 'master' into cloudpickle
angela97lin Oct 22, 2019
7fc3abe
removing unused fixture
angela97lin Oct 22, 2019
d6111dd
Merge branch 'master' into cloudpickle
angela97lin Oct 24, 2019
47d0212
Merge branch 'master' into cloudpickle
angela97lin Oct 26, 2019
d628f5c
changelog
angela97lin Oct 26, 2019
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
2 changes: 1 addition & 1 deletion evalml/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
list_model_types,
load_pipeline,
save_pipeline
)
)
6 changes: 3 additions & 3 deletions evalml/pipelines/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pickle
import cloudpickle

from .classification import (
LogisticRegressionPipeline,
Expand Down Expand Up @@ -85,7 +85,7 @@ def save_pipeline(pipeline, file_path):
None
"""
with open(file_path, 'wb') as f:
pickle.dump(pipeline, f)
cloudpickle.dump(pipeline, f)


def load_pipeline(file_path):
Expand All @@ -98,4 +98,4 @@ def load_pipeline(file_path):
Pipeline obj
"""
with open(file_path, 'rb') as f:
return pickle.load(f)
return cloudpickle.load(f)
41 changes: 22 additions & 19 deletions evalml/tests/pipeline_tests/test_pipelines.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import errno
import os
import shutil

import pandas as pd
import pytest

import evalml.tests as tests
from evalml.model_types import ModelTypes
from evalml.objectives import FraudCost, Precision
from evalml.pipelines import LogisticRegressionPipeline
Expand All @@ -17,8 +14,6 @@
)
from evalml.problem_types import ProblemTypes

CACHE = os.path.join(os.path.dirname(tests.__file__), '.cache')


def test_list_model_types():
assert set(list_model_types(ProblemTypes.BINARY)) == set([ModelTypes.RANDOM_FOREST, ModelTypes.XGBOOST, ModelTypes.LINEAR_MODEL])
Expand All @@ -33,21 +28,9 @@ def test_get_pipelines():
get_pipelines(problem_type=ProblemTypes.REGRESSION, model_types=["random_forest", "xgboost"])


@pytest.fixture
def path_management():
path = CACHE
try:
os.makedirs(path)
except OSError as e:
if e.errno != errno.EEXIST: # EEXIST corresponds to FileExistsError
raise e
yield path
shutil.rmtree(path)


def test_serialization(X_y, trained_model, path_management):
def test_serialization(X_y, tmpdir):
X, y = X_y
path = os.path.join(path_management, 'pipe.pkl')
path = os.path.join(tmpdir, 'pipe.pkl')
objective = Precision()

pipeline = LogisticRegressionPipeline(objective=objective, penalty='l2', C=1.0, impute_strategy='mean', number_features=len(X[0]))
Expand All @@ -56,6 +39,26 @@ def test_serialization(X_y, trained_model, path_management):
assert pipeline.score(X, y) == load_pipeline(path).score(X, y)


@pytest.fixture
def pickled_pipeline_path(X_y, tmpdir):
X, y = X_y
path = os.path.join(tmpdir, 'pickled_pipe.pkl')
MockPrecision = type('MockPrecision', (Precision,), {})
objective = MockPrecision()
pipeline = LogisticRegressionPipeline(objective=objective, penalty='l2', C=1.0, impute_strategy='mean', number_features=len(X[0]))
pipeline.fit(X, y)
save_pipeline(pipeline, path)
return path


def test_load_pickled_pipeline_with_custom_objective(X_y, pickled_pipeline_path):
X, y = X_y
objective = Precision()
pipeline = LogisticRegressionPipeline(objective=objective, penalty='l2', C=1.0, impute_strategy='mean', number_features=len(X[0]))
pipeline.fit(X, y)
assert load_pipeline(pickled_pipeline_path).score(X, y) == pipeline.score(X, y)


def test_reproducibility(X_y):
X, y = X_y
X = pd.DataFrame(X)
Expand Down
2 changes: 1 addition & 1 deletion evalml/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# flake8:noqa
from .logging_utils import Logger
from .convert_time import convert_to_seconds
from .convert_time import convert_to_seconds