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

scipy-svn at scipy.org scipy-svn at scipy.org
Mon Feb 5 15:49:41 EST 2007


Author: mattknox_ca
Date: 2007-02-05 14:49:37 -0600 (Mon, 05 Feb 2007)
New Revision: 2678

Modified:
   trunk/Lib/sandbox/timeseries/tdates.py
Log:
modified date_to_index to handle DateArray's

Modified: trunk/Lib/sandbox/timeseries/tdates.py
===================================================================
--- trunk/Lib/sandbox/timeseries/tdates.py	2007-02-05 15:51:10 UTC (rev 2677)
+++ trunk/Lib/sandbox/timeseries/tdates.py	2007-02-05 20:49:37 UTC (rev 2678)
@@ -673,16 +673,24 @@
 
     def date_to_index(self, date):
         "Returns the index corresponding to one given date, as an integer."
-        if self.isvalid():
-            index = date.value - self[0].value
-            if index < 0 or index > self.size:
-                raise ValueError, "Date out of bounds!"
-            return index
+        if isDate(date):
+            if self.isvalid():
+                index = date.value - self[0].value
+                if index < 0 or index > self.size:
+                    raise ValueError, "Date out of bounds!"
+                return index
+            else:
+                index_asarray = (self == date.value).nonzero()
+                if fromnumeric.size(index_asarray) == 0:
+                    raise ValueError, "Date out of bounds!" 
+                return index_asarray[0][0]
         else:
-            index_asarray = (self == date.value).nonzero()
-            if fromnumeric.size(index_asarray) == 0:
-                raise ValueError, "Date out of bounds!" 
-            return index_asarray[0][0]
+            #date is a DateArray
+            def idx_check(val): return (date == val).any()
+            idx_check_v = numpy.vectorize(idx_check)
+            return numpy.where(idx_check_v(self.tovalue()))[0]
+            
+            
     #......................................................        
     def get_steps(self):
         """Returns the time steps between consecutive dates.




More information about the Scipy-svn mailing list