From 1ebf2b58afe8d411f1814dfd1919838c490f308e Mon Sep 17 00:00:00 2001 From: dswah Date: Fri, 26 Oct 2018 17:04:33 +0200 Subject: [PATCH 1/2] use catch_warnings context to ignore warnings --- pygam/utils.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/pygam/utils.py b/pygam/utils.py index b437c23f..e360fb63 100644 --- a/pygam/utils.py +++ b/pygam/utils.py @@ -218,16 +218,13 @@ def check_y(y, link, dist, min_samples=1, verbose=True): y = check_array(y, force_2d=False, min_samples=min_samples, ndim=1, name='y data', verbose=verbose) - warnings.filterwarnings('ignore', 'divide by zero encountered in log') - warnings.filterwarnings('ignore', 'invalid value encountered in log') - if np.any(np.isnan(link.link(y, dist))): - raise ValueError('y data is not in domain of {} link function. ' \ - 'Expected domain: {}, but found {}' \ - .format(link, get_link_domain(link, dist), - [float('%.2f'%np.min(y)), - float('%.2f'%np.max(y))])) - warnings.resetwarnings() - + with warnings.catch_warnings(): + if np.any(np.isnan(link.link(y, dist))): + raise ValueError('y data is not in domain of {} link function. ' \ + 'Expected domain: {}, but found {}' \ + .format(link, get_link_domain(link, dist), + [float('%.2f'%np.min(y)), + float('%.2f'%np.max(y))])) return y def check_X(X, n_feats=None, min_samples=1, edge_knots=None, dtypes=None, From 9abdc2dff3f1f01bb5239c17d91462ce3150ce28 Mon Sep 17 00:00:00 2001 From: dswah Date: Fri, 26 Oct 2018 17:09:07 +0200 Subject: [PATCH 2/2] then filter ignored warnings --- pygam/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pygam/utils.py b/pygam/utils.py index e360fb63..4f3745dc 100644 --- a/pygam/utils.py +++ b/pygam/utils.py @@ -219,6 +219,8 @@ def check_y(y, link, dist, min_samples=1, verbose=True): name='y data', verbose=verbose) with warnings.catch_warnings(): + warnings.simplefilter("ignore") + if np.any(np.isnan(link.link(y, dist))): raise ValueError('y data is not in domain of {} link function. ' \ 'Expected domain: {}, but found {}' \