From 98dfc007363c3850907d59b1d85d9d5743c35590 Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Sun, 23 Aug 2020 23:56:54 +0100 Subject: [PATCH] MAINT: Remove print statements Remove extraneous print statements closes #6981 --- statsmodels/base/model.py | 1 - .../discrete/tests/test_constrained.py | 7 +-- statsmodels/nonparametric/kde.py | 46 ------------------- statsmodels/nonparametric/smoothers_lowess.py | 3 -- .../nonparametric/tests/test_kernels.py | 11 ----- statsmodels/stats/_adnorm.py | 15 ------ statsmodels/stats/descriptivestats.py | 1 - statsmodels/stats/multivariate.py | 1 - statsmodels/tools/rootfinding.py | 7 --- 9 files changed, 2 insertions(+), 90 deletions(-) diff --git a/statsmodels/base/model.py b/statsmodels/base/model.py index 64ab02ed264..8d0328b471d 100644 --- a/statsmodels/base/model.py +++ b/statsmodels/base/model.py @@ -2383,7 +2383,6 @@ def bootstrap(self, nrep=100, method='nm', disp=0, store=1): distributed observations. """ results = [] - print(self.model.__class__) hascloneattr = True if hasattr(self.model, 'cloneattr') else False for i in range(nrep): rvsind = np.random.randint(self.nobs, size=self.nobs) diff --git a/statsmodels/discrete/tests/test_constrained.py b/statsmodels/discrete/tests/test_constrained.py index 7f0f5c4cae8..1c8b2f20a68 100644 --- a/statsmodels/discrete/tests/test_constrained.py +++ b/statsmodels/discrete/tests/test_constrained.py @@ -553,12 +553,9 @@ def junk(): # FIXME: make this into a test, or move/remove # example without offset formula1a = 'deaths ~ logpyears + smokes + C(agecat)' mod1a = Poisson.from_formula(formula1a, data=data) - print(mod1a.exog.shape) mod1a.fit() lc_1a = patsy.DesignInfo(mod1a.exog_names).linear_constraint( 'C(agecat)[T.4] = C(agecat)[T.5]') - resc1a = mod1a.fit_constrained(lc_1a.coefs, lc_1a.constants, - fit_kwds={'method': 'newton'}) - print(resc1a[0]) - print(resc1a[1]) + mod1a.fit_constrained(lc_1a.coefs, lc_1a.constants, + fit_kwds={'method': 'newton'}) diff --git a/statsmodels/nonparametric/kde.py b/statsmodels/nonparametric/kde.py index a344dad7f84..12da35f7455 100644 --- a/statsmodels/nonparametric/kde.py +++ b/statsmodels/nonparametric/kde.py @@ -498,49 +498,3 @@ def kdensityfft(X, kernel="gau", bw="normal_reference", weights=None, gridsize=N return f, grid, bw else: return f, bw - -if __name__ == "__main__": - import numpy as np - np.random.seed(12345) - xi = np.random.randn(100) - f,grid, bw1 = kdensity(xi, kernel="gau", bw=.372735, retgrid=True) - f2, bw2 = kdensityfft(xi, kernel="gau", bw="silverman",retgrid=False) - -# do some checking vs. silverman algo. -# you need denes.f, http://lib.stat.cmu.edu/apstat/176 -#NOTE: I (SS) made some changes to the Fortran -# and the FFT stuff from Munro http://lib.stat.cmu.edu/apstat/97o -# then compile everything and link to denest with f2py -#Make pyf file as usual, then compile shared object -#f2py denest.f -m denest2 -h denest.pyf -#edit pyf -#-c flag makes it available to other programs, fPIC builds a shared library -#/usr/bin/gfortran -Wall -c -fPIC fft.f -#f2py -c denest.pyf ./fft.o denest.f - - try: - from denest2 import denest # @UnresolvedImport - a = -3.4884382032045504 - b = 4.3671504686785605 - RANGE = b - a - bw = bandwidths.bw_silverman(xi) - - ft,smooth,ifault,weights,smooth1 = denest(xi,a,b,bw,np.zeros(512),np.zeros(512),0, - np.zeros(512), np.zeros(512)) -# We use a different binning algo, so only accurate up to 3 decimal places - np.testing.assert_almost_equal(f2, smooth, 3) -#NOTE: for debugging -# y2 = forrt(weights) -# RJ = np.arange(512/2+1) -# FAC1 = 2*(np.pi*bw/RANGE)**2 -# RJFAC = RJ**2*FAC1 -# BC = 1 - RJFAC/(6*(bw/((b-a)/M))**2) -# FAC = np.exp(-RJFAC)/BC -# SMOOTH = np.r_[FAC,FAC[1:-1]] * y2 - -# dens = revrt(SMOOTH) - - except: -# ft = np.loadtxt('./ft_silver.csv') -# smooth = np.loadtxt('./smooth_silver.csv') - print("Did not get the estimates from the Silverman algorithm") diff --git a/statsmodels/nonparametric/smoothers_lowess.py b/statsmodels/nonparametric/smoothers_lowess.py index 1e0bf9907e5..c1b53590bdc 100644 --- a/statsmodels/nonparametric/smoothers_lowess.py +++ b/statsmodels/nonparametric/smoothers_lowess.py @@ -211,14 +211,12 @@ def lowess(endog, exog, frac=2.0/3.0, it=3, delta=0.0, xvals=None, is_sorted=Fal if not given_xvals: # Run LOWESS on the data points - print("Not giving xvalues") res, _ = _lowess(y, x, x, np.ones_like(x), frac=frac, it=it, delta=delta, given_xvals=False) else: # First run LOWESS on the data points to get the weights of the data points # using it-1 iterations, last iter done next if it > 0: - print("Not giving xvalues") _, weights = _lowess(y, x, x, np.ones_like(x), frac=frac, it=it-1, delta=delta, given_xvals=False) else: @@ -226,7 +224,6 @@ def lowess(endog, exog, frac=2.0/3.0, it=3, delta=0.0, xvals=None, is_sorted=Fal # Then run once more using those supplied weights at the points provided by xvals # No extra iterations are performed here since weights are fixed - print("giving xvalues") res, _ = _lowess(y, x, xvalues, weights, frac=frac, it=0, delta=delta, given_xvals=True) diff --git a/statsmodels/nonparametric/tests/test_kernels.py b/statsmodels/nonparametric/tests/test_kernels.py index 774ddf148c6..6eac0d5d4d4 100644 --- a/statsmodels/nonparametric/tests/test_kernels.py +++ b/statsmodels/nonparametric/tests/test_kernels.py @@ -85,19 +85,10 @@ def test_smoothconf(self): se_n_diff = self.se_n_diff assert_array_less(mask.sum(), se_n_diff + 1) # at most 5 large diffs - if DEBUG: - # raises: RuntimeWarning: invalid value encountered in divide - print(fitted / res_fitted - 1) - print(se / res_se - 1) # Stata only displays ci, does not save it res_upp = res_fitted + crit * res_se res_low = res_fitted - crit * res_se self.res_fittedg = np.column_stack((res_low, res_fitted, res_upp)) - if DEBUG: - print(fittedg[:, 2] / res_upp - 1) - print(fittedg[:, 2] - res_upp) - print(fittedg[:, 0] - res_low) - print(np.max(np.abs(fittedg[:, 2] / res_upp - 1))) assert_allclose(fittedg[se_valid, 2], res_upp[se_valid], rtol=self.upp_rtol, atol=0.2) assert_allclose(fittedg[se_valid, 0], res_low[se_valid], @@ -112,8 +103,6 @@ def test_smoothconf_data(self): crit = 1.9599639845400545 # norm.isf(0.05 / 2) # no reference results saved to csv yet fitted_x = np.array([kern.smoothconf(x, y, xi) for xi in x]) - if DEBUG: - print(fitted_x[:, 2] - fitted_x[:, 1]) / crit class TestEpan(CheckKernelMixin): diff --git a/statsmodels/stats/_adnorm.py b/statsmodels/stats/_adnorm.py index 917c70c13e1..d008faaf96a 100644 --- a/statsmodels/stats/_adnorm.py +++ b/statsmodels/stats/_adnorm.py @@ -137,18 +137,3 @@ def normal_ad(x, axis=0): pval[mask] = pvalli[i](ad2a[mask]) return ad2, pval - - -if __name__ == '__main__': - x = np.array([-0.1184, -1.3403, 0.0063, -0.612, -0.3869, -0.2313, - -2.8485, -0.2167, 0.4153, 1.8492, -0.3706, 0.9726, - -0.1501, -0.0337, -1.4423, 1.2489, 0.9182, -0.2331, - -0.6182, 0.1830]) - r_res = np.array([0.58672353588821502, 0.1115380760041617]) - ad2, pval = normal_ad(x) - print(ad2, pval) - print(r_res - [ad2, pval]) - - print(anderson_statistic((x - x.mean()) / x.std(), dist=stats.norm, - fit=False)) - print(anderson_statistic(x, dist=stats.norm, fit=True)) diff --git a/statsmodels/stats/descriptivestats.py b/statsmodels/stats/descriptivestats.py index d03456f494f..96d455ca182 100644 --- a/statsmodels/stats/descriptivestats.py +++ b/statsmodels/stats/descriptivestats.py @@ -499,7 +499,6 @@ def _mode(ser): while dupe: scale *= 10 idx = np.floor(scale * perc.index) - print(np.diff(idx)) if np.all(np.diff(idx) > 0): dupe = False index = np.floor(scale * index) / (scale / 100) diff --git a/statsmodels/stats/multivariate.py b/statsmodels/stats/multivariate.py index 97dc27a5628..df178e14e77 100644 --- a/statsmodels/stats/multivariate.py +++ b/statsmodels/stats/multivariate.py @@ -579,7 +579,6 @@ def test_cov_oneway(cov_list, nobs_list): else: tmp = b2 * stat0 statistic_f = a2 / a1 * tmp / (1 + tmp) - print("in branch 2") df_f = (a1, a2) pvalue_f = stats.f.sf(statistic_f, *df_f) return HolderTuple(statistic=statistic_f, # name convention, using F here diff --git a/statsmodels/tools/rootfinding.py b/statsmodels/tools/rootfinding.py index 7a26f2dd8f2..1f226ee9d2b 100644 --- a/statsmodels/tools/rootfinding.py +++ b/statsmodels/tools/rootfinding.py @@ -130,8 +130,6 @@ def brentq_expanding(func, low=None, upp=None, args=(), xtol=1e-5, sl = 1e-8 f_low = func(sl, *args) increasing = (f_low < f_upp) - if DEBUG: - print('symm', sl, su, f_low, f_upp) # possibly func returns nan delta = su - sl @@ -162,11 +160,6 @@ def brentq_expanding(func, low=None, upp=None, args=(), xtol=1e-5, increasing = (f_low < f_upp) - if DEBUG: - print('low, upp', low, upp, func(sl, *args), func(su, *args)) - print('increasing', increasing) - print('sl, su', sl, su) - if not increasing: sl, su = su, sl left, right = right, left