Skip to content

Commit 96c1468

Browse files
committed
Additional test coverage for v0.9.1
1 parent db465bb commit 96c1468

File tree

7 files changed

+43
-52
lines changed

7 files changed

+43
-52
lines changed

pandas/tests/test_graphics.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ class TestDataFramePlots(unittest.TestCase):
156156

157157
@classmethod
158158
def setUpClass(cls):
159-
import sys
160-
if 'IPython' in sys.modules:
161-
raise nose.SkipTest
159+
#import sys
160+
#if 'IPython' in sys.modules:
161+
# raise nose.SkipTest
162162

163163
try:
164164
import matplotlib as mpl
@@ -485,9 +485,9 @@ class TestDataFrameGroupByPlots(unittest.TestCase):
485485

486486
@classmethod
487487
def setUpClass(cls):
488-
import sys
489-
if 'IPython' in sys.modules:
490-
raise nose.SkipTest
488+
#import sys
489+
#if 'IPython' in sys.modules:
490+
# raise nose.SkipTest
491491

492492
try:
493493
import matplotlib as mpl

pandas/tools/plotting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,8 @@ def plot_frame(frame=None, x=None, y=None, subplots=False, sharex=True,
12931293

12941294
def plot_series(series, label=None, kind='line', use_index=True, rot=None,
12951295
xticks=None, yticks=None, xlim=None, ylim=None,
1296-
ax=None, style=None, grid=None, logy=False, secondary_y=False,
1297-
**kwds):
1296+
ax=None, style=None, grid=None, legend=False, logy=False,
1297+
secondary_y=False, **kwds):
12981298
"""
12991299
Plot the input series with the index on the x-axis using matplotlib
13001300
@@ -1358,7 +1358,7 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
13581358
plot_obj = klass(series, kind=kind, rot=rot, logy=logy,
13591359
ax=ax, use_index=use_index, style=style,
13601360
xticks=xticks, yticks=yticks, xlim=xlim, ylim=ylim,
1361-
legend=False, grid=grid, label=label,
1361+
legend=legend, grid=grid, label=label,
13621362
secondary_y=secondary_y, **kwds)
13631363

13641364
plot_obj.generate()

pandas/tseries/converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def __call__(self):
326326
if len(all_dates) > 0:
327327
locs = self.raise_if_exceeds(dates.date2num(all_dates))
328328
return locs
329-
except Exception, e:
329+
except Exception, e: #pragma: no cover
330330
pass
331331

332332
lims = dates.date2num([dmin, dmax])

pandas/tseries/index.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,11 +1566,3 @@ def _time_to_micros(time):
15661566
return 1000000 * seconds + time.microsecond
15671567

15681568

1569-
def _utc_naive(dt):
1570-
if dt is None:
1571-
return dt
1572-
1573-
if dt.tz is not None:
1574-
dt = dt.tz_convert('utc').replace(tzinfo=None)
1575-
1576-
return dt

pandas/tseries/plotting.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def _maybe_resample(series, ax, freq, plotf, kwargs):
9999
elif frequencies.is_subperiod(freq, ax_freq) or _is_sub(freq, ax_freq):
100100
_upsample_others(ax, freq, plotf, kwargs)
101101
ax_freq = freq
102-
else:
102+
else: #pragma: no cover
103103
raise ValueError('Incompatible frequency conversion')
104104
return freq, ax_freq, series
105105

@@ -146,7 +146,6 @@ def _upsample_others(ax, freq, plotf, kwargs):
146146
title = None
147147
ax.legend(lines, labels, loc='best', title=title)
148148

149-
150149
def _replot_ax(ax, freq, plotf, kwargs):
151150
data = getattr(ax, '_plot_data', None)
152151
ax._plot_data = []
@@ -187,7 +186,7 @@ def _maybe_mask(series):
187186
masked_array = np.ma.masked_where(mask, masked_array)
188187
args = [series.index, masked_array]
189188
else:
190-
args = [series.index, series]
189+
args = [series.index, series.values]
191190
return args
192191

193192

@@ -222,19 +221,6 @@ def _get_xlim(lines):
222221
right = max(x[-1].ordinal, right)
223222
return left, right
224223

225-
226-
def get_datevalue(date, freq):
227-
if isinstance(date, Period):
228-
return date.asfreq(freq).ordinal
229-
elif isinstance(date, (str, datetime, pydt.date, pydt.time)):
230-
return Period(date, freq).ordinal
231-
elif (com.is_integer(date) or com.is_float(date) or
232-
(isinstance(date, np.ndarray) and (date.size == 1))):
233-
return date
234-
elif date is None:
235-
return None
236-
raise ValueError("Unrecognizable date '%s'" % date)
237-
238224
# Patch methods for subplot. Only format_dateaxis is currently used.
239225
# Do we need the rest for convenience?
240226

pandas/tseries/tests/test_period.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ def test_constructor_corner(self):
427427
freq='2M')
428428

429429
self.assertRaises(ValueError, Period, datetime.now())
430+
self.assertRaises(ValueError, Period, datetime.now().date())
430431
self.assertRaises(ValueError, Period, 1.6, freq='D')
431432
self.assertRaises(ValueError, Period, ordinal=1.6, freq='D')
432433
self.assertRaises(ValueError, Period, ordinal=2, value=1, freq='D')
@@ -1191,6 +1192,19 @@ def test_getitem_partial(self):
11911192
result = ts['2008Q1':'2009Q4']
11921193
self.assertEquals(len(result), 24)
11931194

1195+
result = ts[:'2009']
1196+
self.assertEquals(len(result), 36)
1197+
1198+
result = ts['2009':]
1199+
self.assertEquals(len(result), 50 - 24)
1200+
1201+
exp = result
1202+
result = ts[24:]
1203+
assert_series_equal(exp, result)
1204+
1205+
ts = ts[10:].append(ts[10:])
1206+
self.assertRaises(ValueError, ts.__getitem__, slice('2008', '2009'))
1207+
11941208
def test_getitem_datetime(self):
11951209
rng = period_range(start='2012-01-01', periods=10, freq='W-MON')
11961210
ts = Series(range(len(rng)), index=rng)

pandas/tseries/tests/test_plotting.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
from numpy.testing.decorators import slow
99
from numpy.testing import assert_array_equal
1010

11-
from pandas import Index, Series, DataFrame, isnull, notnull
11+
from pandas import Index, Series, DataFrame
1212

1313
from pandas.tseries.index import date_range, bdate_range
14-
from pandas.tseries.offsets import Minute, DateOffset
15-
from pandas.tseries.period import period_range, Period
16-
from pandas.tseries.resample import DatetimeIndex, TimeGrouper
17-
import pandas.tseries.offsets as offsets
18-
import pandas.tseries.frequencies as frequencies
14+
from pandas.tseries.offsets import DateOffset
15+
from pandas.tseries.period import period_range, Period, PeriodIndex
16+
from pandas.tseries.resample import DatetimeIndex
1917

20-
from pandas.util.testing import assert_series_equal, assert_almost_equal
18+
from pandas.util.testing import assert_series_equal
2119
import pandas.util.testing as tm
2220

2321
class TestTSPlot(unittest.TestCase):
@@ -100,7 +98,7 @@ def test_high_freq(self):
10098
_check_plot_works(ser.plot)
10199

102100
def test_get_datevalue(self):
103-
from pandas.tseries.plotting import get_datevalue
101+
from pandas.tseries.converter import get_datevalue
104102
self.assert_(get_datevalue(None, 'D') is None)
105103
self.assert_(get_datevalue(1987, 'A') == 1987)
106104
self.assert_(get_datevalue(Period(1987, 'A'), 'M') ==
@@ -238,7 +236,7 @@ def test_business_freq(self):
238236
self.assert_(ax.get_lines()[0].get_xydata()[0, 0],
239237
bts.index[0].ordinal)
240238
idx = ax.get_lines()[0].get_xdata()
241-
self.assert_(idx.freqstr == 'B')
239+
self.assert_(PeriodIndex(data=idx).freqstr == 'B')
242240

243241
@slow
244242
def test_business_freq_convert(self):
@@ -252,7 +250,7 @@ def test_business_freq_convert(self):
252250
ax = bts.plot()
253251
self.assert_(ax.get_lines()[0].get_xydata()[0, 0], ts.index[0].ordinal)
254252
idx = ax.get_lines()[0].get_xdata()
255-
self.assert_(idx.freqstr == 'M')
253+
self.assert_(PeriodIndex(data=idx).freqstr == 'M')
256254

257255
@slow
258256
def test_dataframe(self):
@@ -606,7 +604,7 @@ def test_mixed_freq_hf_first(self):
606604
high.plot()
607605
ax = low.plot()
608606
for l in ax.get_lines():
609-
self.assert_(l.get_xdata().freq == 'D')
607+
self.assert_(PeriodIndex(data=l.get_xdata()).freq == 'D')
610608

611609
@slow
612610
def test_mixed_freq_lf_first(self):
@@ -616,10 +614,12 @@ def test_mixed_freq_lf_first(self):
616614
idxl = date_range('1/1/1999', periods=12, freq='M')
617615
high = Series(np.random.randn(len(idxh)), idxh)
618616
low = Series(np.random.randn(len(idxl)), idxl)
619-
low.plot()
620-
ax = high.plot()
617+
low.plot(legend=True)
618+
ax = high.plot(legend=True)
621619
for l in ax.get_lines():
622-
self.assert_(l.get_xdata().freq == 'D')
620+
self.assert_(PeriodIndex(data=l.get_xdata()).freq == 'D')
621+
leg = ax.get_legend()
622+
self.assert_(len(leg.texts) == 2)
623623

624624
plt.close('all')
625625
idxh = date_range('1/1/1999', periods=240, freq='T')
@@ -629,7 +629,7 @@ def test_mixed_freq_lf_first(self):
629629
low.plot()
630630
ax = high.plot()
631631
for l in ax.get_lines():
632-
self.assert_(l.get_xdata().freq == 'T')
632+
self.assert_(PeriodIndex(data=l.get_xdata()).freq == 'T')
633633

634634
@slow
635635
def test_mixed_freq_irreg_period(self):
@@ -651,7 +651,7 @@ def test_to_weekly_resampling(self):
651651
high.plot()
652652
ax = low.plot()
653653
for l in ax.get_lines():
654-
self.assert_(l.get_xdata().freq.startswith('W'))
654+
self.assert_(PeriodIndex(data=l.get_xdata()).freq.startswith('W'))
655655

656656
@slow
657657
def test_from_weekly_resampling(self):
@@ -664,11 +664,10 @@ def test_from_weekly_resampling(self):
664664
low.plot()
665665
ax = high.plot()
666666
for l in ax.get_lines():
667-
self.assert_(l.get_xdata().freq.startswith('W'))
667+
self.assert_(PeriodIndex(data=l.get_xdata()).freq.startswith('W'))
668668

669669
@slow
670670
def test_irreg_dtypes(self):
671-
import matplotlib.pyplot as plt
672671
#date
673672
idx = [date(2000, 1, 1), date(2000, 1, 5), date(2000, 1, 20)]
674673
df = DataFrame(np.random.randn(len(idx), 3), Index(idx, dtype=object))

0 commit comments

Comments
 (0)