[Scipy-svn] r2563 - trunk/Lib/sandbox/timeseries/tests

scipy-svn at scipy.org scipy-svn at scipy.org
Mon Jan 15 12:57:26 CST 2007


Author: mattknox_ca
Date: 2007-01-15 12:57:21 -0600 (Mon, 15 Jan 2007)
New Revision: 2563

Modified:
   trunk/Lib/sandbox/timeseries/tests/test_dates.py
Log:
added tests for frequency conversion


Modified: trunk/Lib/sandbox/timeseries/tests/test_dates.py
===================================================================
--- trunk/Lib/sandbox/timeseries/tests/test_dates.py	2007-01-15 18:55:50 UTC (rev 2562)
+++ trunk/Lib/sandbox/timeseries/tests/test_dates.py	2007-01-15 18:57:21 UTC (rev 2563)
@@ -26,9 +26,10 @@
 import maskedarray.testutils
 from maskedarray.testutils import assert_equal, assert_array_equal
 
-import tdates
+from timeseries import tdates
+from timeseries import tcore
 reload(tdates)
-from tdates import date_array_fromlist, Date, DateArray, mxDFromString
+from timeseries.tdates import date_array_fromlist, Date, DateArray, mxDFromString
 
 class test_creation(NumpyTestCase):
     "Base test class for MaskedArrays."
@@ -103,7 +104,407 @@
         odates = date_array_fromlist(dobj)
         assert_equal(dates,odates)
 
+    def test_consistent_value(self):
+        "Tests that values don't get mutated when constructing dates from a value"
+        freqs = [x for x in list(tcore.fmtfreq_dict) if x != 'U']
+        for f in freqs:
+            today = tdates.thisday(f)
+            assert(tdates.Date(freq=f, value=today.value) == today)
 
+
+class test_freq_conversion(NumpyTestCase):
+    "Test frequency conversion of date objects"
+    
+    def __init__(self, *args, **kwds):
+        NumpyTestCase.__init__(self, *args, **kwds)       
+        
+    def test_conv_annual(self):
+        "frequency conversion tests: from Annual Frequency"
+
+        date_A = tdates.Date(freq='A', year=2007)
+        date_A_to_Q_before = tdates.Date(freq='Q', year=2007, quarter=1)
+        date_A_to_Q_after = tdates.Date(freq='Q', year=2007, quarter=4)
+        date_A_to_M_before = tdates.Date(freq='M', year=2007, month=1)
+        date_A_to_M_after = tdates.Date(freq='M', year=2007, month=12)
+        date_A_to_W_before = tdates.Date(freq='W', year=2007, month=1, day=1)
+        date_A_to_W_after = tdates.Date(freq='W', year=2007, month=12, day=31)
+        date_A_to_B_before = tdates.Date(freq='B', year=2007, month=1, day=1)
+        date_A_to_B_after = tdates.Date(freq='B', year=2007, month=12, day=31)
+        date_A_to_D_before = tdates.Date(freq='D', year=2007, month=1, day=1)
+        date_A_to_D_after = tdates.Date(freq='D', year=2007, month=12, day=31)
+        date_A_to_H_before = tdates.Date(freq='H', year=2007, month=1, day=1, hours=0)
+        date_A_to_H_after = tdates.Date(freq='H', year=2007, month=12, day=31, hours=23)
+        date_A_to_T_before = tdates.Date(freq='T', year=2007, month=1, day=1, hours=0, minutes=0)
+        date_A_to_T_after = tdates.Date(freq='T', year=2007, month=12, day=31, hours=23, minutes=59)
+        date_A_to_S_before = tdates.Date(freq='S', year=2007, month=1, day=1, hours=0, minutes=0, seconds=0)
+        date_A_to_S_after = tdates.Date(freq='S', year=2007, month=12, day=31, hours=23, minutes=59, seconds=59)
+        
+        assert(date_A.asfreq('Q', "BEFORE") == date_A_to_Q_before)
+        assert(date_A.asfreq('Q', "AFTER") == date_A_to_Q_after)
+        assert(date_A.asfreq('M', "BEFORE") == date_A_to_M_before)
+        assert(date_A.asfreq('M', "AFTER") == date_A_to_M_after)
+        assert(date_A.asfreq('W', "BEFORE") == date_A_to_W_before)
+        assert(date_A.asfreq('W', "AFTER") == date_A_to_W_after)
+        assert(date_A.asfreq('B', "BEFORE") == date_A_to_B_before)
+        assert(date_A.asfreq('B', "AFTER") == date_A_to_B_after)
+        assert(date_A.asfreq('D', "BEFORE") == date_A_to_D_before)
+        assert(date_A.asfreq('D', "AFTER") == date_A_to_D_after)
+        assert(date_A.asfreq('H', "BEFORE") == date_A_to_H_before)
+        assert(date_A.asfreq('H', "AFTER") == date_A_to_H_after)
+        assert(date_A.asfreq('T', "BEFORE") == date_A_to_T_before)
+        assert(date_A.asfreq('T', "AFTER") == date_A_to_T_after)
+        assert(date_A.asfreq('S', "BEFORE") == date_A_to_S_before)
+        assert(date_A.asfreq('S', "AFTER") == date_A_to_S_after)
+
+        
+    def test_conv_quarterly(self):
+        "frequency conversion tests: from Quarterly Frequency"
+
+        date_Q = tdates.Date(freq='Q', year=2007, quarter=1)
+        date_Q_end_of_year = tdates.Date(freq='Q', year=2007, quarter=4)
+        date_Q_to_A = tdates.Date(freq='A', year=2007)
+        date_Q_to_M_before = tdates.Date(freq='M', year=2007, month=1)
+        date_Q_to_M_after = tdates.Date(freq='M', year=2007, month=3)
+        date_Q_to_W_before = tdates.Date(freq='W', year=2007, month=1, day=1)
+        date_Q_to_W_after = tdates.Date(freq='W', year=2007, month=3, day=31)
+        date_Q_to_B_before = tdates.Date(freq='B', year=2007, month=1, day=1)
+        date_Q_to_B_after = tdates.Date(freq='B', year=2007, month=3, day=30)
+        date_Q_to_D_before = tdates.Date(freq='D', year=2007, month=1, day=1)
+        date_Q_to_D_after = tdates.Date(freq='D', year=2007, month=3, day=31)
+        date_Q_to_H_before = tdates.Date(freq='H', year=2007, month=1, day=1, hours=0)
+        date_Q_to_H_after = tdates.Date(freq='H', year=2007, month=3, day=31, hours=23)
+        date_Q_to_T_before = tdates.Date(freq='T', year=2007, month=1, day=1, hours=0, minutes=0)
+        date_Q_to_T_after = tdates.Date(freq='T', year=2007, month=3, day=31, hours=23, minutes=59)
+        date_Q_to_S_before = tdates.Date(freq='S', year=2007, month=1, day=1, hours=0, minutes=0, seconds=0)
+        date_Q_to_S_after = tdates.Date(freq='S', year=2007, month=3, day=31, hours=23, minutes=59, seconds=59)
+        
+        assert(date_Q.asfreq('A') == date_Q_to_A)
+        assert(date_Q_end_of_year.asfreq('A') == date_Q_to_A)
+        
+        assert(date_Q.asfreq('M', "BEFORE") == date_Q_to_M_before)
+        assert(date_Q.asfreq('M', "AFTER") == date_Q_to_M_after)
+        assert(date_Q.asfreq('W', "BEFORE") == date_Q_to_W_before)
+        assert(date_Q.asfreq('W', "AFTER") == date_Q_to_W_after)
+        assert(date_Q.asfreq('B', "BEFORE") == date_Q_to_B_before)
+        assert(date_Q.asfreq('B', "AFTER") == date_Q_to_B_after)
+        assert(date_Q.asfreq('D', "BEFORE") == date_Q_to_D_before)
+        assert(date_Q.asfreq('D', "AFTER") == date_Q_to_D_after)
+        assert(date_Q.asfreq('H', "BEFORE") == date_Q_to_H_before)
+        assert(date_Q.asfreq('H', "AFTER") == date_Q_to_H_after)
+        assert(date_Q.asfreq('T', "BEFORE") == date_Q_to_T_before)
+        assert(date_Q.asfreq('T', "AFTER") == date_Q_to_T_after)
+        assert(date_Q.asfreq('S', "BEFORE") == date_Q_to_S_before)
+        assert(date_Q.asfreq('S', "AFTER") == date_Q_to_S_after)
+        
+
+    def test_conv_monthly(self):
+        "frequency conversion tests: from Monthly Frequency"
+        
+        date_M = tdates.Date(freq='M', year=2007, month=1)
+        date_M_end_of_year = tdates.Date(freq='M', year=2007, month=12)
+        date_M_end_of_quarter = tdates.Date(freq='M', year=2007, month=3)
+        date_M_to_A = tdates.Date(freq='A', year=2007)
+        date_M_to_Q = tdates.Date(freq='Q', year=2007, quarter=1)
+        date_M_to_W_before = tdates.Date(freq='W', year=2007, month=1, day=1)
+        date_M_to_W_after = tdates.Date(freq='W', year=2007, month=1, day=31)
+        date_M_to_B_before = tdates.Date(freq='B', year=2007, month=1, day=1)
+        date_M_to_B_after = tdates.Date(freq='B', year=2007, month=1, day=31)
+        date_M_to_D_before = tdates.Date(freq='D', year=2007, month=1, day=1)
+        date_M_to_D_after = tdates.Date(freq='D', year=2007, month=1, day=31)
+        date_M_to_H_before = tdates.Date(freq='H', year=2007, month=1, day=1, hours=0)
+        date_M_to_H_after = tdates.Date(freq='H', year=2007, month=1, day=31, hours=23)
+        date_M_to_T_before = tdates.Date(freq='T', year=2007, month=1, day=1, hours=0, minutes=0)
+        date_M_to_T_after = tdates.Date(freq='T', year=2007, month=1, day=31, hours=23, minutes=59)
+        date_M_to_S_before = tdates.Date(freq='S', year=2007, month=1, day=1, hours=0, minutes=0, seconds=0)
+        date_M_to_S_after = tdates.Date(freq='S', year=2007, month=1, day=31, hours=23, minutes=59, seconds=59)
+        
+        assert(date_M.asfreq('A') == date_M_to_A)
+        assert(date_M_end_of_year.asfreq('A') == date_M_to_A)
+        assert(date_M.asfreq('Q') == date_M_to_Q)
+        assert(date_M_end_of_quarter.asfreq('Q') == date_M_to_Q)
+
+        assert(date_M.asfreq('W', "BEFORE") == date_M_to_W_before)
+        assert(date_M.asfreq('W', "AFTER") == date_M_to_W_after)
+        assert(date_M.asfreq('B', "BEFORE") == date_M_to_B_before)
+        assert(date_M.asfreq('B', "AFTER") == date_M_to_B_after)
+        assert(date_M.asfreq('D', "BEFORE") == date_M_to_D_before)
+        assert(date_M.asfreq('D', "AFTER") == date_M_to_D_after)
+        assert(date_M.asfreq('H', "BEFORE") == date_M_to_H_before)
+        assert(date_M.asfreq('H', "AFTER") == date_M_to_H_after)
+        assert(date_M.asfreq('T', "BEFORE") == date_M_to_T_before)
+        assert(date_M.asfreq('T', "AFTER") == date_M_to_T_after)
+        assert(date_M.asfreq('S', "BEFORE") == date_M_to_S_before)
+        assert(date_M.asfreq('S', "AFTER") == date_M_to_S_after)
+
+        
+    def test_conv_weekly(self):
+        "frequency conversion tests: from Weekly Frequency"
+        
+        date_W = tdates.Date(freq='W', year=2007, month=1, day=1)
+        date_W_end_of_year = tdates.Date(freq='W', year=2007, month=12, day=31)
+        date_W_end_of_quarter = tdates.Date(freq='W', year=2007, month=3, day=31)
+        date_W_end_of_month = tdates.Date(freq='W', year=2007, month=1, day=31)
+        date_W_to_A = tdates.Date(freq='A', year=2007)
+        date_W_to_Q = tdates.Date(freq='Q', year=2007, quarter=1)
+        date_W_to_M = tdates.Date(freq='M', year=2007, month=1)
+
+        if tdates.Date(freq='D', year=2007, month=12, day=31).day_of_week() == 6:
+            date_W_to_A_end_of_year = tdates.Date(freq='A', year=2007)
+        else:
+            date_W_to_A_end_of_year = tdates.Date(freq='A', year=2008)
+
+        if tdates.Date(freq='D', year=2007, month=3, day=31).day_of_week() == 6:
+            date_W_to_Q_end_of_quarter = tdates.Date(freq='Q', year=2007, quarter=1)
+        else:
+            date_W_to_Q_end_of_quarter = tdates.Date(freq='Q', year=2007, quarter=2)
+
+        if tdates.Date(freq='D', year=2007, month=1, day=31).day_of_week() == 6:
+            date_W_to_M_end_of_month = tdates.Date(freq='M', year=2007, month=1)
+        else:
+            date_W_to_M_end_of_month = tdates.Date(freq='M', year=2007, month=2)
+
+        date_W_to_B_before = tdates.Date(freq='B', year=2007, month=1, day=1)
+        date_W_to_B_after = tdates.Date(freq='B', year=2007, month=1, day=5)
+        date_W_to_D_before = tdates.Date(freq='D', year=2007, month=1, day=1)
+        date_W_to_D_after = tdates.Date(freq='D', year=2007, month=1, day=7)
+        date_W_to_H_before = tdates.Date(freq='H', year=2007, month=1, day=1, hours=0)
+        date_W_to_H_after = tdates.Date(freq='H', year=2007, month=1, day=7, hours=23)
+        date_W_to_T_before = tdates.Date(freq='T', year=2007, month=1, day=1, hours=0, minutes=0)
+        date_W_to_T_after = tdates.Date(freq='T', year=2007, month=1, day=7, hours=23, minutes=59)
+        date_W_to_S_before = tdates.Date(freq='S', year=2007, month=1, day=1, hours=0, minutes=0, seconds=0)
+        date_W_to_S_after = tdates.Date(freq='S', year=2007, month=1, day=7, hours=23, minutes=59, seconds=59)
+        
+        assert(date_W.asfreq('A') == date_W_to_A)
+        assert(date_W_end_of_year.asfreq('A') == date_W_to_A_end_of_year)
+        assert(date_W.asfreq('Q') == date_W_to_Q)
+        assert(date_W_end_of_quarter.asfreq('Q') == date_W_to_Q_end_of_quarter)
+        assert(date_W.asfreq('M') == date_W_to_M)
+        assert(date_W_end_of_month.asfreq('M') == date_W_to_M_end_of_month)
+
+        assert(date_W.asfreq('B', "BEFORE") == date_W_to_B_before)
+        assert(date_W.asfreq('B', "AFTER") == date_W_to_B_after)
+        assert(date_W.asfreq('D', "BEFORE") == date_W_to_D_before)
+        assert(date_W.asfreq('D', "AFTER") == date_W_to_D_after)
+        assert(date_W.asfreq('H', "BEFORE") == date_W_to_H_before)
+        assert(date_W.asfreq('H', "AFTER") == date_W_to_H_after)
+        assert(date_W.asfreq('T', "BEFORE") == date_W_to_T_before)
+        assert(date_W.asfreq('T', "AFTER") == date_W_to_T_after)
+        assert(date_W.asfreq('S', "BEFORE") == date_W_to_S_before)
+        assert(date_W.asfreq('S', "AFTER") == date_W_to_S_after)
+        
+    def test_conv_business(self):
+        "frequency conversion tests: from Business Frequency"
+        
+        date_B = tdates.Date(freq='B', year=2007, month=1, day=1)
+        date_B_end_of_year = tdates.Date(freq='B', year=2007, month=12, day=31)
+        date_B_end_of_quarter = tdates.Date(freq='B', year=2007, month=3, day=30)
+        date_B_end_of_month = tdates.Date(freq='B', year=2007, month=1, day=31)
+        date_B_end_of_week = tdates.Date(freq='B', year=2007, month=1, day=5)
+        
+        date_B_to_A = tdates.Date(freq='A', year=2007)
+        date_B_to_Q = tdates.Date(freq='Q', year=2007, quarter=1)
+        date_B_to_M = tdates.Date(freq='M', year=2007, month=1)
+        date_B_to_W = tdates.Date(freq='W', year=2007, month=1, day=7)
+        date_B_to_D = tdates.Date(freq='D', year=2007, month=1, day=1)
+        date_B_to_H_before = tdates.Date(freq='H', year=2007, month=1, day=1, hours=0)
+        date_B_to_H_after = tdates.Date(freq='H', year=2007, month=1, day=1, hours=23)
+        date_B_to_T_before = tdates.Date(freq='T', year=2007, month=1, day=1, hours=0, minutes=0)
+        date_B_to_T_after = tdates.Date(freq='T', year=2007, month=1, day=1, hours=23, minutes=59)
+        date_B_to_S_before = tdates.Date(freq='S', year=2007, month=1, day=1, hours=0, minutes=0, seconds=0)
+        date_B_to_S_after = tdates.Date(freq='S', year=2007, month=1, day=1, hours=23, minutes=59, seconds=59)
+        
+        assert(date_B.asfreq('A') == date_B_to_A)
+        assert(date_B_end_of_year.asfreq('A') == date_B_to_A)
+        assert(date_B.asfreq('Q') == date_B_to_Q)
+        assert(date_B_end_of_quarter.asfreq('Q') == date_B_to_Q)
+        assert(date_B.asfreq('M') == date_B_to_M)
+        assert(date_B_end_of_month.asfreq('M') == date_B_to_M)
+        assert(date_B.asfreq('W') == date_B_to_W)
+        assert(date_B_end_of_week.asfreq('W') == date_B_to_W)
+
+        assert(date_B.asfreq('D') == date_B_to_D)
+
+        assert(date_B.asfreq('H', "BEFORE") == date_B_to_H_before)
+        assert(date_B.asfreq('H', "AFTER") == date_B_to_H_after)
+        assert(date_B.asfreq('T', "BEFORE") == date_B_to_T_before)
+        assert(date_B.asfreq('T', "AFTER") == date_B_to_T_after)
+        assert(date_B.asfreq('S', "BEFORE") == date_B_to_S_before)
+        assert(date_B.asfreq('S', "AFTER") == date_B_to_S_after)
+
+    def test_conv_daily(self):
+        "frequency conversion tests: from Business Frequency"
+        
+        date_D = tdates.Date(freq='D', year=2007, month=1, day=1)
+        date_D_end_of_year = tdates.Date(freq='D', year=2007, month=12, day=31)
+        date_D_end_of_quarter = tdates.Date(freq='D', year=2007, month=3, day=31)
+        date_D_end_of_month = tdates.Date(freq='D', year=2007, month=1, day=31)
+        date_D_end_of_week = tdates.Date(freq='D', year=2007, month=1, day=7)
+        
+        date_D_friday = tdates.Date(freq='D', year=2007, month=1, day=5)
+        date_D_saturday = tdates.Date(freq='D', year=2007, month=1, day=6)
+        date_D_sunday = tdates.Date(freq='D', year=2007, month=1, day=7)
+        date_D_monday = tdates.Date(freq='D', year=2007, month=1, day=8)
+        
+        date_B_friday = tdates.Date(freq='B', year=2007, month=1, day=5)
+        date_B_monday = tdates.Date(freq='B', year=2007, month=1, day=8)
+        
+        date_D_to_A = tdates.Date(freq='A', year=2007)
+        date_D_to_Q = tdates.Date(freq='Q', year=2007, quarter=1)
+        date_D_to_M = tdates.Date(freq='M', year=2007, month=1)
+        date_D_to_W = tdates.Date(freq='W', year=2007, month=1, day=7)
+
+        date_D_to_H_before = tdates.Date(freq='H', year=2007, month=1, day=1, hours=0)
+        date_D_to_H_after = tdates.Date(freq='H', year=2007, month=1, day=1, hours=23)
+        date_D_to_T_before = tdates.Date(freq='T', year=2007, month=1, day=1, hours=0, minutes=0)
+        date_D_to_T_after = tdates.Date(freq='T', year=2007, month=1, day=1, hours=23, minutes=59)
+        date_D_to_S_before = tdates.Date(freq='S', year=2007, month=1, day=1, hours=0, minutes=0, seconds=0)
+        date_D_to_S_after = tdates.Date(freq='S', year=2007, month=1, day=1, hours=23, minutes=59, seconds=59)
+        
+        assert(date_D.asfreq('A') == date_D_to_A)
+        assert(date_D_end_of_year.asfreq('A') == date_D_to_A)
+        assert(date_D.asfreq('Q') == date_D_to_Q)
+        assert(date_D_end_of_quarter.asfreq('Q') == date_D_to_Q)
+        assert(date_D.asfreq('M') == date_D_to_M)
+        assert(date_D_end_of_month.asfreq('M') == date_D_to_M)
+        assert(date_D.asfreq('W') == date_D_to_W)
+        assert(date_D_end_of_week.asfreq('W') == date_D_to_W)
+
+        assert(date_D_friday.asfreq('B') == date_B_friday)
+        assert(date_D_saturday.asfreq('B', "BEFORE") == date_B_friday)
+        assert(date_D_saturday.asfreq('B', "AFTER") == date_B_monday)
+        assert(date_D_sunday.asfreq('B', "BEFORE") == date_B_friday)
+        assert(date_D_sunday.asfreq('B', "AFTER") == date_B_monday)
+
+        assert(date_D.asfreq('H', "BEFORE") == date_D_to_H_before)
+        assert(date_D.asfreq('H', "AFTER") == date_D_to_H_after)
+        assert(date_D.asfreq('T', "BEFORE") == date_D_to_T_before)
+        assert(date_D.asfreq('T', "AFTER") == date_D_to_T_after)
+        assert(date_D.asfreq('S', "BEFORE") == date_D_to_S_before)
+        assert(date_D.asfreq('S', "AFTER") == date_D_to_S_after)
+
+    def test_conv_hourly(self):
+        "frequency conversion tests: from Hourly Frequency"
+        
+        date_H = tdates.Date(freq='H', year=2007, month=1, day=1, hours=0)
+        date_H_end_of_year = tdates.Date(freq='H', year=2007, month=12, day=31, hours=23)
+        date_H_end_of_quarter = tdates.Date(freq='H', year=2007, month=3, day=31, hours=23)
+        date_H_end_of_month = tdates.Date(freq='H', year=2007, month=1, day=31, hours=23)
+        date_H_end_of_week = tdates.Date(freq='H', year=2007, month=1, day=7, hours=23)
+        date_H_end_of_day = tdates.Date(freq='H', year=2007, month=1, day=1, hours=23)
+        date_H_end_of_bus = tdates.Date(freq='H', year=2007, month=1, day=1, hours=23)
+        
+        date_H_to_A = tdates.Date(freq='A', year=2007)
+        date_H_to_Q = tdates.Date(freq='Q', year=2007, quarter=1)
+        date_H_to_M = tdates.Date(freq='M', year=2007, month=1)
+        date_H_to_W = tdates.Date(freq='W', year=2007, month=1, day=7)
+        date_H_to_D = tdates.Date(freq='D', year=2007, month=1, day=1)
+        date_H_to_B = tdates.Date(freq='B', year=2007, month=1, day=1)
+        
+        date_H_to_T_before = tdates.Date(freq='T', year=2007, month=1, day=1, hours=0, minutes=0)
+        date_H_to_T_after = tdates.Date(freq='T', year=2007, month=1, day=1, hours=0, minutes=59)
+        date_H_to_S_before = tdates.Date(freq='S', year=2007, month=1, day=1, hours=0, minutes=0, seconds=0)
+        date_H_to_S_after = tdates.Date(freq='S', year=2007, month=1, day=1, hours=0, minutes=59, seconds=59)
+        
+        assert(date_H.asfreq('A') == date_H_to_A)
+        assert(date_H_end_of_year.asfreq('A') == date_H_to_A)
+        assert(date_H.asfreq('Q') == date_H_to_Q)
+        assert(date_H_end_of_quarter.asfreq('Q') == date_H_to_Q)
+        assert(date_H.asfreq('M') == date_H_to_M)
+        assert(date_H_end_of_month.asfreq('M') == date_H_to_M)
+        assert(date_H.asfreq('W') == date_H_to_W)
+        assert(date_H_end_of_week.asfreq('W') == date_H_to_W)
+        assert(date_H.asfreq('D') == date_H_to_D)
+        assert(date_H_end_of_day.asfreq('D') == date_H_to_D)
+        assert(date_H.asfreq('B') == date_H_to_B)
+        assert(date_H_end_of_bus.asfreq('B') == date_H_to_B)
+
+        assert(date_H.asfreq('T', "BEFORE") == date_H_to_T_before)
+        assert(date_H.asfreq('T', "AFTER") == date_H_to_T_after)
+        assert(date_H.asfreq('S', "BEFORE") == date_H_to_S_before)
+        assert(date_H.asfreq('S', "AFTER") == date_H_to_S_after)
+
+    def test_conv_minutely(self):
+        "frequency conversion tests: from Minutely Frequency"
+        
+        date_T = tdates.Date(freq='T', year=2007, month=1, day=1, hours=0, minutes=0)
+        date_T_end_of_year = tdates.Date(freq='T', year=2007, month=12, day=31, hours=23, minutes=59)
+        date_T_end_of_quarter = tdates.Date(freq='T', year=2007, month=3, day=31, hours=23, minutes=59)
+        date_T_end_of_month = tdates.Date(freq='T', year=2007, month=1, day=31, hours=23, minutes=59)
+        date_T_end_of_week = tdates.Date(freq='T', year=2007, month=1, day=7, hours=23, minutes=59)
+        date_T_end_of_day = tdates.Date(freq='T', year=2007, month=1, day=1, hours=23, minutes=59)
+        date_T_end_of_bus = tdates.Date(freq='T', year=2007, month=1, day=1, hours=23, minutes=59)
+        date_T_end_of_hour = tdates.Date(freq='T', year=2007, month=1, day=1, hours=0, minutes=59)
+        
+        date_T_to_A = tdates.Date(freq='A', year=2007)
+        date_T_to_Q = tdates.Date(freq='Q', year=2007, quarter=1)
+        date_T_to_M = tdates.Date(freq='M', year=2007, month=1)
+        date_T_to_W = tdates.Date(freq='W', year=2007, month=1, day=7)
+        date_T_to_D = tdates.Date(freq='D', year=2007, month=1, day=1)
+        date_T_to_B = tdates.Date(freq='B', year=2007, month=1, day=1)
+        date_T_to_H = tdates.Date(freq='H', year=2007, month=1, day=1, hours=0)
+        
+        date_T_to_S_before = tdates.Date(freq='S', year=2007, month=1, day=1, hours=0, minutes=0, seconds=0)
+        date_T_to_S_after = tdates.Date(freq='S', year=2007, month=1, day=1, hours=0, minutes=0, seconds=59)
+        
+        assert(date_T.asfreq('A') == date_T_to_A)
+        assert(date_T_end_of_year.asfreq('A') == date_T_to_A)
+        assert(date_T.asfreq('Q') == date_T_to_Q)
+        assert(date_T_end_of_quarter.asfreq('Q') == date_T_to_Q)
+        assert(date_T.asfreq('M') == date_T_to_M)
+        assert(date_T_end_of_month.asfreq('M') == date_T_to_M)
+        assert(date_T.asfreq('W') == date_T_to_W)
+        assert(date_T_end_of_week.asfreq('W') == date_T_to_W)
+        assert(date_T.asfreq('D') == date_T_to_D)
+        assert(date_T_end_of_day.asfreq('D') == date_T_to_D)
+        assert(date_T.asfreq('B') == date_T_to_B)
+        assert(date_T_end_of_bus.asfreq('B') == date_T_to_B)
+        assert(date_T.asfreq('H') == date_T_to_H)
+        assert(date_T_end_of_hour.asfreq('H') == date_T_to_H)
+
+        assert(date_T.asfreq('S', "BEFORE") == date_T_to_S_before)
+        assert(date_T.asfreq('S', "AFTER") == date_T_to_S_after)
+
+
+    def test_conv_secondly(self):
+        "frequency conversion tests: from Secondly Frequency"
+        
+        date_S = tdates.Date(freq='S', year=2007, month=1, day=1, hours=0, minutes=0, seconds=0)
+        date_S_end_of_year = tdates.Date(freq='S', year=2007, month=12, day=31, hours=23, minutes=59, seconds=59)
+        date_S_end_of_quarter = tdates.Date(freq='S', year=2007, month=3, day=31, hours=23, minutes=59, seconds=59)
+        date_S_end_of_month = tdates.Date(freq='S', year=2007, month=1, day=31, hours=23, minutes=59, seconds=59)
+        date_S_end_of_week = tdates.Date(freq='S', year=2007, month=1, day=7, hours=23, minutes=59, seconds=59)
+        date_S_end_of_day = tdates.Date(freq='S', year=2007, month=1, day=1, hours=23, minutes=59, seconds=59)
+        date_S_end_of_bus = tdates.Date(freq='S', year=2007, month=1, day=1, hours=23, minutes=59, seconds=59)
+        date_S_end_of_hour = tdates.Date(freq='S', year=2007, month=1, day=1, hours=0, minutes=59, seconds=59)
+        date_S_end_of_minute = tdates.Date(freq='S', year=2007, month=1, day=1, hours=0, minutes=0, seconds=59)
+        
+        date_S_to_A = tdates.Date(freq='A', year=2007)
+        date_S_to_Q = tdates.Date(freq='Q', year=2007, quarter=1)
+        date_S_to_M = tdates.Date(freq='M', year=2007, month=1)
+        date_S_to_W = tdates.Date(freq='W', year=2007, month=1, day=7)
+        date_S_to_D = tdates.Date(freq='D', year=2007, month=1, day=1)
+        date_S_to_B = tdates.Date(freq='B', year=2007, month=1, day=1)
+        date_S_to_H = tdates.Date(freq='H', year=2007, month=1, day=1, hours=0)
+        date_S_to_T = tdates.Date(freq='T', year=2007, month=1, day=1, hours=0, minutes=0)
+        
+        assert(date_S.asfreq('A') == date_S_to_A)
+        assert(date_S_end_of_year.asfreq('A') == date_S_to_A)
+        assert(date_S.asfreq('Q') == date_S_to_Q)
+        assert(date_S_end_of_quarter.asfreq('Q') == date_S_to_Q)
+        assert(date_S.asfreq('M') == date_S_to_M)
+        assert(date_S_end_of_month.asfreq('M') == date_S_to_M)
+        assert(date_S.asfreq('W') == date_S_to_W)
+        assert(date_S_end_of_week.asfreq('W') == date_S_to_W)
+        assert(date_S.asfreq('D') == date_S_to_D)
+        assert(date_S_end_of_day.asfreq('D') == date_S_to_D)
+        assert(date_S.asfreq('B') == date_S_to_B)
+        assert(date_S_end_of_bus.asfreq('B') == date_S_to_B)
+        assert(date_S.asfreq('H') == date_S_to_H)
+        assert(date_S_end_of_hour.asfreq('H') == date_S_to_H)
+        assert(date_S.asfreq('T') == date_S_to_T)
+        assert(date_S_end_of_minute.asfreq('T') == date_S_to_T)
+        
+
 class test_methods(NumpyTestCase):
     "Base test class for MaskedArrays."
     
@@ -137,7 +538,10 @@
         dlist = ['2007-01-%02i' %i for i in (1,2,3,4,8,9,10,11,12,15)]
         ddates = date_array_fromlist(dlist)
         assert_equal(ddates.get_steps(), [1,1,1,4,1,1,1,1,3])
+        
+        
 
+
 ###############################################################################
 #------------------------------------------------------------------------------
 if __name__ == "__main__":



More information about the Scipy-svn mailing list