Skip to content

Commit

Permalink
BUG: Warn rather than print
Browse files Browse the repository at this point in the history
Warn users abotu convergence rather than priting a message

closes statsmodels#3794
  • Loading branch information
bashtage committed Jun 8, 2019
1 parent 39d2fcb commit e348d5b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions statsmodels/base/l1_solvers_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
Holds common functions for l1 solvers.
"""
from __future__ import print_function

import numpy as np

from statsmodels.compat.python import range
from statsmodels.tools.sm_exceptions import ConvergenceWarning


def qc_results(params, alpha, score, qc_tol, qc_verbose=False):
Expand Down Expand Up @@ -65,7 +68,9 @@ def qc_results(params, alpha, score, qc_tol, qc_verbose=False):
', decreasing alpha, or switch solvers'
if qc_verbose:
message += _get_verbose_addon(qc_dict)
print(message)

import warnings
warnings.warn(message, ConvergenceWarning)

return passed

Expand Down Expand Up @@ -135,8 +140,10 @@ def do_trim_params(params, k_params, alpha, score, passed, trim_mode,
if trim_mode == 'off':
trimmed = np.array([False] * k_params)
elif trim_mode == 'auto' and not passed:
print("Could not trim params automatically due to failed QC "
"check. Trimming using trim_mode == 'size' will still work.")
import warnings
msg = "Could not trim params automatically due to failed QC check. " \
"Trimming using trim_mode == 'size' will still work."
warnings.warn(msg, ConvergenceWarning)
trimmed = np.array([False] * k_params)
elif trim_mode == 'auto' and passed:
fprime = score(params)
Expand Down

0 comments on commit e348d5b

Please sign in to comment.