Skip to content

Commit 45e55d0

Browse files
committed
COMPAT: Pandas 0.20 compat
The tests all pass on the RC, so we don't have any substantial changes. This fixes some new FutureWarnings, related to pandas new module privacy. Closes #3617
1 parent cc3fd16 commit 45e55d0

File tree

6 files changed

+20
-27
lines changed

6 files changed

+20
-27
lines changed

statsmodels/compat/pandas.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ def is_numeric_dtype(arr_or_dtype):
5555
return (issubclass(tipo, (np.number, np.bool_)) and
5656
not issubclass(tipo, (np.datetime64, np.timedelta64)))
5757

58-
try:
59-
import pandas.tseries.tools as datetools
60-
import pandas.tseries.frequencies as frequencies
61-
except ImportError:
62-
from pandas.core import datetools
63-
frequencies = datetools
64-
58+
if version >= '0.20':
59+
from pandas.tseries import frequencies
60+
else:
61+
try:
62+
import pandas.tseries.frequencies as frequencies
63+
except ImportError:
64+
from pandas.core import datetools as frequencies

statsmodels/discrete/discrete_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import statsmodels.regression.linear_model as lm
3939
import statsmodels.base.wrapper as wrap
4040
from statsmodels.compat.numpy import np_matrix_rank
41-
from pandas.core.api import get_dummies
41+
from pandas import get_dummies
4242

4343
from statsmodels.base.l1_slsqp import fit_l1_slsqp
4444
try:

statsmodels/graphics/tests/test_tsaplots.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from statsmodels.compat.python import lmap, map
2-
from statsmodels.compat.pandas import datetools
1+
from statsmodels.compat.python import lmap
32
import numpy as np
43
import pandas as pd
54
from numpy.testing import dec, assert_equal
@@ -92,8 +91,7 @@ def test_plot_month():
9291
dta = sm.datasets.elnino.load_pandas().data
9392
dta['YEAR'] = dta.YEAR.astype(int).apply(str)
9493
dta = dta.set_index('YEAR').T.unstack()
95-
dates = lmap(lambda x: datetools.parse_time_string('1 '+' '.join(x))[0],
96-
dta.index.values)
94+
dates = pd.to_datetime(['-'.join([x[1], x[0]]) for x in dta.index.values])
9795

9896
# test dates argument
9997
fig = month_plot(dta.values, dates=dates, ylabel='el nino')
@@ -118,28 +116,24 @@ def test_plot_month():
118116
def test_plot_quarter():
119117
dta = sm.datasets.macrodata.load_pandas().data
120118
dates = lmap('Q'.join, zip(dta.year.astype(int).apply(str),
121-
dta.quarter.astype(int).apply(str)))
119+
dta.quarter.astype(int).apply(str)))
122120
# test dates argument
123121
quarter_plot(dta.unemp.values, dates)
124122
plt.close('all')
125123

126124
# test with a DatetimeIndex with no freq
127-
parser = datetools.parse_time_string
128-
dta.set_index(pd.DatetimeIndex((x[0] for x in map(parser, dates))),
129-
inplace=True)
125+
dta.set_index(pd.to_datetime(dates), inplace=True)
130126
quarter_plot(dta.unemp)
131127
plt.close('all')
132128

133129
# w freq
134130
# see pandas #6631
135-
dta.index = pd.DatetimeIndex((x[0] for x in map(parser, dates)),
136-
freq='QS-Oct')
131+
dta.index = pd.DatetimeIndex(pd.to_datetime(dates), freq='QS-Oct')
137132
quarter_plot(dta.unemp)
138133
plt.close('all')
139134

140135
# w PeriodIndex
141-
dta.index = pd.PeriodIndex((x[0] for x in map(parser, dates)),
142-
freq='Q')
136+
dta.index = pd.PeriodIndex(pd.to_datetime(dates), freq='Q')
143137
quarter_plot(dta.unemp)
144138
plt.close('all')
145139

statsmodels/tools/grouputils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from statsmodels.compat.numpy import npc_unique
3535
from statsmodels.compat.pandas import sort_values
3636
import statsmodels.tools.data as data_util
37-
from pandas.core.index import Index, MultiIndex
37+
from pandas import Index, MultiIndex
3838

3939

4040
def combine_indices(groups, prefix='', sep='.', return_labels=False):

statsmodels/tsa/base/datetools.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"""
44
from statsmodels.compat.python import (lrange, lzip, lmap, string_types, long,
55
callable, asstr, reduce, zip, map)
6-
from statsmodels.compat.pandas import datetools
76
import re
87
import datetime
98

10-
from pandas import Int64Index, Period, PeriodIndex, Timestamp, DatetimeIndex
9+
from pandas import (Int64Index, Period, PeriodIndex, Timestamp, DatetimeIndex,
10+
to_datetime)
1111
import numpy as np
1212

1313
_quarter_to_day = {
@@ -82,7 +82,7 @@ def date_parser(timestr, parserinfo=None, **kwargs):
8282
month, day = 12, 31
8383
year = int(timestr)
8484
else:
85-
return datetools.to_datetime(timestr, **kwargs)
85+
return to_datetime(timestr, **kwargs)
8686

8787
return datetime.datetime(year, month, day)
8888

@@ -176,7 +176,8 @@ def dates_from_range(start, end=None, length=None):
176176
Examples
177177
--------
178178
>>> import statsmodels.api as sm
179-
>>> dates = sm.tsa.datetools.date_range('1960m1', length=nobs)
179+
>>> import pandas as pd
180+
>>> dates = pd.date_range('1960m1', length=nobs)
180181
181182
182183
Returns

statsmodels/tsa/vector_ar/util.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ def parse_lutkepohl_data(path): # pragma: no cover
110110
Source for data files: www.jmulti.de
111111
"""
112112

113-
from statsmodels.compat.pandas import datetools as dt
114-
115113
from collections import deque
116114
from datetime import datetime
117115
import pandas

0 commit comments

Comments
 (0)