示例#1
0
 def test_fill_missing_dates(self):
     """Test fill_missing_dates function"""
     _start = Date(freq='m', year=2005, month=1)
     _end = Date(freq='m', year=2005, month=4)
     #
     dates = date_array([_start, _end], freq='M')
     series = time_series([1, 2], dates)
     filled_ser = fill_missing_dates(series)
     #
     assert_equal(filled_ser.start_date, _start)
     assert_equal(filled_ser.end_date, _end)
     assert(filled_ser.isfull())
     assert(not filled_ser.has_duplicated_dates())
     assert_equal(filled_ser.size, _end - _start + 1)
     #
     data = N.arange(5*24).reshape(5,24)
     datelist = ['2007-07-01','2007-07-02','2007-07-03','2007-07-05','2007-07-06']
     dates = date_array_fromlist(datelist, 'D')
     dseries = time_series(data, dates)
     ndates = date_array_fromrange(start_date=dates[0],end_date=dates[-2])
     #
     fseries = fill_missing_dates(dseries)
     assert_equal(fseries.shape, (6,24))
     assert_equal(fseries._mask[:,0], [0,0,0,1,0,0])
     #
     fseries = fill_missing_dates(dseries[:,0])
     assert_equal(fseries.shape, (6,))
     assert_equal(fseries._mask, [0,0,0,1,0,0])
     #
     series = time_series(data.ravel()[:4].reshape(2,2),dates=dates[:-1])
     fseries = fill_missing_dates(series)
     assert_equal(fseries.shape, (5,))
     assert_equal(fseries._mask, [0,0,0,1,0,])
示例#2
0
 def test_fromlist (self):
     "Base data definition."
     (dlist, dates, data) = self.d
     series = time_series(data, dlist)
     assert(isinstance(series, TimeSeries))
     assert_equal(series._mask, [1,0,0,0,0]*3)
     assert_equal(series._series, data)
     assert_equal(series._dates, date_array_fromlist(dlist))
     assert_equal(series.freqstr, 'D')
示例#3
0
 def test_compressed(self):
     "Tests compress"
     dlist = ['2007-01-%02i' % i for i in range(1,16)]
     dates = date_array_fromlist(dlist)
     data = masked_array(numeric.arange(15), mask=[1,0,0,0,0]*3, dtype=float_)
     series = time_series(data, dlist)
     #
     keeper = N.array([0,1,1,1,1]*3, dtype=bool_)
     c_series = series.compressed()
     assert_equal(c_series._data, [1,2,3,4,6,7,8,9,11,12,13,14])
     assert_equal(c_series._mask, nomask)
     assert_equal(c_series._dates, dates[keeper])
     #
     series_st = time_series(MA.column_stack((data,data[::-1])),
                             dates=dates)
     c_series = series_st.compressed()
     d = [1,2,3,6,7,8,11,12,13]
     assert_equal(c_series._data, N.c_[(d,list(reversed(d)))])
     assert_equal(c_series._mask, nomask)
     assert_equal(c_series._dates, dates[d])
示例#4
0
 def test_concatenate(self):
     "Tests concatenate"
     dlist = ['2007-%02i' % i for i in range(1,6)]
     dates = date_array_fromlist(dlist)
     data = masked_array(numeric.arange(5), mask=[1,0,0,0,0], dtype=float_)
     #
     ser_1 = time_series(data, dates)
     ser_2 = time_series(data, dates=dates+10)
     newseries = concatenate_series(ser_1, ser_2)
     assert_equal(newseries._data,[0,1,2,3,4,0,0,0,0,0,0,1,2,3,4])
     assert_equal(newseries._mask,[1,0,0,0,0]+[1]*5+[1,0,0,0,0])
      #
     ser_1 = time_series(data, dates)
     ser_2 = time_series(data, dates=dates+10)
     newseries = concatenate_series(ser_1, ser_2, keep_gap=False)
     assert_equal(newseries._data,[0,1,2,3,4,0,1,2,3,4])
     assert_equal(newseries._mask,[1,0,0,0,0]+[1,0,0,0,0])
     assert newseries.has_missing_dates()
     #
     ser_2 = time_series(data, dates=dates+3)
     newseries = concatenate_series(ser_1, ser_2)
     assert_equal(newseries._data,[0,1,2,0,1,2,3,4])
     assert_equal(newseries._mask,[1,0,0,1,0,0,0,0])
示例#5
0
 def __init__(self, *args, **kwds):
     NumpyTestCase.__init__(self, *args, **kwds)
     dlist = ['2007-01-%02i' % i for i in range(1,16)]
     dates = date_array_fromlist(dlist)
     data = masked_array(numeric.arange(15), mask=[1,0,0,0,0]*3)
     self.d = (dlist, dates, data)
示例#6
0
 def __init__(self, *args, **kwds):
     NumpyTestCase.__init__(self, *args, **kwds)
     dlist = ['2007-01-%02i' % i for i in range(1,16)]
     dates = date_array_fromlist(dlist)
     data = masked_array(numeric.arange(15), mask=[1,0,0,0,0]*3, dtype=float_)
     self.d = (time_series(data, dlist), data, dates)