gnu: python-statsmodels: Fix tests.
[jackhill/guix/guix.git] / gnu / packages / patches / python-statsmodels-fix-tests.patch
1 This patch fixes a couple of test failures introduced by changes to the pandas
2 package. It was extracted from this pull request:
3
4 https://github.com/statsmodels/statsmodels/pull/2675
5
6
7 From c9ef60a7bc4407766ab9e9f12c8a6b89013046ee Mon Sep 17 00:00:00 2001
8 From: Ralf Gommers <ralf.gommers@gmail.com>
9 Date: Tue, 20 Oct 2015 07:34:11 +0200
10 Subject: [PATCH 1/4] MAINT: fix use of old_behavior kw for numpy.correlate.
11 Was removed in 1.10.0
12
13 Numpy PR that removed it: https://github.com/numpy/numpy/pull/5991
14
15 Closes gh-2667.
16 ---
17 statsmodels/tsa/ar_model.py | 6 ++----
18 1 file changed, 2 insertions(+), 4 deletions(-)
19
20 diff --git a/statsmodels/tsa/ar_model.py b/statsmodels/tsa/ar_model.py
21 index 087a9e0..02984bd 100644
22 --- a/statsmodels/tsa/ar_model.py
23 +++ b/statsmodels/tsa/ar_model.py
24 @@ -261,10 +261,8 @@ def _presample_varcov(self, params):
25
26 Vpinv = np.zeros((p, p), dtype=params.dtype)
27 for i in range(1, p1):
28 - Vpinv[i-1, i-1:] = np.correlate(params0, params0[:i],
29 - old_behavior=False)[:-1]
30 - Vpinv[i-1, i-1:] -= np.correlate(params0[-i:], params0,
31 - old_behavior=False)[:-1]
32 + Vpinv[i-1, i-1:] = np.correlate(params0, params0[:i],)[:-1]
33 + Vpinv[i-1, i-1:] -= np.correlate(params0[-i:], params0,)[:-1]
34
35 Vpinv = Vpinv + Vpinv.T - np.diag(Vpinv.diagonal())
36 return Vpinv
37
38 From f1dc8979b09bc1736149993f895943b3158ee2db Mon Sep 17 00:00:00 2001
39 From: Ralf Gommers <ralf.gommers@gmail.com>
40 Date: Wed, 21 Oct 2015 22:05:52 +0200
41 Subject: [PATCH 2/4] MAINT: fix graphics module for changes in recent pandas
42 versions.
43
44 ---
45 statsmodels/graphics/tests/test_mosaicplot.py | 2 +-
46 statsmodels/graphics/tests/test_tsaplots.py | 6 +++---
47 statsmodels/graphics/tsaplots.py | 2 +-
48 3 files changed, 5 insertions(+), 5 deletions(-)
49
50 diff --git a/statsmodels/graphics/tests/test_mosaicplot.py b/statsmodels/graphics/tests/test_mosaicplot.py
51 index cb9bbbe..e41020e 100644
52 --- a/statsmodels/graphics/tests/test_mosaicplot.py
53 +++ b/statsmodels/graphics/tests/test_mosaicplot.py
54 @@ -113,7 +113,7 @@ def test_mosaic():
55 # sort by the marriage quality and give meaningful name
56 # [rate_marriage, age, yrs_married, children,
57 # religious, educ, occupation, occupation_husb]
58 - datas = datas.sort(['rate_marriage', 'religious'])
59 + datas = datas.sort_values(by=['rate_marriage', 'religious'])
60 num_to_desc = {1: 'awful', 2: 'bad', 3: 'intermediate',
61 4: 'good', 5: 'wonderful'}
62 datas['rate_marriage'] = datas['rate_marriage'].map(num_to_desc)
63 diff --git a/statsmodels/graphics/tests/test_tsaplots.py b/statsmodels/graphics/tests/test_tsaplots.py
64 index 511f18f..365be82 100644
65 --- a/statsmodels/graphics/tests/test_tsaplots.py
66 +++ b/statsmodels/graphics/tests/test_tsaplots.py
67 @@ -1,4 +1,4 @@
68 -from statsmodels.compat.python import lmap, lzip, map
69 +from statsmodels.compat.python import lmap, map
70 import numpy as np
71 import pandas as pd
72 from numpy.testing import dec
73 @@ -51,8 +51,8 @@ def test_plot_month():
74 dta = sm.datasets.elnino.load_pandas().data
75 dta['YEAR'] = dta.YEAR.astype(int).apply(str)
76 dta = dta.set_index('YEAR').T.unstack()
77 - dates = lmap(lambda x : pd.datetools.parse('1 '+' '.join(x)),
78 - dta.index.values)
79 + dates = lmap(lambda x : pd.datetools.parse_time_string('1 '+' '.join(x))[0],
80 + dta.index.values)
81
82 # test dates argument
83 fig = month_plot(dta.values, dates=dates, ylabel='el nino')
84 diff --git a/statsmodels/graphics/tsaplots.py b/statsmodels/graphics/tsaplots.py
85 index 3d04692..94626c9 100644
86 --- a/statsmodels/graphics/tsaplots.py
87 +++ b/statsmodels/graphics/tsaplots.py
88 @@ -200,7 +200,7 @@ def seasonal_plot(grouped_x, xticklabels, ylabel=None, ax=None):
89 ticks = []
90 for season, df in grouped_x:
91 df = df.copy() # or sort balks for series. may be better way
92 - df.sort()
93 + df.sort_values(inplace=True)
94 nobs = len(df)
95 x_plot = np.arange(start, start + nobs)
96 ticks.append(x_plot.mean())
97
98 From 4cfbef6af137629c6953f1f025d9cfc781874256 Mon Sep 17 00:00:00 2001
99 From: Ralf Gommers <ralf.gommers@gmail.com>
100 Date: Wed, 21 Oct 2015 22:15:25 +0200
101 Subject: [PATCH 3/4] MAINT: work around pandas breaking backwards compat for
102 pandas.version
103
104 ---
105 setup.py | 5 ++++-
106 statsmodels/tools/testing.py | 6 ++----
107 2 files changed, 6 insertions(+), 5 deletions(-)
108
109 diff --git a/setup.py b/setup.py
110 index 0002840..74aefb8 100644
111 --- a/setup.py
112 +++ b/setup.py
113 @@ -134,7 +134,10 @@ def check_dependency_versions(min_versions):
114 (spversion, min_versions['scipy']))
115
116 try:
117 - from pandas.version import short_version as pversion
118 + import pandas
119 + #FIXME: this will break for pandas 1.0.0. Needs elaborate parsing now,
120 + # due to pandas removing version.short_version
121 + pversion = pandas.__version__[:6]
122 except ImportError:
123 install_requires.append('pandas')
124 else:
125 diff --git a/statsmodels/tools/testing.py b/statsmodels/tools/testing.py
126 index e207e44..643f79f 100644
127 --- a/statsmodels/tools/testing.py
128 +++ b/statsmodels/tools/testing.py
129 @@ -16,10 +16,8 @@ def strip_rc(version):
130
131
132 def is_pandas_min_version(min_version):
133 - '''check whether pandas is at least min_version
134 - '''
135 - from pandas.version import short_version as pversion
136 - return StrictVersion(strip_rc(pversion)) >= min_version
137 + '''check whether pandas is at least min_version '''
138 + return StrictVersion((pandas.__version__[:6])) >= min_version
139
140
141 # local copies, all unchanged
142
143 From c894c3f4882d570efb517950069d83afa9794db8 Mon Sep 17 00:00:00 2001
144 From: Ralf Gommers <ralf.gommers@gmail.com>
145 Date: Mon, 26 Oct 2015 20:47:51 +0100
146 Subject: [PATCH 4/4] BUG: fix use of Series.sort_values for older pandas.
147
148 Some failing tests in the previous commits because older ``pandas`` versions
149 don't have ``Series.sort_values``. That method was only added in pandas 0.17,
150 in https://github.com/pydata/pandas/pull/10726
151 ---
152 statsmodels/graphics/tests/test_mosaicplot.py | 6 +++++-
153 statsmodels/graphics/tsaplots.py | 6 +++++-
154 2 files changed, 10 insertions(+), 2 deletions(-)
155
156 diff --git a/statsmodels/graphics/tests/test_mosaicplot.py b/statsmodels/graphics/tests/test_mosaicplot.py
157 index e41020e..2a873e7 100644
158 --- a/statsmodels/graphics/tests/test_mosaicplot.py
159 +++ b/statsmodels/graphics/tests/test_mosaicplot.py
160 @@ -113,7 +113,11 @@ def test_mosaic():
161 # sort by the marriage quality and give meaningful name
162 # [rate_marriage, age, yrs_married, children,
163 # religious, educ, occupation, occupation_husb]
164 - datas = datas.sort_values(by=['rate_marriage', 'religious'])
165 + if pandas.__version__ < '0.17.0':
166 + datas = datas.sort(['rate_marriage', 'religious'])
167 + else:
168 + datas = datas.sort_values(by=['rate_marriage', 'religious'])
169 +
170 num_to_desc = {1: 'awful', 2: 'bad', 3: 'intermediate',
171 4: 'good', 5: 'wonderful'}
172 datas['rate_marriage'] = datas['rate_marriage'].map(num_to_desc)
173 diff --git a/statsmodels/graphics/tsaplots.py b/statsmodels/graphics/tsaplots.py
174 index 94626c9..217724f 100644
175 --- a/statsmodels/graphics/tsaplots.py
176 +++ b/statsmodels/graphics/tsaplots.py
177 @@ -2,6 +2,7 @@
178
179
180 import numpy as np
181 +import pandas
182
183 from statsmodels.graphics import utils
184 from statsmodels.tsa.stattools import acf, pacf
185 @@ -200,7 +201,10 @@ def seasonal_plot(grouped_x, xticklabels, ylabel=None, ax=None):
186 ticks = []
187 for season, df in grouped_x:
188 df = df.copy() # or sort balks for series. may be better way
189 - df.sort_values(inplace=True)
190 + if pandas.__version__ < '0.17.0':
191 + df.sort()
192 + else:
193 + df.sort_values(inplace=True)
194 nobs = len(df)
195 x_plot = np.arange(start, start + nobs)
196 ticks.append(x_plot.mean())