def test_timeseries_daterange(self): """Tests returning the starting and ending dates in various formats.""" # ordinal daterange as ordinals, self.assertTupleEqual( self.ts.daterange(), ( datetime(2015, 12, 31).toordinal(), datetime(2016, 1, 9).toordinal(), ), ) # ordinal daterange as string self.assertTupleEqual(self.ts.daterange("str"), ("2015-12-31", "2016-01-09")) # ordinal daterange as datetimes self.assertTupleEqual( self.ts.daterange("datetime"), (date(2015, 12, 31), date(2016, 1, 9)), ) # timestamp tstamp_list = datetime(2016, 1, 1).timestamp() + np.arange(20) ts = Timeseries() ts.frequency = FREQ_SEC ts.dseries = tstamp_list ts.tseries = np.arange(20) # timestamp daterange as timestamps self.assertTupleEqual( ts.daterange(), ( datetime(2016, 1, 1).timestamp(), datetime(2016, 1, 1, 0, 0, 19).timestamp(), ), ) # timestamp daterange as string self.assertTupleEqual( ts.daterange("str"), ("2016-01-01 00:00:00", "2016-01-01 00:00:19"), ) # timestamp daterange as datetimes self.assertTupleEqual( ts.daterange("datetime"), ( datetime(2016, 1, 1, 0, 0, 0), datetime(2016, 1, 1, 0, 0, 19), ), ) # test blank Timeseries ts = Timeseries() self.assertTupleEqual(ts.daterange(), (None, None)) # test invalid format flag self.assertRaises(ValueError, self.ts.daterange, fmt="wrong")
def test_timeseries_datetime_series(self): """ Tests returning a date series converted to date/datetime objects. """ ord_list = datetime(2016, 1, 1).toordinal() + np.arange(20) tstamp_list = datetime(2016, 1, 1).timestamp() + np.arange(20) ts = Timeseries() ts.dseries = ord_list ts.tseries = np.arange(20) # gilding the lily dt_list = [date(2016, 1, 1) + timedelta(days=i) for i in range(20)] self.assertListEqual(ts.datetime_series(), dt_list) ts.frequency = FREQ_SEC ts.dseries = tstamp_list ts.tseries = np.arange(20) dt_list = [ datetime(2016, 1, 1) + timedelta(seconds=i) for i in range(20) ] self.assertListEqual(ts.datetime_series(), dt_list)