Skip to content

Commit c440bc9

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 e68580a commit c440bc9

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
@@ -699,8 +699,8 @@ def test_mixed_freq_regular_first(self):
699699
assert idx2.equals(s2.index.to_period('B'))
700700
left, right = ax2.get_xlim()
701701
pidx = s1.index.to_period()
702-
assert left == pidx[0].ordinal
703-
assert right == pidx[-1].ordinal
702+
assert left <= pidx[0].ordinal
703+
assert right >= pidx[-1].ordinal
704704

705705
@pytest.mark.slow
706706
def test_mixed_freq_irregular_first(self):
@@ -730,8 +730,8 @@ def test_mixed_freq_regular_first_df(self):
730730
assert idx2.equals(s2.index.to_period('B'))
731731
left, right = ax2.get_xlim()
732732
pidx = s1.index.to_period()
733-
assert left == pidx[0].ordinal
734-
assert right == pidx[-1].ordinal
733+
assert left <= pidx[0].ordinal
734+
assert right >= pidx[-1].ordinal
735735

736736
@pytest.mark.slow
737737
def test_mixed_freq_irregular_first_df(self):
@@ -1245,8 +1245,8 @@ def test_irregular_ts_shared_ax_xlim(self):
12451245

12461246
# check that axis limits are correct
12471247
left, right = ax.get_xlim()
1248-
assert left == ts_irregular.index.min().toordinal()
1249-
assert right == ts_irregular.index.max().toordinal()
1248+
assert left <= ts_irregular.index.min().toordinal()
1249+
assert right >= ts_irregular.index.max().toordinal()
12501250

12511251
@pytest.mark.slow
12521252
def test_secondary_y_non_ts_xlim(self):
@@ -1262,7 +1262,7 @@ def test_secondary_y_non_ts_xlim(self):
12621262
s2.plot(secondary_y=True, ax=ax)
12631263
left_after, right_after = ax.get_xlim()
12641264

1265-
assert left_before == left_after
1265+
assert left_before >= left_after
12661266
assert right_before < right_after
12671267

12681268
@pytest.mark.slow
@@ -1279,7 +1279,7 @@ def test_secondary_y_regular_ts_xlim(self):
12791279
s2.plot(secondary_y=True, ax=ax)
12801280
left_after, right_after = ax.get_xlim()
12811281

1282-
assert left_before == left_after
1282+
assert left_before >= left_after
12831283
assert right_before < right_after
12841284

12851285
@pytest.mark.slow
@@ -1312,8 +1312,8 @@ def test_secondary_y_irregular_ts_xlim(self):
13121312
ts_irregular[:5].plot(ax=ax)
13131313

13141314
left, right = ax.get_xlim()
1315-
assert left == ts_irregular.index.min().toordinal()
1316-
assert right == ts_irregular.index.max().toordinal()
1315+
assert left <= ts_irregular.index.min().toordinal()
1316+
assert right >= ts_irregular.index.max().toordinal()
13171317

13181318
def test_plot_outofbounds_datetime(self):
13191319
# 2579 - checking this does not raise

pandas/tests/plotting/test_frame.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -758,14 +758,14 @@ def test_line_lim(self):
758758
ax = df.plot()
759759
xmin, xmax = ax.get_xlim()
760760
lines = ax.get_lines()
761-
assert xmin == lines[0].get_data()[0][0]
762-
assert xmax == lines[0].get_data()[0][-1]
761+
assert xmin <= lines[0].get_data()[0][0]
762+
assert xmax >= lines[0].get_data()[0][-1]
763763

764764
ax = df.plot(secondary_y=True)
765765
xmin, xmax = ax.get_xlim()
766766
lines = ax.get_lines()
767-
assert xmin == lines[0].get_data()[0][0]
768-
assert xmax == lines[0].get_data()[0][-1]
767+
assert xmin <= lines[0].get_data()[0][0]
768+
assert xmax >= lines[0].get_data()[0][-1]
769769

770770
axes = df.plot(secondary_y=True, subplots=True)
771771
self._check_axes_shape(axes, axes_num=3, layout=(3, 1))
@@ -774,8 +774,8 @@ def test_line_lim(self):
774774
assert not hasattr(ax, 'right_ax')
775775
xmin, xmax = ax.get_xlim()
776776
lines = ax.get_lines()
777-
assert xmin == lines[0].get_data()[0][0]
778-
assert xmax == lines[0].get_data()[0][-1]
777+
assert xmin <= lines[0].get_data()[0][0]
778+
assert xmax >= lines[0].get_data()[0][-1]
779779

780780
def test_area_lim(self):
781781
df = DataFrame(rand(6, 4), columns=['x', 'y', 'z', 'four'])
@@ -786,8 +786,8 @@ def test_area_lim(self):
786786
xmin, xmax = ax.get_xlim()
787787
ymin, ymax = ax.get_ylim()
788788
lines = ax.get_lines()
789-
assert xmin == lines[0].get_data()[0][0]
790-
assert xmax == lines[0].get_data()[0][-1]
789+
assert xmin <= lines[0].get_data()[0][0]
790+
assert xmax >= lines[0].get_data()[0][-1]
791791
assert ymin == 0
792792

793793
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)