[Scipy-svn] r2668 - trunk/Lib/sandbox/timeseries

scipy-svn@scip... scipy-svn@scip...
Thu Feb 1 12:16:02 CST 2007


Author: pierregm
Date: 2007-02-01 12:15:59 -0600 (Thu, 01 Feb 2007)
New Revision: 2668

Modified:
   trunk/Lib/sandbox/timeseries/tdates.py
   trunk/Lib/sandbox/timeseries/tmulti.py
Log:
tmulti:fixed tmulti.__getitem__

Modified: trunk/Lib/sandbox/timeseries/tdates.py
===================================================================
--- trunk/Lib/sandbox/timeseries/tdates.py	2007-02-01 05:34:20 UTC (rev 2667)
+++ trunk/Lib/sandbox/timeseries/tdates.py	2007-02-01 18:15:59 UTC (rev 2668)
@@ -539,14 +539,15 @@
             except AttributeError:
                 pass     
         r = ndarray.__getitem__(self, indx)
+#        return r
         if not hasattr(r, "size"):
             if isinstance(r, int): 
                 return Date(self.freq, value=r)
             else: 
                 return r
-        elif r.size == 1:
+        elif r.size == 1:
             # Only one element, and it's not a scalar: we have a DateArray of size 1
-            if len(numeric.shape(r)) > 0:
+            if len(r.shape) > 0:
                 r = r.item()
             return Date(self.freq, value=r)
         else:
@@ -981,4 +982,7 @@
 if __name__ == '__main__':
     assert (Date('D','2007-01')==Date('D',string='2007-01'))
     assert (Date('D','2007-01')==Date('D', value=732677))
-    assert (Date('D',732677)==Date('D', value=732677))
\ No newline at end of file
+    assert (Date('D',732677)==Date('D', value=732677))
+    n = Date('D','2007-01')
+    tmp = date_array(n,n+3)
+    print tmp[0]
\ No newline at end of file

Modified: trunk/Lib/sandbox/timeseries/tmulti.py
===================================================================
--- trunk/Lib/sandbox/timeseries/tmulti.py	2007-02-01 05:34:20 UTC (rev 2667)
+++ trunk/Lib/sandbox/timeseries/tmulti.py	2007-02-01 18:15:59 UTC (rev 2668)
@@ -238,18 +238,20 @@
             obj._mask = make_mask(_localdict['_fieldmask'][indx])
             return obj
         # We want some elements ..
-        indx = super(MultiTimeSeries, self)._TimeSeries__checkindex(indx)
-        return MultiTimeSeries(_localdict['_series'][indx], 
-                               dates=_localdict['_dates'][indx],
+        (sindx, dindx) = super(MultiTimeSeries, self)._TimeSeries__checkindex(indx)
+        return MultiTimeSeries(_localdict['_series'][sindx], 
+                               dates=_localdict['_dates'][dindx],
 #                              mask=_localdict['_fieldmask'][indx],
                                dtype=self.dtype)
         
     def __getslice__(self, i, j):
         """Returns the slice described by [i,j]."""
         _localdict = self.__dict__
-        return MultiTimeSeries(_localdict['_data'][i:j], 
-                               mask=_localdict['_fieldmask'][i:j],
-                               dates=_localdict['_dates'][i:j],
+        (si, di) = super(MultiTimeSeries, self)._TimeSeries__checkindex(i)
+        (sj, dj) = super(MultiTimeSeries, self)._TimeSeries__checkindex(j)
+        return MultiTimeSeries(_localdict['_data'][si:sj], 
+                               mask=_localdict['_fieldmask'][si:sj],
+                               dates=_localdict['_dates'][di:dj],
                                dtype=self.dtype)      
         
     def __setslice__(self, i, j, value):
@@ -564,48 +566,17 @@
 
     
 ################################################################################
-#if 1:
-#    from tseries import aligned
-#    import maskedarray.testutils
-#    from maskedarray.testutils import *
-#    
-#    if 1:
-#        mlist = ['2005-%02i' % i for i in range(1,13)]
-#        mlist += ['2006-%02i' % i for i in range(1,13)]
-#        mdata = numpy.arange(24)
-#        mser1 = time_series(mdata, mlist, observed='SUMMED')
-#        #
-#    if 1:
-#        mlist2 = ['2004-%02i' % i for i in range(1,13)]
-#        mlist2 += ['2005-%02i' % i for i in range(1,13)]
-#        mser2 = time_series(mdata, mlist2, observed='SUMMED')
-#        #
-#        (malg1,malg2) = aligned(mser1, mser2)
-#    if 1:
-#        mrec = MR.fromarrays([mser1])
-#        descr = [('A',N.float_),('B',N.float_)]
-#
-#if 1:
-#    import numpy as N
-#    if 1:        
-##    def setup(self):       
-##        "Generic setup" 
-#        d = N.arange(5)
-#        m = MA.make_mask([1,0,0,1,1])
-#        base_d = N.r_[d,d[::-1]].reshape(2,-1).T
-#        base_m = N.r_[[m, m[::-1]]].T
-#        base = MA.array(base_d, mask=base_m)    
-#        mrec = MR.fromarrays(base.T,)
-#        dlist = ['2007-%02i' % (i+1) for i in d]
-#        dates = date_array(dlist)
-#        ts = time_series(mrec,dates)
-#        mts = MultiTimeSeries(mrec,dates)
-#        
-#        logmts = N.log(mts)
-#        self_data = [d, m, mrec, dlist, dates, ts, mts]
-#        #
-#        mts.addfield(masked_array(d+10, mask=m[::-1]))
-#        assert('f2' in mts.dtype.names)
-#        assert_equal(mts.f2, d+10)
-#        assert_equal(mts.f2._mask, m[::-1])
-
+if __name__ == '__main__':
+    import numpy as N
+    if 1:
+        d = N.arange(5)
+        m = MA.make_mask([1,0,0,1,1])
+        base_d = N.r_[d,d[::-1]].reshape(2,-1).T
+        base_m = N.r_[[m, m[::-1]]].T
+        base = MA.array(base_d, mask=base_m)    
+        mrec = MR.fromarrays(base.T,)
+        dlist = ['2007-%02i' % (i+1) for i in d]
+        dates = date_array(dlist)
+        ts = time_series(mrec,dates)
+        mts = MultiTimeSeries(mrec,dates)
+        self_data = [d, m, mrec, dlist, dates, ts, mts]
\ No newline at end of file



More information about the Scipy-svn mailing list