Skip to content

Commit 5282a29

Browse files
Chang Shewesm
authored andcommitted
TST: test case for tseries plots with data gaps
1 parent 2abfd5b commit 5282a29

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

pandas/tseries/plotting.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def tsplot(series, plotf, *args, **kwargs):
9999
if freq != series.index.freq:
100100
series = series.asfreq(freq)
101101

102-
mask = isnull(series)
102+
103103

104104
style = kwargs.pop('style', None)
105105

@@ -118,9 +118,15 @@ def tsplot(series, plotf, *args, **kwargs):
118118
ax.date_axis_info = None
119119

120120
# format args and lot
121-
masked_array = np.ma.array(series.values)
122-
masked_array = np.ma.masked_where(mask, masked_array)
123-
args = _check_plot_params(masked_array, series.index, freq, style, *args)
121+
mask = isnull(series)
122+
if mask.any():
123+
masked_array = np.ma.array(series.values)
124+
masked_array = np.ma.masked_where(mask, masked_array)
125+
args = _check_plot_params(masked_array, series.index, freq, style,
126+
*args)
127+
else:
128+
args = _check_plot_params(series, series.index, freq, style, *args)
129+
124130
plotted = plotf(ax, *args, **kwargs)
125131

126132
format_dateaxis(ax, ax.freq)

pandas/tseries/tests/test_plotting.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,21 @@ def test_finder_monthly(self):
192192
rs = xaxis.get_majorticklocs()[0]
193193
self.assert_(rs == xp)
194194

195+
@slow
196+
def test_gaps(self):
197+
import matplotlib.pyplot as plt
198+
plt.close('all')
199+
ts = tm.makeTimeSeries()
200+
ts[5:25] = np.nan
201+
ax = ts.plot()
202+
lines = ax.get_lines()
203+
self.assert_(len(lines) == 1)
204+
l = lines[0]
205+
data = l.get_xydata()
206+
self.assert_(isinstance(data, np.ma.core.MaskedArray))
207+
mask = data.mask
208+
self.assert_(mask[5:25, 1].all())
209+
195210
@slow
196211
def test_secondary_y(self):
197212
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)