Skip to content

Commit 6348786

Browse files
author
TomAugspurger
committed
TST: Adjust boxplot tests following MPL API change
fliers on a boxplot are now 1 object instead of 2.
1 parent 4074957 commit 6348786

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

pandas/tests/test_graphics.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _skip_if_mpl_14_or_dev_boxplot():
3333
# Boxplot failures on 1.4 and 1.4.1
3434
# Don't need try / except since that's done at class level
3535
import matplotlib
36-
if matplotlib.__version__ in ('1.4.0', '1.5.x'):
36+
if matplotlib.__version__ >= LooseVersion('1.4'):
3737
raise nose.SkipTest("Matplotlib Regression in 1.4 and current dev.")
3838

3939

@@ -72,6 +72,11 @@ def setUp(self):
7272
'weight': random.normal(161, 32, size=n),
7373
'category': random.randint(4, size=n)})
7474

75+
if mpl.__version__ >= LooseVersion('1.4'):
76+
self.bp_n_objects = 7
77+
else:
78+
self.bp_n_objects = 8
79+
7580
def tearDown(self):
7681
tm.close()
7782

@@ -1799,23 +1804,26 @@ def test_bar_log_subplots(self):
17991804

18001805
@slow
18011806
def test_boxplot(self):
1802-
_skip_if_mpl_14_or_dev_boxplot()
18031807
df = self.hist_df
18041808
series = df['height']
18051809
numeric_cols = df._get_numeric_data().columns
18061810
labels = [com.pprint_thing(c) for c in numeric_cols]
18071811

18081812
ax = _check_plot_works(df.plot, kind='box')
18091813
self._check_text_labels(ax.get_xticklabels(), labels)
1810-
assert_array_equal(ax.xaxis.get_ticklocs(), np.arange(1, len(numeric_cols) + 1))
1811-
self.assertEqual(len(ax.lines), 8 * len(numeric_cols))
1814+
assert_array_equal(ax.xaxis.get_ticklocs(),
1815+
np.arange(1, len(numeric_cols) + 1))
1816+
self.assertEqual(len(ax.lines),
1817+
self.bp_n_objects * len(numeric_cols))
18121818

1813-
axes = _check_plot_works(df.plot, kind='box', subplots=True, logy=True)
1819+
with tm.assert_produces_warning(UserWarning):
1820+
axes = _check_plot_works(df.plot, kind='box',
1821+
subplots=True, logy=True)
18141822
self._check_axes_shape(axes, axes_num=3, layout=(1, 3))
18151823
self._check_ax_scales(axes, yaxis='log')
18161824
for ax, label in zip(axes, labels):
18171825
self._check_text_labels(ax.get_xticklabels(), [label])
1818-
self.assertEqual(len(ax.lines), 8)
1826+
self.assertEqual(len(ax.lines), self.bp_n_objects)
18191827

18201828
axes = series.plot(kind='box', rot=40)
18211829
self._check_ticks_props(axes, xrot=40, yrot=0)
@@ -1829,35 +1837,33 @@ def test_boxplot(self):
18291837
labels = [com.pprint_thing(c) for c in numeric_cols]
18301838
self._check_text_labels(ax.get_xticklabels(), labels)
18311839
assert_array_equal(ax.xaxis.get_ticklocs(), positions)
1832-
self.assertEqual(len(ax.lines), 8 * len(numeric_cols))
1840+
self.assertEqual(len(ax.lines), self.bp_n_objects * len(numeric_cols))
18331841

18341842
@slow
18351843
def test_boxplot_vertical(self):
1836-
_skip_if_mpl_14_or_dev_boxplot()
18371844
df = self.hist_df
1838-
series = df['height']
18391845
numeric_cols = df._get_numeric_data().columns
18401846
labels = [com.pprint_thing(c) for c in numeric_cols]
18411847

18421848
# if horizontal, yticklabels are rotated
18431849
ax = df.plot(kind='box', rot=50, fontsize=8, vert=False)
18441850
self._check_ticks_props(ax, xrot=0, yrot=50, ylabelsize=8)
18451851
self._check_text_labels(ax.get_yticklabels(), labels)
1846-
self.assertEqual(len(ax.lines), 8 * len(numeric_cols))
1852+
self.assertEqual(len(ax.lines), self.bp_n_objects * len(numeric_cols))
18471853

18481854
axes = _check_plot_works(df.plot, kind='box', subplots=True,
18491855
vert=False, logx=True)
18501856
self._check_axes_shape(axes, axes_num=3, layout=(1, 3))
18511857
self._check_ax_scales(axes, xaxis='log')
18521858
for ax, label in zip(axes, labels):
18531859
self._check_text_labels(ax.get_yticklabels(), [label])
1854-
self.assertEqual(len(ax.lines), 8)
1860+
self.assertEqual(len(ax.lines), self.bp_n_objects)
18551861

18561862
positions = np.array([3, 2, 8])
18571863
ax = df.plot(kind='box', positions=positions, vert=False)
18581864
self._check_text_labels(ax.get_yticklabels(), labels)
18591865
assert_array_equal(ax.yaxis.get_ticklocs(), positions)
1860-
self.assertEqual(len(ax.lines), 8 * len(numeric_cols))
1866+
self.assertEqual(len(ax.lines), self.bp_n_objects * len(numeric_cols))
18611867

18621868
@slow
18631869
def test_boxplot_return_type(self):

0 commit comments

Comments
 (0)