Skip to content

Commit

Permalink
Add a DeprecationWarning about deprecating the list API for Component…
Browse files Browse the repository at this point in the history
…Graphs (#2488)


* filter warnings unless for pipeline init
  • Loading branch information
angela97lin committed Jul 9, 2021
1 parent f5b37b4 commit bd6bae6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/source/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Release Notes
* Added custom exception message for partial dependence on features with scales that are too small :pr:`2455`
* Updated to work with Pandas 1.3.0 :pr:`2442`
* Changes
* Added a ``DeprecationWarning`` about deprecating the list API for ``ComponentGraph`` :pr:`2488`
* Documentation Changes
* Moved docstrings from ``__init__`` to class pages, added missing docstrings for missing classes, and updated missing default values :pr:`2452`
* Testing Changes
Expand Down
6 changes: 6 additions & 0 deletions evalml/pipelines/component_graph.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import networkx as nx
import pandas as pd
import woodwork as ww
Expand Down Expand Up @@ -101,6 +103,10 @@ def from_list(cls, component_list, random_seed=0):
component_list (list): String names or ComponentBase subclasses in
an order that represents a valid linear graph
"""
warnings.warn(
"ComponentGraph.from_list will be deprecated in the next release. Please use a dictionary to specify your graph instead.",
DeprecationWarning,
)
component_dict = {}
previous_component = None

Expand Down
12 changes: 9 additions & 3 deletions evalml/pipelines/pipeline_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import traceback
import warnings
from abc import ABC, abstractmethod
from collections import OrderedDict

Expand Down Expand Up @@ -66,9 +67,14 @@ def __init__(
self.random_seed = random_seed

if isinstance(component_graph, list): # Backwards compatibility
self.component_graph = ComponentGraph().from_list(
component_graph, random_seed=self.random_seed
)
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
message="ComponentGraph.from_list will be deprecated in the next release. Please use a dictionary to specify your graph instead.",
)
self.component_graph = ComponentGraph().from_list(
component_graph, random_seed=self.random_seed
)
elif isinstance(component_graph, dict):
self.component_graph = ComponentGraph(
component_dict=component_graph, random_seed=self.random_seed
Expand Down
11 changes: 11 additions & 0 deletions evalml/tests/pipeline_tests/test_component_graph.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from datetime import datetime, timedelta
from unittest.mock import patch

Expand Down Expand Up @@ -289,6 +290,16 @@ def test_from_list_repeat_component():
assert component_graph.get_component("One Hot Encoder_2").parameters["top_n"] == 11


def test_component_graph_from_list_deprecation_warning():
component_list = ["Imputer", "One Hot Encoder", RandomForestClassifier]
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
ComponentGraph.from_list(component_list)
assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
assert "deprecated" in str(w[-1].message)


def test_instantiate_with_parameters(example_graph):
graph = example_graph
component_graph = ComponentGraph(graph)
Expand Down

0 comments on commit bd6bae6

Please sign in to comment.