Skip to content

Commit 75f857d

Browse files
committed
COMPAT: Use consistent import location for pandas testing
Add pandas testing to compat
1 parent a08d4f6 commit 75f857d

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

statsmodels/base/tests/test_generic_methods.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1111
Author: Josef Perktold
1212
"""
13+
from statsmodels.compat.pandas import assert_series_equal, assert_index_equal
1314
from statsmodels.compat.python import range
1415

1516
import numpy as np
@@ -660,12 +661,6 @@ def test_predict_missing(self):
660661
ex.iloc[0, 1] = np.nan
661662
predicted1 = self.res.predict(ex)
662663
predicted2 = self.res.predict(ex[1:])
663-
from pandas.util.testing import assert_series_equal
664-
try:
665-
from pandas.util.testing import assert_index_equal
666-
except ImportError:
667-
# for old pandas
668-
from numpy.testing import assert_array_equal as assert_index_equal
669664

670665
assert_index_equal(predicted1.index, ex.index)
671666
assert_series_equal(predicted1[1:], predicted2)

statsmodels/base/tests/test_predict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"""
33
Tests for Results.predict
44
"""
5+
from statsmodels.compat.pandas import testing as pdt
56

67
import numpy as np
78
import pandas as pd
89

910
from numpy.testing import assert_allclose, assert_equal
10-
import pandas.util.testing as pdt
1111

1212
from statsmodels.regression.linear_model import OLS
1313
from statsmodels.genmod.generalized_linear_model import GLM

statsmodels/compat/pandas.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@ def sort_values(df, *args, **kwargs):
2929

3030
data_klasses = (pandas.Series, pandas.DataFrame, pandas.Panel,
3131
pandas.WidePanel)
32+
33+
try:
34+
import pandas.testing as testing
35+
except ImportError:
36+
import pandas.util.testing as testing
37+
38+
assert_frame_equal = testing.assert_frame_equal
39+
assert_index_equal = testing.assert_index_equal
40+
assert_series_equal = testing.assert_series_equal

statsmodels/stats/tests/test_influence.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
44
55
Author: Josef Perktold
66
"""
7+
from statsmodels.compat.pandas import testing as pdt
78

89
import os.path
910
import numpy as np
1011
from numpy.testing import assert_allclose
1112
import pandas as pd
12-
try:
13-
import pandas.testing as pdt
14-
except ImportError:
15-
import pandas.util.testing as pdt
1613

1714
import pytest
1815

statsmodels/tools/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""assert functions from numpy and pandas testing
22
33
"""
4+
from statsmodels.compat.pandas import testing as pdt
45

56
import re
67

78
import numpy.testing as npt
89
import pandas
9-
import pandas.util.testing as pdt
1010

1111
# for pandas version check
1212
def strip_rc(version):

statsmodels/tsa/tests/test_stattools.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from statsmodels.compat.pandas import assert_index_equal
12
from statsmodels.compat.python import lrange
23

34
import os
@@ -752,35 +753,34 @@ def test_innovations_errors():
752753
def test_innovations_filter_brockwell_davis():
753754
ma = -0.9
754755
acovf = np.array([1 + ma ** 2, ma])
755-
theta, sigma2 = innovations_algo(acovf, nobs=4)
756+
theta, _ = innovations_algo(acovf, nobs=4)
756757
e = np.random.randn(5)
757758
endog = e[1:] + ma * e[:-1]
758759
resid = innovations_filter(endog, theta)
759760
expected = [endog[0]]
760761
for i in range(1, 4):
761762
expected.append(endog[i] + theta[i, 0] * expected[-1])
762-
print(expected)
763763
expected = np.array(expected)
764764
assert_allclose(resid, expected)
765765

766766

767767
def test_innovations_filter_pandas():
768768
ma = np.array([-0.9, 0.5])
769769
acovf = np.array([1 + (ma ** 2).sum(), ma[0] + ma[1] * ma[0], ma[1]])
770-
theta, sigma2 = innovations_algo(acovf, nobs=10)
770+
theta, _ = innovations_algo(acovf, nobs=10)
771771
endog = np.random.randn(10)
772772
endog_pd = pd.Series(endog,
773773
index=pd.date_range('2000-01-01', periods=10))
774774
resid = innovations_filter(endog, theta)
775775
resid_pd = innovations_filter(endog_pd, theta)
776776
assert_allclose(resid, resid_pd.values)
777-
pd.testing.assert_index_equal(endog_pd.index, resid_pd.index)
777+
assert_index_equal(endog_pd.index, resid_pd.index)
778778

779779

780780
def test_innovations_filter_errors():
781781
ma = -0.9
782782
acovf = np.array([1 + ma ** 2, ma])
783-
theta, sigma2 = innovations_algo(acovf, nobs=4)
783+
theta, _ = innovations_algo(acovf, nobs=4)
784784
with pytest.raises(ValueError):
785785
innovations_filter(np.empty((2, 2)), theta)
786786
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)