def test_iindex_multiples(self): ii = IntervalIndex(start='1/1/10', end='12/31/12', freq='2M') self.assertEquals(ii[0], Interval('1/1/10', '2M')) self.assertEquals(ii[1], Interval('3/1/10', '2M')) self.assertEquals(ii[0].resample('6M'), ii[2].resample('6M')) self.assertEquals(ii[0].resample('A'), ii[2].resample('A')) self.assertEquals(ii[0].resample('M', how='S'), Interval('Jan 2010', '1M')) self.assertEquals(ii[0].resample('M', how='E'), Interval('Feb 2010', '1M')) self.assertEquals(ii[1].resample('M', how='S'), Interval('Mar 2010', '1M')) i = Interval('1/1/2010 12:05:18', '5S') self.assertEquals(i, Interval('1/1/2010 12:05:15', '5S')) i = Interval('1/1/2010 12:05:18', '5S') self.assertEquals(i.resample('1S', how='E'), Interval('1/1/2010 12:05:19', '1S'))
def test_conv_secondly(self): # frequency conversion tests: from Secondly Frequency" ival_S = Interval(freq='S', year=2007, month=1, day=1, hour=0, minute=0, second=0) ival_S_end_of_year = Interval(freq='S', year=2007, month=12, day=31, hour=23, minute=59, second=59) ival_S_end_of_quarter = Interval(freq='S', year=2007, month=3, day=31, hour=23, minute=59, second=59) ival_S_end_of_month = Interval(freq='S', year=2007, month=1, day=31, hour=23, minute=59, second=59) ival_S_end_of_week = Interval(freq='S', year=2007, month=1, day=7, hour=23, minute=59, second=59) ival_S_end_of_day = Interval(freq='S', year=2007, month=1, day=1, hour=23, minute=59, second=59) ival_S_end_of_bus = Interval(freq='S', year=2007, month=1, day=1, hour=23, minute=59, second=59) ival_S_end_of_hour = Interval(freq='S', year=2007, month=1, day=1, hour=0, minute=59, second=59) ival_S_end_of_minute = Interval(freq='S', year=2007, month=1, day=1, hour=0, minute=0, second=59) ival_S_to_A = Interval(freq='A', year=2007) ival_S_to_Q = Interval(freq='Q', year=2007, quarter=1) ival_S_to_M = Interval(freq='M', year=2007, month=1) ival_S_to_W = Interval(freq='WK', year=2007, month=1, day=7) ival_S_to_D = Interval(freq='D', year=2007, month=1, day=1) ival_S_to_B = Interval(freq='B', year=2007, month=1, day=1) ival_S_to_H = Interval(freq='H', year=2007, month=1, day=1, hour=0) ival_S_to_T = Interval(freq='Min', year=2007, month=1, day=1, hour=0, minute=0) assert_equal(ival_S.resample('A'), ival_S_to_A) assert_equal(ival_S_end_of_year.resample('A'), ival_S_to_A) assert_equal(ival_S.resample('Q'), ival_S_to_Q) assert_equal(ival_S_end_of_quarter.resample('Q'), ival_S_to_Q) assert_equal(ival_S.resample('M'), ival_S_to_M) assert_equal(ival_S_end_of_month.resample('M'), ival_S_to_M) assert_equal(ival_S.resample('WK'), ival_S_to_W) assert_equal(ival_S_end_of_week.resample('WK'), ival_S_to_W) assert_equal(ival_S.resample('D'), ival_S_to_D) assert_equal(ival_S_end_of_day.resample('D'), ival_S_to_D) assert_equal(ival_S.resample('B'), ival_S_to_B) assert_equal(ival_S_end_of_bus.resample('B'), ival_S_to_B) assert_equal(ival_S.resample('H'), ival_S_to_H) assert_equal(ival_S_end_of_hour.resample('H'), ival_S_to_H) assert_equal(ival_S.resample('Min'), ival_S_to_T) assert_equal(ival_S_end_of_minute.resample('Min'), ival_S_to_T) assert_equal(ival_S.resample('S'), ival_S)
def test_conv_daily(self): # frequency conversion tests: from Business Frequency" ival_D = Interval(freq='D', year=2007, month=1, day=1) ival_D_end_of_year = Interval(freq='D', year=2007, month=12, day=31) ival_D_end_of_quarter = Interval(freq='D', year=2007, month=3, day=31) ival_D_end_of_month = Interval(freq='D', year=2007, month=1, day=31) ival_D_end_of_week = Interval(freq='D', year=2007, month=1, day=7) ival_D_friday = Interval(freq='D', year=2007, month=1, day=5) ival_D_saturday = Interval(freq='D', year=2007, month=1, day=6) ival_D_sunday = Interval(freq='D', year=2007, month=1, day=7) ival_D_monday = Interval(freq='D', year=2007, month=1, day=8) ival_B_friday = Interval(freq='B', year=2007, month=1, day=5) ival_B_monday = Interval(freq='B', year=2007, month=1, day=8) ival_D_to_A = Interval(freq='A', year=2007) ival_Deoq_to_AJAN = Interval(freq='A-JAN', year=2008) ival_Deoq_to_AJUN = Interval(freq='A-JUN', year=2007) ival_Deoq_to_ADEC = Interval(freq='A-DEC', year=2007) ival_D_to_QEJAN = Interval(freq="Q-JAN", year=2007, quarter=4) ival_D_to_QEJUN = Interval(freq="Q-JUN", year=2007, quarter=3) ival_D_to_QEDEC = Interval(freq="Q-DEC", year=2007, quarter=1) ival_D_to_M = Interval(freq='M', year=2007, month=1) ival_D_to_W = Interval(freq='WK', year=2007, month=1, day=7) ival_D_to_H_start = Interval(freq='H', year=2007, month=1, day=1, hour=0) ival_D_to_H_end = Interval(freq='H', year=2007, month=1, day=1, hour=23) ival_D_to_T_start = Interval(freq='Min', year=2007, month=1, day=1, hour=0, minute=0) ival_D_to_T_end = Interval(freq='Min', year=2007, month=1, day=1, hour=23, minute=59) ival_D_to_S_start = Interval(freq='S', year=2007, month=1, day=1, hour=0, minute=0, second=0) ival_D_to_S_end = Interval(freq='S', year=2007, month=1, day=1, hour=23, minute=59, second=59) assert_equal(ival_D.resample('A'), ival_D_to_A) assert_equal(ival_D_end_of_quarter.resample('A-JAN'), ival_Deoq_to_AJAN) assert_equal(ival_D_end_of_quarter.resample('A-JUN'), ival_Deoq_to_AJUN) assert_equal(ival_D_end_of_quarter.resample('A-DEC'), ival_Deoq_to_ADEC) assert_equal(ival_D_end_of_year.resample('A'), ival_D_to_A) assert_equal(ival_D_end_of_quarter.resample('Q'), ival_D_to_QEDEC) assert_equal(ival_D.resample("Q-JAN"), ival_D_to_QEJAN) assert_equal(ival_D.resample("Q-JUN"), ival_D_to_QEJUN) assert_equal(ival_D.resample("Q-DEC"), ival_D_to_QEDEC) assert_equal(ival_D.resample('M'), ival_D_to_M) assert_equal(ival_D_end_of_month.resample('M'), ival_D_to_M) assert_equal(ival_D.resample('WK'), ival_D_to_W) assert_equal(ival_D_end_of_week.resample('WK'), ival_D_to_W) assert_equal(ival_D_friday.resample('B'), ival_B_friday) assert_equal(ival_D_saturday.resample('B', 'S'), ival_B_friday) assert_equal(ival_D_saturday.resample('B', 'E'), ival_B_monday) assert_equal(ival_D_sunday.resample('B', 'S'), ival_B_friday) assert_equal(ival_D_sunday.resample('B', 'E'), ival_B_monday) assert_equal(ival_D.resample('H', 'S'), ival_D_to_H_start) assert_equal(ival_D.resample('H', 'E'), ival_D_to_H_end) assert_equal(ival_D.resample('Min', 'S'), ival_D_to_T_start) assert_equal(ival_D.resample('Min', 'E'), ival_D_to_T_end) assert_equal(ival_D.resample('S', 'S'), ival_D_to_S_start) assert_equal(ival_D.resample('S', 'E'), ival_D_to_S_end) assert_equal(ival_D.resample('D'), ival_D)
def test_conv_business(self): # frequency conversion tests: from Business Frequency" ival_B = Interval(freq='B', year=2007, month=1, day=1) ival_B_end_of_year = Interval(freq='B', year=2007, month=12, day=31) ival_B_end_of_quarter = Interval(freq='B', year=2007, month=3, day=30) ival_B_end_of_month = Interval(freq='B', year=2007, month=1, day=31) ival_B_end_of_week = Interval(freq='B', year=2007, month=1, day=5) ival_B_to_A = Interval(freq='A', year=2007) ival_B_to_Q = Interval(freq='Q', year=2007, quarter=1) ival_B_to_M = Interval(freq='M', year=2007, month=1) ival_B_to_W = Interval(freq='WK', year=2007, month=1, day=7) ival_B_to_D = Interval(freq='D', year=2007, month=1, day=1) ival_B_to_H_start = Interval(freq='H', year=2007, month=1, day=1, hour=0) ival_B_to_H_end = Interval(freq='H', year=2007, month=1, day=1, hour=23) ival_B_to_T_start = Interval(freq='Min', year=2007, month=1, day=1, hour=0, minute=0) ival_B_to_T_end = Interval(freq='Min', year=2007, month=1, day=1, hour=23, minute=59) ival_B_to_S_start = Interval(freq='S', year=2007, month=1, day=1, hour=0, minute=0, second=0) ival_B_to_S_end = Interval(freq='S', year=2007, month=1, day=1, hour=23, minute=59, second=59) assert_equal(ival_B.resample('A'), ival_B_to_A) assert_equal(ival_B_end_of_year.resample('A'), ival_B_to_A) assert_equal(ival_B.resample('Q'), ival_B_to_Q) assert_equal(ival_B_end_of_quarter.resample('Q'), ival_B_to_Q) assert_equal(ival_B.resample('M'), ival_B_to_M) assert_equal(ival_B_end_of_month.resample('M'), ival_B_to_M) assert_equal(ival_B.resample('WK'), ival_B_to_W) assert_equal(ival_B_end_of_week.resample('WK'), ival_B_to_W) assert_equal(ival_B.resample('D'), ival_B_to_D) assert_equal(ival_B.resample('H', 'S'), ival_B_to_H_start) assert_equal(ival_B.resample('H', 'E'), ival_B_to_H_end) assert_equal(ival_B.resample('Min', 'S'), ival_B_to_T_start) assert_equal(ival_B.resample('Min', 'E'), ival_B_to_T_end) assert_equal(ival_B.resample('S', 'S'), ival_B_to_S_start) assert_equal(ival_B.resample('S', 'E'), ival_B_to_S_end) assert_equal(ival_B.resample('B'), ival_B)
def test_conv_weekly(self): # frequency conversion tests: from Weekly Frequency ival_W = Interval(freq='WK', year=2007, month=1, day=1) ival_WSUN = Interval(freq='WK', year=2007, month=1, day=7) ival_WSAT = Interval(freq='WK-SAT', year=2007, month=1, day=6) ival_WFRI = Interval(freq='WK-FRI', year=2007, month=1, day=5) ival_WTHU = Interval(freq='WK-THU', year=2007, month=1, day=4) ival_WWED = Interval(freq='WK-WED', year=2007, month=1, day=3) ival_WTUE = Interval(freq='WK-TUE', year=2007, month=1, day=2) ival_WMON = Interval(freq='WK-MON', year=2007, month=1, day=1) ival_WSUN_to_D_start = Interval(freq='D', year=2007, month=1, day=1) ival_WSUN_to_D_end = Interval(freq='D', year=2007, month=1, day=7) ival_WSAT_to_D_start = Interval(freq='D', year=2006, month=12, day=31) ival_WSAT_to_D_end = Interval(freq='D', year=2007, month=1, day=6) ival_WFRI_to_D_start = Interval(freq='D', year=2006, month=12, day=30) ival_WFRI_to_D_end = Interval(freq='D', year=2007, month=1, day=5) ival_WTHU_to_D_start = Interval(freq='D', year=2006, month=12, day=29) ival_WTHU_to_D_end = Interval(freq='D', year=2007, month=1, day=4) ival_WWED_to_D_start = Interval(freq='D', year=2006, month=12, day=28) ival_WWED_to_D_end = Interval(freq='D', year=2007, month=1, day=3) ival_WTUE_to_D_start = Interval(freq='D', year=2006, month=12, day=27) ival_WTUE_to_D_end = Interval(freq='D', year=2007, month=1, day=2) ival_WMON_to_D_start = Interval(freq='D', year=2006, month=12, day=26) ival_WMON_to_D_end = Interval(freq='D', year=2007, month=1, day=1) ival_W_end_of_year = Interval(freq='WK', year=2007, month=12, day=31) ival_W_end_of_quarter = Interval(freq='WK', year=2007, month=3, day=31) ival_W_end_of_month = Interval(freq='WK', year=2007, month=1, day=31) ival_W_to_A = Interval(freq='A', year=2007) ival_W_to_Q = Interval(freq='Q', year=2007, quarter=1) ival_W_to_M = Interval(freq='M', year=2007, month=1) if Interval(freq='D', year=2007, month=12, day=31).weekday == 6: ival_W_to_A_end_of_year = Interval(freq='A', year=2007) else: ival_W_to_A_end_of_year = Interval(freq='A', year=2008) if Interval(freq='D', year=2007, month=3, day=31).weekday == 6: ival_W_to_Q_end_of_quarter = Interval(freq='Q', year=2007, quarter=1) else: ival_W_to_Q_end_of_quarter = Interval(freq='Q', year=2007, quarter=2) if Interval(freq='D', year=2007, month=1, day=31).weekday == 6: ival_W_to_M_end_of_month = Interval(freq='M', year=2007, month=1) else: ival_W_to_M_end_of_month = Interval(freq='M', year=2007, month=2) ival_W_to_B_start = Interval(freq='B', year=2007, month=1, day=1) ival_W_to_B_end = Interval(freq='B', year=2007, month=1, day=5) ival_W_to_D_start = Interval(freq='D', year=2007, month=1, day=1) ival_W_to_D_end = Interval(freq='D', year=2007, month=1, day=7) ival_W_to_H_start = Interval(freq='H', year=2007, month=1, day=1, hour=0) ival_W_to_H_end = Interval(freq='H', year=2007, month=1, day=7, hour=23) ival_W_to_T_start = Interval(freq='Min', year=2007, month=1, day=1, hour=0, minute=0) ival_W_to_T_end = Interval(freq='Min', year=2007, month=1, day=7, hour=23, minute=59) ival_W_to_S_start = Interval(freq='S', year=2007, month=1, day=1, hour=0, minute=0, second=0) ival_W_to_S_end = Interval(freq='S', year=2007, month=1, day=7, hour=23, minute=59, second=59) assert_equal(ival_W.resample('A'), ival_W_to_A) assert_equal(ival_W_end_of_year.resample('A'), ival_W_to_A_end_of_year) assert_equal(ival_W.resample('Q'), ival_W_to_Q) assert_equal(ival_W_end_of_quarter.resample('Q'), ival_W_to_Q_end_of_quarter) assert_equal(ival_W.resample('M'), ival_W_to_M) assert_equal(ival_W_end_of_month.resample('M'), ival_W_to_M_end_of_month) assert_equal(ival_W.resample('B', 'S'), ival_W_to_B_start) assert_equal(ival_W.resample('B', 'E'), ival_W_to_B_end) assert_equal(ival_W.resample('D', 'S'), ival_W_to_D_start) assert_equal(ival_W.resample('D', 'E'), ival_W_to_D_end) assert_equal(ival_WSUN.resample('D', 'S'), ival_WSUN_to_D_start) assert_equal(ival_WSUN.resample('D', 'E'), ival_WSUN_to_D_end) assert_equal(ival_WSAT.resample('D', 'S'), ival_WSAT_to_D_start) assert_equal(ival_WSAT.resample('D', 'E'), ival_WSAT_to_D_end) assert_equal(ival_WFRI.resample('D', 'S'), ival_WFRI_to_D_start) assert_equal(ival_WFRI.resample('D', 'E'), ival_WFRI_to_D_end) assert_equal(ival_WTHU.resample('D', 'S'), ival_WTHU_to_D_start) assert_equal(ival_WTHU.resample('D', 'E'), ival_WTHU_to_D_end) assert_equal(ival_WWED.resample('D', 'S'), ival_WWED_to_D_start) assert_equal(ival_WWED.resample('D', 'E'), ival_WWED_to_D_end) assert_equal(ival_WTUE.resample('D', 'S'), ival_WTUE_to_D_start) assert_equal(ival_WTUE.resample('D', 'E'), ival_WTUE_to_D_end) assert_equal(ival_WMON.resample('D', 'S'), ival_WMON_to_D_start) assert_equal(ival_WMON.resample('D', 'E'), ival_WMON_to_D_end) assert_equal(ival_W.resample('H', 'S'), ival_W_to_H_start) assert_equal(ival_W.resample('H', 'E'), ival_W_to_H_end) assert_equal(ival_W.resample('Min', 'S'), ival_W_to_T_start) assert_equal(ival_W.resample('Min', 'E'), ival_W_to_T_end) assert_equal(ival_W.resample('S', 'S'), ival_W_to_S_start) assert_equal(ival_W.resample('S', 'E'), ival_W_to_S_end) assert_equal(ival_W.resample('WK'), ival_W)
def test_conv_monthly(self): # frequency conversion tests: from Monthly Frequency ival_M = Interval(freq='M', year=2007, month=1) ival_M_end_of_year = Interval(freq='M', year=2007, month=12) ival_M_end_of_quarter = Interval(freq='M', year=2007, month=3) ival_M_to_A = Interval(freq='A', year=2007) ival_M_to_Q = Interval(freq='Q', year=2007, quarter=1) ival_M_to_W_start = Interval(freq='WK', year=2007, month=1, day=1) ival_M_to_W_end = Interval(freq='WK', year=2007, month=1, day=31) ival_M_to_B_start = Interval(freq='B', year=2007, month=1, day=1) ival_M_to_B_end = Interval(freq='B', year=2007, month=1, day=31) ival_M_to_D_start = Interval(freq='D', year=2007, month=1, day=1) ival_M_to_D_end = Interval(freq='D', year=2007, month=1, day=31) ival_M_to_H_start = Interval(freq='H', year=2007, month=1, day=1, hour=0) ival_M_to_H_end = Interval(freq='H', year=2007, month=1, day=31, hour=23) ival_M_to_T_start = Interval(freq='Min', year=2007, month=1, day=1, hour=0, minute=0) ival_M_to_T_end = Interval(freq='Min', year=2007, month=1, day=31, hour=23, minute=59) ival_M_to_S_start = Interval(freq='S', year=2007, month=1, day=1, hour=0, minute=0, second=0) ival_M_to_S_end = Interval(freq='S', year=2007, month=1, day=31, hour=23, minute=59, second=59) assert_equal(ival_M.resample('A'), ival_M_to_A) assert_equal(ival_M_end_of_year.resample('A'), ival_M_to_A) assert_equal(ival_M.resample('Q'), ival_M_to_Q) assert_equal(ival_M_end_of_quarter.resample('Q'), ival_M_to_Q) assert_equal(ival_M.resample('WK', 'S'), ival_M_to_W_start) assert_equal(ival_M.resample('WK', 'E'), ival_M_to_W_end) assert_equal(ival_M.resample('B', 'S'), ival_M_to_B_start) assert_equal(ival_M.resample('B', 'E'), ival_M_to_B_end) assert_equal(ival_M.resample('D', 'S'), ival_M_to_D_start) assert_equal(ival_M.resample('D', 'E'), ival_M_to_D_end) assert_equal(ival_M.resample('H', 'S'), ival_M_to_H_start) assert_equal(ival_M.resample('H', 'E'), ival_M_to_H_end) assert_equal(ival_M.resample('Min', 'S'), ival_M_to_T_start) assert_equal(ival_M.resample('Min', 'E'), ival_M_to_T_end) assert_equal(ival_M.resample('S', 'S'), ival_M_to_S_start) assert_equal(ival_M.resample('S', 'E'), ival_M_to_S_end) assert_equal(ival_M.resample('M'), ival_M)
def test_conv_quarterly(self): # frequency conversion tests: from Quarterly Frequency ival_Q = Interval(freq='Q', year=2007, quarter=1) ival_Q_end_of_year = Interval(freq='Q', year=2007, quarter=4) ival_QEJAN = Interval(freq="Q-JAN", year=2007, quarter=1) ival_QEJUN = Interval(freq="Q-JUN", year=2007, quarter=1) ival_Q_to_A = Interval(freq='A', year=2007) ival_Q_to_M_start = Interval(freq='M', year=2007, month=1) ival_Q_to_M_end = Interval(freq='M', year=2007, month=3) ival_Q_to_W_start = Interval(freq='WK', year=2007, month=1, day=1) ival_Q_to_W_end = Interval(freq='WK', year=2007, month=3, day=31) ival_Q_to_B_start = Interval(freq='B', year=2007, month=1, day=1) ival_Q_to_B_end = Interval(freq='B', year=2007, month=3, day=30) ival_Q_to_D_start = Interval(freq='D', year=2007, month=1, day=1) ival_Q_to_D_end = Interval(freq='D', year=2007, month=3, day=31) ival_Q_to_H_start = Interval(freq='H', year=2007, month=1, day=1, hour=0) ival_Q_to_H_end = Interval(freq='H', year=2007, month=3, day=31, hour=23) ival_Q_to_T_start = Interval(freq='Min', year=2007, month=1, day=1, hour=0, minute=0) ival_Q_to_T_end = Interval(freq='Min', year=2007, month=3, day=31, hour=23, minute=59) ival_Q_to_S_start = Interval(freq='S', year=2007, month=1, day=1, hour=0, minute=0, second=0) ival_Q_to_S_end = Interval(freq='S', year=2007, month=3, day=31, hour=23, minute=59, second=59) ival_QEJAN_to_D_start = Interval(freq='D', year=2006, month=2, day=1) ival_QEJAN_to_D_end = Interval(freq='D', year=2006, month=4, day=30) ival_QEJUN_to_D_start = Interval(freq='D', year=2006, month=7, day=1) ival_QEJUN_to_D_end = Interval(freq='D', year=2006, month=9, day=30) assert_equal(ival_Q.resample('A'), ival_Q_to_A) assert_equal(ival_Q_end_of_year.resample('A'), ival_Q_to_A) assert_equal(ival_Q.resample('M', 'S'), ival_Q_to_M_start) assert_equal(ival_Q.resample('M', 'E'), ival_Q_to_M_end) assert_equal(ival_Q.resample('WK', 'S'), ival_Q_to_W_start) assert_equal(ival_Q.resample('WK', 'E'), ival_Q_to_W_end) assert_equal(ival_Q.resample('B', 'S'), ival_Q_to_B_start) assert_equal(ival_Q.resample('B', 'E'), ival_Q_to_B_end) assert_equal(ival_Q.resample('D', 'S'), ival_Q_to_D_start) assert_equal(ival_Q.resample('D', 'E'), ival_Q_to_D_end) assert_equal(ival_Q.resample('H', 'S'), ival_Q_to_H_start) assert_equal(ival_Q.resample('H', 'E'), ival_Q_to_H_end) assert_equal(ival_Q.resample('Min', 'S'), ival_Q_to_T_start) assert_equal(ival_Q.resample('Min', 'E'), ival_Q_to_T_end) assert_equal(ival_Q.resample('S', 'S'), ival_Q_to_S_start) assert_equal(ival_Q.resample('S', 'E'), ival_Q_to_S_end) assert_equal(ival_QEJAN.resample('D', 'S'), ival_QEJAN_to_D_start) assert_equal(ival_QEJAN.resample('D', 'E'), ival_QEJAN_to_D_end) assert_equal(ival_QEJUN.resample('D', 'S'), ival_QEJUN_to_D_start) assert_equal(ival_QEJUN.resample('D', 'E'), ival_QEJUN_to_D_end) assert_equal(ival_Q.resample('Q'), ival_Q)
def test_conv_annual(self): # frequency conversion tests: from Annual Frequency ival_A = Interval(freq='A', year=2007) ival_AJAN = Interval(freq="A-JAN", year=2007) ival_AJUN = Interval(freq="A-JUN", year=2007) ival_ANOV = Interval(freq="A-NOV", year=2007) ival_A_to_Q_start = Interval(freq='Q', year=2007, quarter=1) ival_A_to_Q_end = Interval(freq='Q', year=2007, quarter=4) ival_A_to_M_start = Interval(freq='M', year=2007, month=1) ival_A_to_M_end = Interval(freq='M', year=2007, month=12) ival_A_to_W_start = Interval(freq='WK', year=2007, month=1, day=1) ival_A_to_W_end = Interval(freq='WK', year=2007, month=12, day=31) ival_A_to_B_start = Interval(freq='B', year=2007, month=1, day=1) ival_A_to_B_end = Interval(freq='B', year=2007, month=12, day=31) ival_A_to_D_start = Interval(freq='D', year=2007, month=1, day=1) ival_A_to_D_end = Interval(freq='D', year=2007, month=12, day=31) ival_A_to_H_start = Interval(freq='H', year=2007, month=1, day=1, hour=0) ival_A_to_H_end = Interval(freq='H', year=2007, month=12, day=31, hour=23) ival_A_to_T_start = Interval(freq='Min', year=2007, month=1, day=1, hour=0, minute=0) ival_A_to_T_end = Interval(freq='Min', year=2007, month=12, day=31, hour=23, minute=59) ival_A_to_S_start = Interval(freq='S', year=2007, month=1, day=1, hour=0, minute=0, second=0) ival_A_to_S_end = Interval(freq='S', year=2007, month=12, day=31, hour=23, minute=59, second=59) ival_AJAN_to_D_end = Interval(freq='D', year=2007, month=1, day=31) ival_AJAN_to_D_start = Interval(freq='D', year=2006, month=2, day=1) ival_AJUN_to_D_end = Interval(freq='D', year=2007, month=6, day=30) ival_AJUN_to_D_start = Interval(freq='D', year=2006, month=7, day=1) ival_ANOV_to_D_end = Interval(freq='D', year=2007, month=11, day=30) ival_ANOV_to_D_start = Interval(freq='D', year=2006, month=12, day=1) assert_equal(ival_A.resample('Q', 'S'), ival_A_to_Q_start) assert_equal(ival_A.resample('Q', 'E'), ival_A_to_Q_end) assert_equal(ival_A.resample('M', 'S'), ival_A_to_M_start) assert_equal(ival_A.resample('M', 'E'), ival_A_to_M_end) assert_equal(ival_A.resample('WK', 'S'), ival_A_to_W_start) assert_equal(ival_A.resample('WK', 'E'), ival_A_to_W_end) assert_equal(ival_A.resample('B', 'S'), ival_A_to_B_start) assert_equal(ival_A.resample('B', 'E'), ival_A_to_B_end) assert_equal(ival_A.resample('D', 'S'), ival_A_to_D_start) assert_equal(ival_A.resample('D', 'E'), ival_A_to_D_end) assert_equal(ival_A.resample('H', 'S'), ival_A_to_H_start) assert_equal(ival_A.resample('H', 'E'), ival_A_to_H_end) assert_equal(ival_A.resample('Min', 'S'), ival_A_to_T_start) assert_equal(ival_A.resample('Min', 'E'), ival_A_to_T_end) assert_equal(ival_A.resample('S', 'S'), ival_A_to_S_start) assert_equal(ival_A.resample('S', 'E'), ival_A_to_S_end) assert_equal(ival_AJAN.resample('D', 'S'), ival_AJAN_to_D_start) assert_equal(ival_AJAN.resample('D', 'E'), ival_AJAN_to_D_end) assert_equal(ival_AJUN.resample('D', 'S'), ival_AJUN_to_D_start) assert_equal(ival_AJUN.resample('D', 'E'), ival_AJUN_to_D_end) assert_equal(ival_ANOV.resample('D', 'S'), ival_ANOV_to_D_start) assert_equal(ival_ANOV.resample('D', 'E'), ival_ANOV_to_D_end) assert_equal(ival_A.resample('A'), ival_A)
def test_interval_constructor(self): i1 = Interval('1/1/2005', freq='M') i2 = Interval('Jan 2005') self.assertEquals(i1, i2) i1 = Interval('2005', freq='A') i2 = Interval('2005') i3 = Interval('2005', freq='a') self.assertEquals(i1, i2) self.assertEquals(i1, i3) i4 = Interval('2005', freq='M') i5 = Interval('2005', freq='m') self.assert_(i1 != i4) self.assertEquals(i4, i5) i1 = Interval.now('Q') i2 = Interval(datetime.now(), freq='Q') i3 = Interval.now('q') self.assertEquals(i1, i2) self.assertEquals(i1, i3) # Biz day construction, roll forward if non-weekday i1 = Interval('3/10/12', freq='B') i2 = Interval('3/12/12', freq='D') self.assertEquals(i1, i2.resample('B')) i3 = Interval('3/10/12', freq='b') self.assertEquals(i1, i3) i1 = Interval(year=2005, quarter=1, freq='Q') i2 = Interval('1/1/2005', freq='Q') self.assertEquals(i1, i2) i1 = Interval(year=2005, quarter=3, freq='Q') i2 = Interval('9/1/2005', freq='Q') self.assertEquals(i1, i2) i1 = Interval(year=2005, month=3, day=1, freq='D') i2 = Interval('3/1/2005', freq='D') self.assertEquals(i1, i2) i3 = Interval(year=2005, month=3, day=1, freq='d') self.assertEquals(i1, i3) i1 = Interval(year=2012, month=3, day=10, freq='B') i2 = Interval('3/12/12', freq='B') self.assertEquals(i1, i2) i1 = Interval('2005Q1') i2 = Interval(year=2005, quarter=1, freq='Q') i3 = Interval('2005q1') self.assertEquals(i1, i2) self.assertEquals(i1, i3) i1 = Interval('05Q1') self.assertEquals(i1, i2) lower = Interval('05q1') self.assertEquals(i1, lower) i1 = Interval('1Q2005') self.assertEquals(i1, i2) lower = Interval('1q2005') self.assertEquals(i1, lower) i1 = Interval('1Q05') self.assertEquals(i1, i2) lower = Interval('1q05') self.assertEquals(i1, lower) i1 = Interval('4Q1984') self.assertEquals(i1.year, 1984) lower = Interval('4q1984') self.assertEquals(i1, lower) i1 = Interval('1982', freq='min') i2 = Interval('1982', freq='MIN') self.assertEquals(i1, i2) i2 = Interval('1982', freq=('Min', 1)) self.assertEquals(i1, i2)
def test_to_timestamp(self): intv = Interval('1982', freq='A') start_ts = intv.to_timestamp(which_end='S') aliases = ['s', 'StarT', 'BEGIn'] for a in aliases: self.assertEquals(start_ts, intv.to_timestamp(which_end=a)) end_ts = intv.to_timestamp(which_end='E') aliases = ['e', 'end', 'FINIsH'] for a in aliases: self.assertEquals(end_ts, intv.to_timestamp(which_end=a)) from_lst = ['A', 'Q', 'M', 'W', 'B', 'D', 'H', 'Min', 'S'] for i, fcode in enumerate(from_lst): intv = Interval('1982', freq=fcode) result = intv.to_timestamp().to_interval(fcode) self.assertEquals(result, intv) self.assertEquals(intv.start_time(), intv.to_timestamp('S')) self.assertEquals(intv.end_time(), intv.to_timestamp('E'))