Skip to content

Commit edc90b3

Browse files
committed
BUG: handle columns argument in DataFrame.to_html, use statsmodels.api to avoid deprecation warnings, close pandas-dev#890
1 parent 4428ad3 commit edc90b3

File tree

12 files changed

+68
-122
lines changed

12 files changed

+68
-122
lines changed

pandas/core/format.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,13 @@ def write_tr(buf, l, indent=0, indent_delta=4, header=False):
253253
def _column_header():
254254
row = [''] * (frame.index.nlevels - 1)
255255

256-
if isinstance(frame.columns, MultiIndex):
256+
if isinstance(self.columns, MultiIndex):
257257
if self.has_column_names:
258-
row.append(single_column_table(frame.columns.names))
259-
row.extend([single_column_table(c) for c in frame.columns])
258+
row.append(single_column_table(self.columns.names))
259+
row.extend([single_column_table(c) for c in self.columns])
260260
else:
261-
row.append(frame.columns.name or '')
262-
row.extend(frame.columns)
261+
row.append(self.columns.name or '')
262+
row.extend(self.columns)
263263
return row
264264

265265
if len(frame.columns) == 0 or len(frame.index) == 0:
@@ -282,7 +282,7 @@ def _column_header():
282282
indent += indent_delta
283283
write_tr(buf, col_row, indent, indent_delta, header=True)
284284
if self.has_index_names:
285-
row = frame.index.names + [''] * len(frame.columns)
285+
row = frame.index.names + [''] * len(self.columns)
286286
write_tr(buf, row, indent, indent_delta, header=True)
287287

288288
write(buf, '</thead>', indent)
@@ -299,7 +299,7 @@ def _maybe_bold_row(x):
299299
return x
300300

301301
fmt_values = {}
302-
for col in frame.columns:
302+
for col in self.columns:
303303
fmt_values[col] = self._format_col(col)
304304

305305
# write values
@@ -309,7 +309,7 @@ def _maybe_bold_row(x):
309309
row.extend(_maybe_bold_row(frame.index[i]))
310310
else:
311311
row.append(_maybe_bold_row(frame.index[i]))
312-
for col in frame.columns:
312+
for col in self.columns:
313313
row.append(fmt_values[col][i])
314314
write_tr(buf, row, indent, indent_delta)
315315
indent -= indent_delta

pandas/core/frame.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3931,7 +3931,8 @@ def _bar_plot(self, axes, subplots=False, use_index=True, grid=True,
39313931
if legend and not subplots:
39323932
fig = ax.get_figure()
39333933
fig.legend([r[0] for r in rects], labels, loc='upper center',
3934-
fancybox=True, ncol=6, mode='expand')
3934+
fancybox=True, ncol=6)
3935+
#mode='expand')
39353936

39363937
import matplotlib.pyplot as plt
39373938
plt.subplots_adjust(top=0.8)

pandas/core/groupby.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,6 @@ def _convert_grouper(axis, grouper):
833833

834834
class SeriesGroupBy(GroupBy):
835835

836-
_cythonized_methods = set(['add', 'mean'])
837-
838836
def aggregate(self, func_or_funcs, *args, **kwargs):
839837
"""
840838
Apply aggregation function or functions to groups, yielding most likely

pandas/core/series.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,21 @@ def plot(self, label=None, kind='line', use_index=True, rot=30, ax=None,
21212121
ax.set_xticklabels([gfx._stringify(key) for key in self.index],
21222122
rotation=rot,
21232123
fontsize=fontsize)
2124+
elif kind == 'barh':
2125+
yinds = np.arange(N) + 0.25
2126+
ax.barh(yinds, self.values.astype(float), 0.5,
2127+
left=np.zeros(N), linewidth=1, **kwds)
2128+
2129+
if N < 10:
2130+
fontsize = 12
2131+
else:
2132+
fontsize = 10
2133+
2134+
ax.set_yticks(yinds + 0.25)
2135+
ax.set_yticklabels([gfx._stringify(key) for key in self.index],
2136+
rotation=rot,
2137+
fontsize=fontsize)
2138+
21242139
ax.grid(grid)
21252140
plt.draw_if_interactive()
21262141

pandas/stats/ols.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ class OLS(object):
3838

3939
def __init__(self, y, x, intercept=True, weights=None, nw_lags=None,
4040
nw_overlap=False):
41-
import scikits.statsmodels.api as sm
41+
try:
42+
import statsmodels.api as sm
43+
except ImportError:
44+
import scikits.statsmodels.api as sm
45+
4246
self._x_orig = x
4347
self._y_orig = y
4448
self._weights_orig = weights

pandas/stats/tests/common.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ def check_for_scipy():
3838
raise nose.SkipTest('no scipy')
3939

4040
def check_for_statsmodels():
41+
_have_statsmodels = True
4142
try:
42-
import scikits.statsmodels as sm
43-
except Exception:
44-
raise nose.SkipTest('no statsmodels')
43+
import statsmodels.api as sm
44+
except ImportError:
45+
try:
46+
import scikits.statsmodels.api as sm
47+
except ImportError:
48+
raise nose.SkipTest('no statsmodels')
4549

4650

4751
class BaseTest(unittest.TestCase):

pandas/stats/tests/test_ols.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from datetime import datetime
1010
import unittest
11+
import nose
1112
import numpy as np
1213

1314
from pandas.core.panel import Panel
@@ -21,10 +22,14 @@
2122

2223
from common import BaseTest
2324

25+
_have_statsmodels = True
2426
try:
25-
import scikits.statsmodels.api as sm
27+
import statsmodels.api as sm
2628
except ImportError:
27-
pass
29+
try:
30+
import scikits.statsmodels.api as sm
31+
except ImportError:
32+
_have_statsmodels = False
2833

2934
def _check_repr(obj):
3035
repr(obj)
@@ -60,10 +65,7 @@ def setUpClass(cls):
6065
except ImportError:
6166
pass
6267

63-
try:
64-
import scikits.statsmodels.api as _
65-
except ImportError:
66-
import nose
68+
if not _have_statsmodels:
6769
raise nose.SkipTest
6870

6971
def testOLSWithDatasets(self):
@@ -149,8 +151,7 @@ def checkOLS(self, exog, endog, x, y):
149151
_check_non_raw_results(result)
150152

151153
def checkMovingOLS(self, window_type, x, y, weights=None, **kwds):
152-
from scikits.statsmodels.tools.tools import rank
153-
window = rank(x.values) * 2
154+
window = sm.tools.tools.rank(x.values) * 2
154155

155156
moving = ols(y=y, x=x, weights=weights, window_type=window_type,
156157
window=window, **kwds)
@@ -232,10 +233,7 @@ class TestOLSMisc(unittest.TestCase):
232233
'''
233234
@classmethod
234235
def setupClass(cls):
235-
try:
236-
import scikits.statsmodels.api as _
237-
except ImportError:
238-
import nose
236+
if not _have_statsmodels:
239237
raise nose.SkipTest
240238

241239
def test_f_test(self):

pandas/stats/tests/test_var.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77

88
raise nose.SkipTest('skipping this for now')
99

10-
import scikits.statsmodels.tsa.var as sm_var
11-
import scikits.statsmodels as sm
10+
try:
11+
import statsmodels.tsa.var as sm_var
12+
import statsmodels as sm
13+
except ImportError:
14+
import scikits.statsmodels.tsa.var as sm_var
15+
import scikits.statsmodels as sm
16+
1217

1318
import pandas.stats.var as _pvar
1419
reload(_pvar)

pandas/stats/var.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ class VAR(object):
2323
"""
2424

2525
def __init__(self, data, p=1, intercept=True):
26-
import scikits.statsmodels.tsa.var as sm_var
26+
try:
27+
import statsmodels.tsa.var as sm_var
28+
except ImportError:
29+
import scikits.statsmodels.tsa.var as sm_var
2730

2831
self._data = DataFrame(_combine_rhs(data))
2932
self._p = p

pandas/tests/test_format.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ def test_to_html_with_no_bold(self):
353353
ashtml = x.to_html(bold_rows=False)
354354
assert('<strong>' not in ashtml)
355355

356+
def test_to_html_columns_arg(self):
357+
result = self.frame.to_html(columns=['A'])
358+
self.assert_('<th>B</th>' not in result)
359+
356360
def test_repr_html(self):
357361
self.frame._repr_html_()
358362

0 commit comments

Comments
 (0)