[Scipy-svn] r3232 - trunk/Lib/sandbox/timeseries/lib

scipy-svn@scip... scipy-svn@scip...
Tue Aug 14 13:29:03 CDT 2007


Author: pierregm
Date: 2007-08-14 13:28:58 -0500 (Tue, 14 Aug 2007)
New Revision: 3232

Modified:
   trunk/Lib/sandbox/timeseries/lib/moving_funcs.py
Log:
maskedarray
mrecords : fixed a pb when creating mrecords from a list of tuples

timeseries
lib.moving_funcs : fixed a pb with the mov_xxx functions: the original data	was affected in certain cases

Modified: trunk/Lib/sandbox/timeseries/lib/moving_funcs.py
===================================================================
--- trunk/Lib/sandbox/timeseries/lib/moving_funcs.py	2007-08-14 17:45:19 UTC (rev 3231)
+++ trunk/Lib/sandbox/timeseries/lib/moving_funcs.py	2007-08-14 18:28:58 UTC (rev 3232)
@@ -33,15 +33,18 @@
 def _process_result_dict(orig_data, result_dict):
     "process the results from the c function"
 
+    rarray = result_dict['array']
     rtype = result_dict['array'].dtype
     rmask = result_dict['mask']
 
     # makes a copy of the appropriate type
-    data = orig_data.astype(rtype)
-    data[:] = result_dict['array']
+    data = orig_data.astype(rtype).copy()
+    data.flat = result_dict['array'].ravel()
+    if not hasattr(data, '__setmask__'):
+        data = data.view(MA.MaskedArray)
+    data.__setmask__(rmask)
+    return data
 
-    return marray(data, mask=rmask, copy=False, subok=True)
-
 def _moving_func(data, cfunc, kwargs):
 
     if data.ndim == 1:
@@ -327,3 +330,29 @@
         fdoc = fdoc.replace('$$'+prm+'$$', dc)
     fdoc += mov_result_doc
     _g[fn].func_doc = fdoc
+
+
+###############################################################################
+if __name__ == '__main__':
+    from timeseries import time_series, today
+    from maskedarray.testutils import assert_equal, assert_almost_equal
+    #
+    series = time_series(N.arange(10),start_date=today('D'))
+    #
+    filtered = mov_sum(series,3)
+    assert_equal(filtered, [0,1,3,6,9,12,15,18,21,24])
+    assert_equal(filtered._mask, [1,1,0,0,0,0,0,0,0,0])
+    assert_equal(filtered._dates, series._dates)
+    assert_equal(series, N.arange(10))
+    #
+    filtered = mov_average(series,3)
+    assert_equal(filtered, [0,1,1,2,3,4,5,6,7,8])
+    assert_equal(filtered._mask, [1,1,0,0,0,0,0,0,0,0])
+    assert_equal(filtered._dates, series._dates)
+    assert_equal(series, N.arange(10))
+    #
+    filtered = mov_average(series._data,3)
+    assert_equal(filtered, [0,1,1,2,3,4,5,6,7,8])
+    assert_equal(filtered._mask, [1,1,0,0,0,0,0,0,0,0])
+    assert_equal(series, N.arange(10))
+    



More information about the Scipy-svn mailing list