Skip to content

Commit e8f0fea

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 4a88eb8 commit e8f0fea

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
@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
@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
@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
@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
@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
@@ -680,14 +680,14 @@ def test_line_lim(self):
680680
ax = df.plot()
681681
xmin, xmax = ax.get_xlim()
682682
lines = ax.get_lines()
683-
assert xmin == lines[0].get_data()[0][0]
684-
assert xmax == lines[0].get_data()[0][-1]
683+
assert xmin <= lines[0].get_data()[0][0]
684+
assert xmax >= lines[0].get_data()[0][-1]
685685

686686
ax = df.plot(secondary_y=True)
687687
xmin, xmax = ax.get_xlim()
688688
lines = ax.get_lines()
689-
assert xmin == lines[0].get_data()[0][0]
690-
assert xmax == lines[0].get_data()[0][-1]
689+
assert xmin <= lines[0].get_data()[0][0]
690+
assert xmax >= lines[0].get_data()[0][-1]
691691

692692
axes = df.plot(secondary_y=True, subplots=True)
693693
self._check_axes_shape(axes, axes_num=3, layout=(3, 1))
@@ -696,8 +696,8 @@ def test_line_lim(self):
696696
assert not hasattr(ax, 'right_ax')
697697
xmin, xmax = ax.get_xlim()
698698
lines = ax.get_lines()
699-
assert xmin == lines[0].get_data()[0][0]
700-
assert xmax == lines[0].get_data()[0][-1]
699+
assert xmin <= lines[0].get_data()[0][0]
700+
assert xmax >= lines[0].get_data()[0][-1]
701701

702702
def test_area_lim(self):
703703
df = DataFrame(rand(6, 4), columns=['x', 'y', 'z', 'four'])
@@ -708,8 +708,8 @@ def test_area_lim(self):
708708
xmin, xmax = ax.get_xlim()
709709
ymin, ymax = ax.get_ylim()
710710
lines = ax.get_lines()
711-
assert xmin == lines[0].get_data()[0][0]
712-
assert xmax == lines[0].get_data()[0][-1]
711+
assert xmin <= lines[0].get_data()[0][0]
712+
assert xmax >= lines[0].get_data()[0][-1]
713713
assert ymin == 0
714714

715715
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
@@ -103,32 +103,32 @@ def test_ts_line_lim(self):
103103
ax = self.ts.plot(ax=ax)
104104
xmin, xmax = ax.get_xlim()
105105
lines = ax.get_lines()
106-
assert xmin == lines[0].get_data(orig=False)[0][0]
107-
assert xmax == lines[0].get_data(orig=False)[0][-1]
106+
assert xmin <= lines[0].get_data(orig=False)[0][0]
107+
assert xmax >= lines[0].get_data(orig=False)[0][-1]
108108
tm.close()
109109

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

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

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

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

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

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

0 commit comments

Comments
 (0)