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

Raise all warnings in _catch_warnings #2765

Merged
merged 12 commits into from
Sep 13, 2021
1 change: 1 addition & 0 deletions docs/source/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Release Notes
**Future Releases**
* Enhancements
* Fixes
* Fixed bug where warnings during ``make_pipeline`` were not being raised to the user :pr:`2765`
* Changes
* Testing Changes

Expand Down
35 changes: 22 additions & 13 deletions evalml/automl/automl_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def __init__(
self.random_seed = random_seed
self.n_jobs = n_jobs

if not self.plot:
if not self.plot and self.verbose:
self.logger.warning(
"Unable to import plotly; skipping pipeline search plotting\n"
)
Expand Down Expand Up @@ -847,19 +847,28 @@ def close_engine(self):
self._engine.close()

def _catch_warnings(self, warning_list):
if len(warning_list) == len(self.allowed_pipelines) and len(warning_list) > 0:
# we find the value(s) that we must throw any ParameterNotUsedWarnings for
parameter_not_used_warnings = []
raised_messages = []
for msg in warning_list:
if isinstance(msg.message, ParameterNotUsedWarning):
parameter_not_used_warnings.append(msg.message)
# Raise non-PNU warnings immediately, but only once per warning
elif str(msg.message) not in raised_messages:
warnings.warn(msg.message)
raised_messages.append(str(msg.message))

# Raise PNU warnings, iff the warning was raised in every pipeline
if len(parameter_not_used_warnings) == len(self.allowed_pipelines) and len(
parameter_not_used_warnings
):
final_message = set([])
for idx, msg in enumerate(warning_list):
if isinstance(msg.message, ParameterNotUsedWarning):
if idx == 0:
final_message = final_message.union(msg.message.components)
else:
final_message = final_message.intersection(
msg.message.components
)
if len(final_message):
warnings.warn(ParameterNotUsedWarning(final_message))
for msg in parameter_not_used_warnings:
if len(final_message) == 0:
final_message = final_message.union(msg.components)
else:
final_message = final_message.intersection(msg.components)

warnings.warn(ParameterNotUsedWarning(final_message))

def _get_batch_number(self):
batch_number = 1
Expand Down
20 changes: 20 additions & 0 deletions evalml/tests/automl_tests/test_automl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5102,6 +5102,26 @@ def test_pipeline_parameter_warnings_only_parameternotused(
assert str(warning) == "Big bad warning"


@pytest.mark.parametrize("verbose", [True, False])
def test_pipeline_parameter_warnings_with_other_types(verbose):
# Data that will trigger a UserWarning from `TargetLeakageDataCheck`
X = pd.DataFrame({"a": [1, 2, 2, 1, 2, 1, 2, 2, 1, 1] * 505})
y = [0.946, 0.972, 1.154, 0.954, 0.969, 1.222, 1.038, 0.999, 0.973, 0.897] * 505

with pytest.warns(None) as w:
AutoMLSearch(
X_train=X,
y_train=y,
problem_type="regression",
allowed_model_families=["random_forest", "linear_model"],
bchen1116 marked this conversation as resolved.
Show resolved Hide resolved
pipeline_parameters={"Decision Tree Classifier": {"max_depth": 1}},
verbose=verbose,
)
assert len(w) == 2
assert isinstance(w[0].message, UserWarning)
assert isinstance(w[1].message, ParameterNotUsedWarning)


bchen1116 marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.parametrize("nans", [None, pd.NA, np.nan])
@patch("evalml.pipelines.components.Estimator.fit")
@patch(
Expand Down