Skip to content

Commit 1727ba1

Browse files
committed
TST: Add lineplot tests with unsorted x data
Two new tests check interaction of non-monotonic x data and xlims: test_frame / test_unsorted_index_lims test_series / test_unsorted_index_xlim
1 parent ceaf852 commit 1727ba1

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

pandas/tests/plotting/test_frame.py

+23
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,29 @@ def test_unsorted_index(self):
301301
rs = Series(rs[:, 1], rs[:, 0], dtype=np.int64, name='y')
302302
tm.assert_series_equal(rs, df.y)
303303

304+
def test_unsorted_index_lims(self):
305+
df = DataFrame({'y': [0., 1., 2., 3.]}, index=[1., 0., 3., 2.])
306+
ax = df.plot()
307+
xmin, xmax = ax.get_xlim()
308+
lines = ax.get_lines()
309+
assert xmin <= np.nanmin(lines[0].get_data()[0])
310+
assert xmax >= np.nanmax(lines[0].get_data()[0])
311+
312+
df = DataFrame({'y': [0., 1., np.nan, 3., 4., 5., 6.]},
313+
index=[1., 0., 3., 2., np.nan, 3., 2.])
314+
ax = df.plot()
315+
xmin, xmax = ax.get_xlim()
316+
lines = ax.get_lines()
317+
assert xmin <= np.nanmin(lines[0].get_data()[0])
318+
assert xmax >= np.nanmax(lines[0].get_data()[0])
319+
320+
df = DataFrame({'y': [0., 1., 2., 3.], 'z': [91., 90., 93., 92.]})
321+
ax = df.plot(x='z', y='y')
322+
xmin, xmax = ax.get_xlim()
323+
lines = ax.get_lines()
324+
assert xmin <= np.nanmin(lines[0].get_data()[0])
325+
assert xmax >= np.nanmax(lines[0].get_data()[0])
326+
304327
@slow
305328
def test_subplots(self):
306329
df = DataFrame(np.random.rand(10, 3),

pandas/tests/plotting/test_series.py

+10
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,16 @@ def test_irregular_datetime(self):
280280
ax.set_xlim('1/1/1999', '1/1/2001')
281281
assert xp == ax.get_xlim()[0]
282282

283+
def test_unsorted_index_xlim(self):
284+
ser = Series([0., 1., np.nan, 3., 4., 5., 6.],
285+
index=[1., 0., 3., 2., np.nan, 3., 2.])
286+
_, ax = self.plt.subplots()
287+
ax = ser.plot(ax=ax)
288+
xmin, xmax = ax.get_xlim()
289+
lines = ax.get_lines()
290+
assert xmin <= np.nanmin(lines[0].get_data(orig=False)[0])
291+
assert xmax >= np.nanmax(lines[0].get_data(orig=False)[0])
292+
283293
@slow
284294
def test_pie_series(self):
285295
# if sum of values is less than 1.0, pie handle them as rate and draw

0 commit comments

Comments
 (0)