[Scipy-svn] r3040 - in trunk/Lib/sandbox/timeseries: src tests
scipy-svn@scip...
scipy-svn@scip...
Thu May 24 12:12:01 CDT 2007
Author: mattknox_ca
Date: 2007-05-24 12:11:57 -0500 (Thu, 24 May 2007)
New Revision: 3040
Modified:
trunk/Lib/sandbox/timeseries/src/c_tdates.c
trunk/Lib/sandbox/timeseries/tests/test_dates.py
Log:
- fixed a memory leak in DateObject_asfreq
- fixed a problem with converting A-NOV freq to daily
- raise error when frequency conversion fails instead of returning invalid result
Modified: trunk/Lib/sandbox/timeseries/src/c_tdates.c
===================================================================
--- trunk/Lib/sandbox/timeseries/src/c_tdates.c 2007-05-24 12:30:05 UTC (rev 3039)
+++ trunk/Lib/sandbox/timeseries/src/c_tdates.c 2007-05-24 17:11:57 UTC (rev 3040)
@@ -770,8 +770,11 @@
static long asfreq_AtoD(long fromDate, char relation, asfreq_info *af_info) {
long absdate, year, final_adj;
- int month = (af_info->from_a_year_end + 1) % 12;
+ int month = (af_info->from_a_year_end) % 12;
+ if (month == 0) { month = 1; }
+ else { month += 1; }
+
if (relation == 'B') {
if (af_info->from_a_year_end == 12) {year = fromDate;}
else {year = fromDate - 1;}
@@ -1384,7 +1387,9 @@
&freq, &value, &string,
&year, &month, &day, &quarter,
&hour, &minute, &second,
- &datetime)) return -1;
+ &datetime)) {
+ return -1;
+ }
if (PyObject_HasAttrString(freq, "freq")) {
PyObject *freq_attr = PyObject_GetAttrString(freq, "freq");
@@ -1610,8 +1615,13 @@
strcmp(relation_uc, "B") == 0 ||
strcmp(relation_uc, "AFTER") == 0 ||
strcmp(relation_uc, "A") == 0) {
- relation = relation_uc[0];
+ if(relation_uc[0] == 'A') { relation = 'A'; }
+ else { relation = 'B'; }
+
} else { invalid_relation=1; }
+
+ free(relation_uc);
+
} else {
invalid_relation=1;
}
@@ -1631,6 +1641,8 @@
result_val = asfreq_func(self->value, relation, &af_info);
+ if (result_val == INT_ERR_CODE) return NULL;
+
result->freq = toFreq;
result->value = result_val;
Modified: trunk/Lib/sandbox/timeseries/tests/test_dates.py
===================================================================
--- trunk/Lib/sandbox/timeseries/tests/test_dates.py 2007-05-24 12:30:05 UTC (rev 3039)
+++ trunk/Lib/sandbox/timeseries/tests/test_dates.py 2007-05-24 17:11:57 UTC (rev 3040)
@@ -260,6 +260,7 @@
date_AJAN = dWrap(Date(freq=C.FR_ANNJAN, year=2007))
date_AJUN = dWrap(Date(freq=C.FR_ANNJUN, year=2007))
+ date_ANOV = dWrap(Date(freq=C.FR_ANNNOV, year=2007))
date_A_to_Q_before = dWrap(Date(freq='Q', year=2007, quarter=1))
date_A_to_Q_after = dWrap(Date(freq='Q', year=2007, quarter=4))
@@ -288,6 +289,8 @@
date_AJAN_to_D_before = dWrap(Date(freq='D', year=2006, month=2, day=1))
date_AJUN_to_D_after = dWrap(Date(freq='D', year=2007, month=6, day=30))
date_AJUN_to_D_before = dWrap(Date(freq='D', year=2006, month=7, day=1))
+ date_ANOV_to_D_after = dWrap(Date(freq='D', year=2007, month=11, day=30))
+ date_ANOV_to_D_before = dWrap(Date(freq='D', year=2006, month=12, day=1))
assert_func(date_A.asfreq('Q', "BEFORE"), date_A_to_Q_before)
assert_func(date_A.asfreq('Q', "AFTER"), date_A_to_Q_after)
@@ -312,6 +315,9 @@
assert_func(date_AJUN.asfreq('D', "BEFORE"), date_AJUN_to_D_before)
assert_func(date_AJUN.asfreq('D', "AFTER"), date_AJUN_to_D_after)
+ assert_func(date_ANOV.asfreq('D', "BEFORE"), date_ANOV_to_D_before)
+ assert_func(date_ANOV.asfreq('D', "AFTER"), date_ANOV_to_D_after)
+
def test_conv_quarterly(self):
"frequency conversion tests: from Quarterly Frequency"
More information about the Scipy-svn
mailing list