Skip to content

Commit 2455240

Browse files
committed
TST: plotting: Relax some tests to work with matplotlib 2.0
Matplotlib 2.0 by default now adds some padding between the boundaries of the data and the boundaries of the plot. This causes some of our tests to fail if we don't relax them slightly. modified: pandas/tests/plotting/test_datetimelike.py test_irregular_ts_shared_ax_xlim test_mixed_freq_regular_first test_mixed_freq_regular_first_df test_secondary_y_irregular_ts_xlim test_secondary_y_non_ts_xlim test_secondary_y_regular_ts_xlim modified: pandas/tests/plotting/test_frame.py test_area_lim test_line_lim modified: pandas/tests/plotting/test_series.py test_ts_area_lim test_ts_line_lim
1 parent 3a19341 commit 2455240

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

pandas/tests/plotting/test_datetimelike.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ def test_mixed_freq_regular_first(self):
697697
assert idx2.equals(s2.index.to_period('B'))
698698
left, right = ax2.get_xlim()
699699
pidx = s1.index.to_period()
700-
assert left == pidx[0].ordinal
701-
assert right == pidx[-1].ordinal
700+
assert left <= pidx[0].ordinal
701+
assert right >= pidx[-1].ordinal
702702

703703
@pytest.mark.slow
704704
def test_mixed_freq_irregular_first(self):
@@ -728,8 +728,8 @@ def test_mixed_freq_regular_first_df(self):
728728
assert idx2.equals(s2.index.to_period('B'))
729729
left, right = ax2.get_xlim()
730730
pidx = s1.index.to_period()
731-
assert left == pidx[0].ordinal
732-
assert right == pidx[-1].ordinal
731+
assert left <= pidx[0].ordinal
732+
assert right >= pidx[-1].ordinal
733733

734734
@pytest.mark.slow
735735
def test_mixed_freq_irregular_first_df(self):
@@ -1243,8 +1243,8 @@ def test_irregular_ts_shared_ax_xlim(self):
12431243

12441244
# check that axis limits are correct
12451245
left, right = ax.get_xlim()
1246-
assert left == ts_irregular.index.min().toordinal()
1247-
assert right == ts_irregular.index.max().toordinal()
1246+
assert left <= ts_irregular.index.min().toordinal()
1247+
assert right >= ts_irregular.index.max().toordinal()
12481248

12491249
@pytest.mark.slow
12501250
def test_secondary_y_non_ts_xlim(self):
@@ -1260,7 +1260,7 @@ def test_secondary_y_non_ts_xlim(self):
12601260
s2.plot(secondary_y=True, ax=ax)
12611261
left_after, right_after = ax.get_xlim()
12621262

1263-
assert left_before == left_after
1263+
assert left_before >= left_after
12641264
assert right_before < right_after
12651265

12661266
@pytest.mark.slow
@@ -1277,7 +1277,7 @@ def test_secondary_y_regular_ts_xlim(self):
12771277
s2.plot(secondary_y=True, ax=ax)
12781278
left_after, right_after = ax.get_xlim()
12791279

1280-
assert left_before == left_after
1280+
assert left_before >= left_after
12811281
assert right_before < right_after
12821282

12831283
@pytest.mark.slow
@@ -1310,8 +1310,8 @@ def test_secondary_y_irregular_ts_xlim(self):
13101310
ts_irregular[:5].plot(ax=ax)
13111311

13121312
left, right = ax.get_xlim()
1313-
assert left == ts_irregular.index.min().toordinal()
1314-
assert right == ts_irregular.index.max().toordinal()
1313+
assert left <= ts_irregular.index.min().toordinal()
1314+
assert right >= ts_irregular.index.max().toordinal()
13151315

13161316
def test_plot_outofbounds_datetime(self):
13171317
# 2579 - checking this does not raise

pandas/tests/plotting/test_frame.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -683,14 +683,14 @@ def test_line_lim(self):
683683
ax = df.plot()
684684
xmin, xmax = ax.get_xlim()
685685
lines = ax.get_lines()
686-
assert xmin == lines[0].get_data()[0][0]
687-
assert xmax == lines[0].get_data()[0][-1]
686+
assert xmin <= lines[0].get_data()[0][0]
687+
assert xmax >= lines[0].get_data()[0][-1]
688688

689689
ax = df.plot(secondary_y=True)
690690
xmin, xmax = ax.get_xlim()
691691
lines = ax.get_lines()
692-
assert xmin == lines[0].get_data()[0][0]
693-
assert xmax == lines[0].get_data()[0][-1]
692+
assert xmin <= lines[0].get_data()[0][0]
693+
assert xmax >= lines[0].get_data()[0][-1]
694694

695695
axes = df.plot(secondary_y=True, subplots=True)
696696
self._check_axes_shape(axes, axes_num=3, layout=(3, 1))
@@ -699,8 +699,8 @@ def test_line_lim(self):
699699
assert not hasattr(ax, 'right_ax')
700700
xmin, xmax = ax.get_xlim()
701701
lines = ax.get_lines()
702-
assert xmin == lines[0].get_data()[0][0]
703-
assert xmax == lines[0].get_data()[0][-1]
702+
assert xmin <= lines[0].get_data()[0][0]
703+
assert xmax >= lines[0].get_data()[0][-1]
704704

705705
def test_area_lim(self):
706706
df = DataFrame(rand(6, 4), columns=['x', 'y', 'z', 'four'])
@@ -711,8 +711,8 @@ def test_area_lim(self):
711711
xmin, xmax = ax.get_xlim()
712712
ymin, ymax = ax.get_ylim()
713713
lines = ax.get_lines()
714-
assert xmin == lines[0].get_data()[0][0]
715-
assert xmax == lines[0].get_data()[0][-1]
714+
assert xmin <= lines[0].get_data()[0][0]
715+
assert xmax >= lines[0].get_data()[0][-1]
716716
assert ymin == 0
717717

718718
ax = _check_plot_works(neg_df.plot.area, stacked=stacked)

pandas/tests/plotting/test_series.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -102,32 +102,32 @@ def test_ts_line_lim(self):
102102
ax = self.ts.plot(ax=ax)
103103
xmin, xmax = ax.get_xlim()
104104
lines = ax.get_lines()
105-
assert xmin == lines[0].get_data(orig=False)[0][0]
106-
assert xmax == lines[0].get_data(orig=False)[0][-1]
105+
assert xmin <= lines[0].get_data(orig=False)[0][0]
106+
assert xmax >= lines[0].get_data(orig=False)[0][-1]
107107
tm.close()
108108

109109
ax = self.ts.plot(secondary_y=True, ax=ax)
110110
xmin, xmax = ax.get_xlim()
111111
lines = ax.get_lines()
112-
assert xmin == lines[0].get_data(orig=False)[0][0]
113-
assert xmax == lines[0].get_data(orig=False)[0][-1]
112+
assert xmin <= lines[0].get_data(orig=False)[0][0]
113+
assert xmax >= lines[0].get_data(orig=False)[0][-1]
114114

115115
def test_ts_area_lim(self):
116116
_, ax = self.plt.subplots()
117117
ax = self.ts.plot.area(stacked=False, ax=ax)
118118
xmin, xmax = ax.get_xlim()
119119
line = ax.get_lines()[0].get_data(orig=False)[0]
120-
assert xmin == line[0]
121-
assert xmax == line[-1]
120+
assert xmin <= line[0]
121+
assert xmax >= line[-1]
122122
tm.close()
123123

124124
# GH 7471
125125
_, ax = self.plt.subplots()
126126
ax = self.ts.plot.area(stacked=False, x_compat=True, ax=ax)
127127
xmin, xmax = ax.get_xlim()
128128
line = ax.get_lines()[0].get_data(orig=False)[0]
129-
assert xmin == line[0]
130-
assert xmax == line[-1]
129+
assert xmin <= line[0]
130+
assert xmax >= line[-1]
131131
tm.close()
132132

133133
tz_ts = self.ts.copy()
@@ -136,16 +136,16 @@ def test_ts_area_lim(self):
136136
ax = tz_ts.plot.area(stacked=False, x_compat=True, ax=ax)
137137
xmin, xmax = ax.get_xlim()
138138
line = ax.get_lines()[0].get_data(orig=False)[0]
139-
assert xmin == line[0]
140-
assert xmax == line[-1]
139+
assert xmin <= line[0]
140+
assert xmax >= line[-1]
141141
tm.close()
142142

143143
_, ax = self.plt.subplots()
144144
ax = tz_ts.plot.area(stacked=False, secondary_y=True, ax=ax)
145145
xmin, xmax = ax.get_xlim()
146146
line = ax.get_lines()[0].get_data(orig=False)[0]
147-
assert xmin == line[0]
148-
assert xmax == line[-1]
147+
assert xmin <= line[0]
148+
assert xmax >= line[-1]
149149

150150
def test_label(self):
151151
s = Series([1, 2])

0 commit comments

Comments
 (0)