Skip to content

Commit bb8fba9

Browse files
committed
Replace WarningManager with catch_warnings
Used np.vectorize to strip the excess string identfiers and switch from string check to integer check for counts. Replaced rec.array with pd.DataFrame... life is easier.
1 parent a222cec commit bb8fba9

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

statsmodels/formula/tests/test_formula.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import numpy.testing as npt
1010
from statsmodels.tools.testing import assert_equal
11-
from numpy.testing.utils import WarningManager
1211

1312

1413
longley_formula = 'TOTEMP ~ GNPDEFL + GNP + UNEMP + ARMED + POP + YEAR'
@@ -34,14 +33,10 @@ def test_endog(self):
3433

3534
def test_summary(self):
3635
# smoke test
37-
warn_ctx = WarningManager()
38-
warn_ctx.__enter__()
39-
try:
36+
with warnings.catch_warnings():
4037
warnings.filterwarnings("ignore",
4138
"kurtosistest only valid for n>=20")
4239
self.model.fit().summary()
43-
finally:
44-
warn_ctx.__exit__()
4540

4641

4742
class TestFormulaPandas(CheckFormulaOLS):

statsmodels/genmod/tests/results/results_glm.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,9 @@ def __init__(self):
684684
# data set up for data not in datasets
685685
filename = os.path.join(os.path.dirname(os.path.abspath(__file__)),
686686
"stata_lbw_glm.csv")
687-
data=np.recfromcsv(open(filename, 'rb'), converters={4: lambda s: s.strip(asbytes("\""))})
687+
data=np.recfromcsv(open(filename, 'rb'))
688+
vfunc = np.vectorize(lambda x: x.strip(asbytes("\"")))
689+
data['race'] = vfunc(data['race'])
688690
data = categorical(data, col='race', drop=True)
689691
self.endog = data.low
690692
design = np.column_stack((data['age'], data['lwt'],
@@ -2191,7 +2193,9 @@ class Medpar1(object):
21912193
def __init__(self):
21922194
filename = os.path.join(os.path.dirname(os.path.abspath(__file__)),
21932195
"stata_medpar1_glm.csv")
2194-
data = np.recfromcsv(open(filename, 'rb'), converters ={1: lambda s: s.strip(asbytes("\""))})
2196+
data = np.recfromcsv(open(filename, 'rb'))
2197+
vfunc = np.vectorize(lambda x: x.strip(asbytes('\"')))
2198+
data['admitype'] = vfunc(data['admitype'])
21952199
self.endog = data.los
21962200
design = np.column_stack((data.admitype, data.codes))
21972201
design = categorical(design, col=0, drop=True)

statsmodels/stats/tests/test_contingency_tables.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def test_SquareTable_from_data():
6161
rslt3.summary().as_text())
6262

6363
s = str(rslt1)
64-
assert_equal(s.startswith('A 5x5 contingency table with counts:\n[[ 8.'), True)
64+
assert_equal(s.startswith('A 5x5 contingency table with counts:'), True)
65+
assert_equal(rslt1.table[0, 0], 8.)
6566

6667

6768
def test_SquareTable_nonsquare():

statsmodels/tsa/tests/test_stattools.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
coint, acovf, kpss, ResultsStore,
88
arma_order_select_ic)
99
import numpy as np
10+
import pandas as pd
1011
from numpy.testing import (assert_almost_equal, assert_equal, assert_warns,
1112
assert_raises, dec, assert_, assert_allclose)
12-
from numpy import genfromtxt
1313
from statsmodels.datasets import macrodata, sunspots
1414
from pandas import Series, DatetimeIndex, DataFrame
1515
import os
@@ -130,7 +130,7 @@ class CheckCorrGram(object):
130130
x = data.data['realgdp']
131131
filename = os.path.dirname(os.path.abspath(__file__))+\
132132
"/results/results_corrgram.csv"
133-
results = genfromtxt(open(filename, "rb"), delimiter=",", names=True,dtype=float)
133+
results = pd.read_csv(filename, delimiter=',')
134134

135135
#not needed: add 1. for lag zero
136136
#self.results['acvar'] = np.concatenate(([1.], self.results['acvar']))
@@ -146,8 +146,8 @@ def setup_class(cls):
146146
#cls.acf = np.concatenate(([1.], cls.acf))
147147
cls.qstat = cls.results['Q1']
148148
cls.res1 = acf(cls.x, nlags=40, qstat=True, alpha=.05)
149-
cls.confint_res = cls.results[['acvar_lb','acvar_ub']].view((float,
150-
2))
149+
cls.confint_res = cls.results[['acvar_lb','acvar_ub']].as_matrix()
150+
151151
def test_acf(self):
152152
assert_almost_equal(self.res1[0][1:41], self.acf, DECIMAL_8)
153153

0 commit comments

Comments
 (0)