[Scipy-svn] r2591 - in trunk/Lib/sandbox/timeseries: . examples

scipy-svn at scipy.org scipy-svn at scipy.org
Tue Jan 23 03:21:39 EST 2007


Author: pierregm
Date: 2007-01-23 02:21:33 -0600 (Tue, 23 Jan 2007)
New Revision: 2591

Added:
   trunk/Lib/sandbox/timeseries/examples/example.wiki
Modified:
   trunk/Lib/sandbox/timeseries/examples/example.py
   trunk/Lib/sandbox/timeseries/readme.txt
   trunk/Lib/sandbox/timeseries/tdates.py
Log:
update readme & example

Modified: trunk/Lib/sandbox/timeseries/examples/example.py
===================================================================
--- trunk/Lib/sandbox/timeseries/examples/example.py	2007-01-23 05:45:43 UTC (rev 2590)
+++ trunk/Lib/sandbox/timeseries/examples/example.py	2007-01-23 08:21:33 UTC (rev 2591)
@@ -1,290 +1,52 @@
-
-"""
-=== TimeSeries ===
-
-A TimeSeries object is the combination of three ndarrays:
-    
-    - `dates`: DateArray object.
-    - `data` : ndarray.
-    - `mask` : Boolean ndarray, indicating missing or invalid data.
-    
-
-==== Construction ====
-
-To construct a TimeSeries, you can use the class constructor:
-
->>> TimeSeries(data, dates=None, mask=nomask, 
-               freq=None, observed=None, start_date=None, 
-               dtype=None, copy=False, fill_value=None,
-               keep_mask=True, small_mask=True, hard_mask=False)
-               
-where `data` is a sequence.
-If `dates` is None, a DateArray of the same length as the data is constructed at 
-a `freq` frequency, starting at `start_date`.
-
-Alternatively, you can use the `time_series` function:
-
-
-time_series(data, dates=None, freq=None, 
-            start_date=None, end_date=None, length=None, include_last=True,
-            mask=nomask, dtype=None, copy=False, fill_value=None,
-            keep_mask=True, small_mask=True, hard_mask=False)    
-
-
-Let us construct a series of 600 random elements, starting 600 business days ago, 
-at  a business daily frequency
-
->>> import numpy as np
->>> import tseries as ts
->>> import tsdate as td
->>> data = np.random.uniform(-100,100,600)
->>> today = td.thisday('B')
->>> series = ts.time_series(data, dtype=np.float_, freq='B', observed='SUMMED',
-                            start_date=today-600)
-                            
-Let us set negative values to zero...
-
->>> series[series<0] = 0
-
-... and the values falling on Fridays to 100
->>> series[series.day_of_week == 4] = 100
-
-Note that we could also create a temporary array of 'day_of weeks' for the 
-corresponding period, and use it as condition.
-
->>> weekdays = td.day_of_week(series)
->>> series[weekdays == 4] = 100
-
-==== Slicing ====
-
-Accessing elements of a TimeSeries works just like slicing
->>> series[-30:]
-
-But you can also use a date:
->>> thirtydaysago = today-30
->>> series[thirtydaysago:]
-
-Or even a string
->>> series[thirtydaysago.tostring():]
-
-
-==== Conversions ====
-
-To convert a TimeSeries to another frequency, use the `convert` method or function.
-The optional argument `func` must be a function that acts on a 1D masked array 
-and returns a scalar. 
-
->>> mSer1 = series.convert('M',func=ma.average)
-
-If `func` is not specified, the default value `'auto'` is used instead. In that case,
-the conversion function is estimated from the `observed` attribute of the series.
-For example, if `observed='SUMMED'`, then `func='auto'` is in fact `func=sum`.
-
->>> mSer1_default = series.convert('M')
-
-If `func` is None, the convert method/function returns a 2D array, where each row 
-corresponds to the new frequency, and the columns to the original data. In our 
-example, convert will return a 2D array with 23 columns, as there are at most
-23 business days per month.
-
->>> mSer1_2d = series.convert('M',func=None)
-
-When converting from a lower frequency to a higher frequency, an extra argument
-`position` is required. The value of the argument is either 'START' or 'END', 
-and determines where the data point will be placed in the
-period. In the future, interpolation methods will be supported to fill in the
-resulting masked values.
-
-Let us create a second series, this time with a monthly frequency, starting 110
-months ago.
->>> data = np.random.uniform(-100,100,100).astype(np.float_)
->>> today = today.asfreq('M') - 110
->>> mSer2 = ts.TimeSeries(data, freq='m', observed='END',start_date=today)
->>> sixtymonthsago = today-60
->>> mSer2[sixtymonthsago:sixtymonthsago+10] = 12
-
-"""
-import numpy as np
-import tseries as ts
-reload(ts)
-import tsdate as td
-reload(td)
-#from numpy import ma
-import maskedarray as ma
-
-data = np.random.uniform(-100,100,600)
-today = td.thisday('B')
-series = ts.time_series(data, dtype=np.float_, freq='B', observed='SUMMED',
+import numpy as N
+import maskedarray as MA
+import tseries as TS
+import tdates as TD
+D = TD.Date(freq='D', year=2007, month=1, day=1)
+M = TD.Date(freq='M', year=2007, month=1, day=1)
+Y = TD.Date(freq='A', year=2007, month=1, day=1)
+TD.Date(freq='Q',year=2004,quarter=3)
+TD.Date(freq='D',year=2001,month=1,day=1)
+TD.Date('D', '2007-01-01')
+TD.Date('D', mxDate=mx.DateTime.now())
+TD.Date('D', mxDate=datetime.datetime.now())
+data = N.random.uniform(-100,100,600)
+today = TD.thisday('B')
+series = TS.time_series(data, dtype=np.float_, freq='B', observed='SUMMED',
                         start_date=today-600)
-series[series < 0] = 0
-
-#WARNING: The ORIGINAL day_of_week version seemed bugged. 
-#It told me that 2006/12/28 was a Friday.
+series[0]
+series[-30:]
+thirtydaysago = today - 30
+series[thirtydaysago:]
+series[thirtydaysago.tostring():]
+series[series<0] = 0
+series[series.day_of_week == 4] = 100
 weekdays = td.day_of_week(series)
 series[weekdays == 4] = 100
-
-mSer1 = series.convert('M',func=ma.average)
-mSer1_2d = series.convert('M',func=None)
-mSer1_default = series.convert('M')
-mToB = series.convert('M',position='START')
-
-
-# Create another monthly frequency series
-data = np.random.uniform(-100,100,100).astype(np.float_)
-today = today.asfreq('M') - 110
-mSer2 = ts.TimeSeries(data, freq='m', observed='END',start_date=today)
+series_log = N.log(series)
+mlist_1 = ['2005-%02i' % i for i in range(1,10)]
+mlist_1 += ['2006-%02i' % i for i in range(2,13)]
+mdata_1 = N.arange(len(mlist_1))
+mser_1 = TS.time_series(mdata_1, mlist_1, observed='SUMMED')
+mser = mser1.asfreq('M')
+mser1.has_duplicated_dates()
+mser1.has_missing_dates()
+mlist_2 = ['2004-%02i' % i for i in range(1,13)]
+mlist_2 += ['2005-%02i' % i for i in range(1,13)]
+mser_2 = TS.time_series(N.arange(len(mlist_2)), mlist_2, observed='SUMMED')
+mser_3 = mser_1 + mser_2
+(malg_1,malg_2) = aligned(mser_1, mser_2) 
+mser_1_filled = fill_missing_dates(mser_1)
+(malg_1,malg_2) = align_series(mser_1_filled, mser_2) 
+mser_3 = malg_1 + malg_2
+mser_3 = filled(malg_1,0) + filled(malg_2,0)
+(malg_1,malg_2) = aligned(mser_1_filled, mser2, 
+                          start_date='2004-06', end_date='2006-06')
+mseries = series.convert('M',func=ma.average)
+mseries_default = series.convert('M')
+mseries_2d = series.convert('M',func=None)
+data = N.random.uniform(-100,100,100).astype(np.float_)
+today = TS.today.asfreq('M') - 110
+nseries = TS.TimeSeries(data, freq='m', observed='END',start_date=today)
 sixtymonthsago = today-60
-mSer2[sixtymonthsago:sixtymonthsago+10] = 12
-
-
-"""
-==== Operations on TimeSeries ====
-
-If you work with only one TimeSeries, you can use regular commands to process
-the data. For example:
-
->>> mSer2_log = np.log(mSer2)
-
-Note that invalid values (negative, in that case), are automatically masked.
-Note as well that trying to use the maskedarray command directly is unlikely to 
-work: you would end up with a regular MaskedArray.
-
-When working with multiple series, only series of the same frequency, size and
-starting date can be used in basic operations. The function `align_series` forces
-series to have matching starting and ending dates. By default, the starting date
-will be set to the smallest starting date of the series, and the ending date to
-the largest. [An alias to `align_series` is aligned]
-
-Let's construct a list of months, starting on Jan 2005 and ending on Dec 2006,
-with a gap from Oct 2005 to Dec 2006. 
-
->>> mlist = ['2005-%02i' % i for i in range(1,10)]
->>> mlist += ['2006-%02i' % i for i in range(2,13)]
->>> mdata = numpy.arange(len(mlist))
->>> mser1 = time_series(mdata, mlist, observed='SUMMED')
-
-Note that the frequency is 'U', for undefined. In fact, you have to specify what
-kind of data is actually missing by forcing a given frequency.
-
->>> mser1 = mser1.asfreq('M')
-
-Let us check whether there are some duplicated dates (no):
-
->>> mser1.has_duplicated_dates()
-
-...or missing dates (yes):
-
->>> mser1.has_missing_dates()
-
-Let us construct a second monthly series, this time without missing dates
-
->>> 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')
-
-Let's try to add the two series:
-
->>> mser3 = mser1 + mser2
-
-That doesn't work, as the series have different starting dates. We need to align 
-them first.
-
->>> (malg1,malg2) = aligned(mser1, mser2) 
-
-That still doesnt' work, as `malg1` has missing dates. Let us fill it, then: 
-data falling on a date that was missing will be masked.
-
->>> mser1_filled = fill_missing_dates(mser1)
->>> (malg1,malg2) = align_series(mser1_filled, mser2) 
-
-Now we can add the two series. Only the data that fall on dates common to the
-original, non-aligned series will be actually added, the others will be masked.
-After all, we are adding masked arrays.
-
->>> mser3 = malg1 + malg2
-
-We could have filled the initial series first:
->>> mser3 = filled(malg1,0) + filled(malg2,0)
-
-Alternatively, we can force the series to start/end at some given dates
-
->>> (malg1,malg2) = aligned(mser1_filled, mser2, 
->>>                         start_date='2004-06', end_date='2006-06')
-
-"""
-mlist = ['2005-%02i' % i for i in range(1,10)]
-mlist += ['2006-%02i' % i for i in range(2,13)]
-mdata = np.arange(len(mlist))
-mser1 = ts.time_series(mdata, mlist, observed='SUMMED')
-mser1 = mser1.asfreq('M')
-#
-mlist2 = ['2004-%02i' % i for i in range(1,13)]
-mlist2 += ['2005-%02i' % i for i in range(1,13)]
-mser2 = ts.time_series(np.arange(len(mlist2)), mlist2, observed='SUMMED')
-#
-mser1_filled = ts.fill_missing_dates(mser1)
-(malg1,malg2) = ts.aligned(mser1_filled, mser2) 
-mser3 = malg1 + malg2 
-
-"""
-# add the two series together, first filling in masked values with zeros
-mAdd1_filled = mSer1.filled(fill_value=0, ts=True) + mSer2.filled(fill_value=0, ts=True)
-
-# adjust the start and end dates of a series
-newSer = ts.adjust_endpoints(mSer1, start_date=td.Date(freq='M', year=1954, month=5),  end_date=td.Date(freq='M', year=2000, month=6))
-
-# calculate the average value in the series. Behaves the same as in ma
-bAverage = ma.average(series)
-
-
-
-
-
-# Get the last day of this year, at daily frequency
-dLastDayOfYear = td.dateOf(td.thisday('A'),'D','AFTER')
-
-
-# Get the first day of this year, at business frequency
-bFirstDayOfYear = td.dateOf(td.thisday('A'),'B','BEFORE')
-
-# Get the last day of the previous quarter, business frequency
-bLastDayOfLastQuarter = td.dateOf(td.thisday('Q')-1,'B','AFTER')
-
-# dateOf can also go from high frequency to low frequency. In this case, the third parameter has no impact
-aTrueValue = (td.thisday('Q') == td.dateOf(td.thisday('b'),'Q'))
-
-# Dates of the same frequency can be subtracted (but not added obviously)
-numberOfBusinessDaysPassedThisYear = td.thisday('b') - bFirstDayOfYear
-
-# Integers can be added/substracted to/from dates
-fiveDaysFromNow = td.thisday('d') + 5
-
-
-# Get the previous business day, where business day is considered to
-# end at day_end_hour and day_end_min
-pbd = td.prevbusday(day_end_hour=18,day_end_min=0)
-"""
-# ------------------------------------------------------------------------------
-"""
-=== Date construction ===
-Several options are available to construct a Date object explicitly:
-
-    - Give appropriate values to the `year`, `month`, `day`, `quarter`, `hours`, 
-      `minutes`, `seconds` arguments.
-      
-      >>> td.Date(freq='Q',year=2004,quarter=3)
-      >>> td.Date(freq='D',year=2001,month=1,day=1)
-      
-    - Use the `string` keyword. This method calls the `mx.DateTime.Parser`
-      submodule, more information is available in its documentation.
-      
-      >>> ts.Date('D', '2007-01-01')
-      
-    - Use the `mxDate` keyword with an existing mx.DateTime.DateTime object, or 
-      even a datetime.datetime object.
-      
-      >>> td.Date('D', mxDate=mx.DateTime.now())
-      >>> td.Date('D', mxDate=datetime.datetime.now())
-"""
-
-# Construct a sequence of dates at a given frequency
+nseries[sixtymonthsago:sixtymonthsago+10] = 12

Added: trunk/Lib/sandbox/timeseries/examples/example.wiki
===================================================================
--- trunk/Lib/sandbox/timeseries/examples/example.wiki	2007-01-23 05:45:43 UTC (rev 2590)
+++ trunk/Lib/sandbox/timeseries/examples/example.wiki	2007-01-23 08:21:33 UTC (rev 2591)
@@ -0,0 +1,221 @@
+
+{{{#!python numbers=disable
+>>> import numpy as N
+>>> import maskedarray as MA
+>>> import tseries as TS
+>>> import tdates as TD
+}}}
+
+== Dates ==
+
+A `Date` object combines some date and/or time related information with a given frequency. You can picture the frequency as the unit into which the date is expressed. For example, the three objects:
+{{{#!python  numbers=disable
+>>> D = TD.Date(freq='D', year=2007, month=1, day=1)
+>>> M = TD.Date(freq='M', year=2007, month=1, day=1)
+>>> Y = TD.Date(freq='A', year=2007, month=1, day=1)
+}}}
+use the same date information, but different frequencies. They correspond to to the day Jan. 01, 2007, the month Jan. 2007 and the year 2007, respectively. The importance of the frequency will become clearer later on.
+~- A more technical note: `Date` objects are internally stored as integers. The conversion to integers and back is controlled by the frequency. In the example above, the internal representation of the three objects `D`, `M` and `Y` are 732677, 24073 and 2007, respectively. -~
+
+Date objects are managed through their own class, appropriately named `Date`.
+
+==== Construction of a `Date` object ====
+Several options are available to construct a Date object explicitly. In each case, the `frequency` argument must be given.
+
+    * Give appropriate values to any of the `year`, `month`, `day`, `quarter`, `hours`, `minutes`, `seconds` arguments.
+
+{{{#!python numbers=disable
+>>> TD.Date(freq='Q',year=2004,quarter=3)
+<Q : 2004Q3>
+>>> TD.Date(freq='D',year=2001,month=1,day=1)
+<D : 01-Jan-2001>
+}}}
+      
+    * Use the `string` keyword. This method calls the `mx.DateTime.Parser` submodule, more information is available in the documentation of this latter.
+
+{{{#!python numbers=disable      
+>>> TD.Date('D', string='2007-01-01')
+<D : 01-Jan-2007>
+}}}      
+
+    * Use the `mxDate` keyword with an existing `mx.DateTime.DateTime` object, or even a `datetime.datetime` object.
+{{{#!python numbers=disable
+>>> TD.Date('D', mxDate=mx.DateTime.now())
+>>> TD.Date('D', mxDate=datetime.datetime.now())
+}}}
+
+
+----
+
+== DateArray objects ==
+
+DateArrays are simply ndarrays of `Date` objects.
+
+----
+
+== TimeSeries ==
+
+A `TimeSeries` object is the combination of three ndarrays:
+
+    * `dates`: DateArray object.
+    * `data` : ndarray.
+    * `mask` : Boolean ndarray, indicating missing or invalid data.
+    
+
+==== Construction ====
+
+To construct a TimeSeries, you can use the class constructor:
+
+{{{#!python numbers=disable
+TimeSeries(data, dates=None, mask=nomask, 
+           freq=None, observed=None, start_date=None, 
+           dtype=None, copy=False, fill_value=None,
+           keep_mask=True, small_mask=True, hard_mask=False)
+}}}               
+where `data` is a sequence, a ndarray or a MaskedArray. If `dates` is None, a DateArray of the same length as the data is constructed at a `freq` frequency, starting at `start_date`.
+
+Alternatively, you can use the `time_series` function:
+{{{#!python numbers=disable
+time_series(data, dates=None, freq=None, 
+            start_date=None, end_date=None, length=None, include_last=True,
+            mask=nomask, dtype=None, copy=False, fill_value=None,
+            keep_mask=True, small_mask=True, hard_mask=False)    
+}}}
+
+Let us construct a series of 600 random elements, starting 600 business days ago, at  a business daily frequency
+{{{#!python numbers=disable
+>>> data = N.random.uniform(-100,100,600)
+>>> today = TD.thisday('B')
+>>> series = TS.time_series(data, dtype=N.float_, freq='B', observed='SUMMED',
+>>>                         start_date=today-600)
+}}}
+
+==== Indexing ====
+
+Elements of a TimeSeries can be accessed just like with regular ndarrrays. Thus,
+{{{#!python numbers=disable
+>>> series[0]
+}}}
+outputs the first element, while
+{{{#!python numbers=disable
+>>> series[-30:]
+}}}
+outputs the last 30 elements.
+
+But you can also use a date:
+{{{#!python numbers=disable
+>>> thirtydaysago = today - 30
+>>> series[thirtydaysago:]
+}}}
+or even a string...
+{{{#!python numbers=disable
+>>> series[thirtydaysago.tostring():]
+}}}
+
+In a similar way, setting elements of a TimeSeries works seamlessly.
+Let us set negative values to zero...
+{{{#!python numbers=disable
+>>> series[series<0] = 0
+}}}
+... and the values falling on Fridays to 100
+{{{#!python numbers=disable
+>>> series[series.day_of_week == 4] = 100
+}}}
+Note that we could also create a temporary array of 'day_of weeks' for the 
+corresponding period, and use it as condition.
+{{{#!python numbers=disable
+>>> weekdays = TD.day_of_week(series)
+>>> series[weekdays == 4] = 100
+}}}
+You should keep in mind that TimeSeries are basically MaskedArrays. If some data are masked, you will not be able to use a condition as index, you will have to fill the data first.
+
+==== Operations on TimeSeries ====
+
+If you work with only one TimeSeries, you can use regular commands to process the data. For example:
+{{{#!python numbers=disable
+>>> series_log = N.log(series)
+}}}
+Note that invalid values (negative, in that case), are automatically masked. Note also that you could use the corresponding function of the `maskedarray` module. This latter approach is actually recommended when you want to use the `reduce` and `accumulate` methods of some ufuncs (such as add or multiply). ~-The reason is that the methods of the numpy.ufuncs do not communicate well with subclasses: as they do not call the `__array_wrap__` method, there is no postprocessing.-~
+
+When working with multiple series, only series of the same frequency, size and starting date can be used in basic operations. The function `align_series` ~-(or its alias `aligned`)-~ forces series to have matching starting and ending dates. By default, the starting date will be set to the smallest starting date of the series, and the ending date to the largest.
+
+Let's construct a list of months, starting on Jan 2005 and ending on Dec 2006, with a gap from Oct 2005 to Dec 2006.
+{{{#!python numbers=disable
+>>> mlist_1 = ['2005-%02i' % i for i in range(1,10)]
+>>> mlist_1 += ['2006-%02i' % i for i in range(2,13)]
+>>> mdata_1 = N.arange(len(mlist_1))
+>>> mser_1 = TS.time_series(mdata_1, mlist_1, observed='SUMMED')
+}}}
+Note that the frequency is 'U', for undefined. In fact, you have to specify what kind of data is actually missing by forcing a given frequency.
+{{{#!python numbers=disable
+>>> mser = mser1.asfreq('M')
+}}}
+Let us check whether there are some duplicated dates (no):
+{{{#!python numbers=disable
+>>> mser1.has_duplicated_dates()
+}}}
+...or missing dates (yes):
+{{{#!python numbers=disable
+>>> mser1.has_missing_dates()
+}}}
+Let us construct a second monthly series, this time without missing dates
+{{{#!python numbers=disable
+>>> mlist_2 = ['2004-%02i' % i for i in range(1,13)]
+>>> mlist_2 += ['2005-%02i' % i for i in range(1,13)]
+>>> mser_2 = TS.time_series(N.arange(len(mlist_2)), mlist_2, observed='SUMMED')
+}}}
+Let's try to add the two series:
+{{{#!python numbers=disable
+>>> mser_3 = mser_1 + mser_2
+}}}
+That doesn't work, as the series have different starting dates. We need to align them first.
+{{{#!python numbers=disable
+>>> (malg_1,malg_2) = aligned(mser_1, mser_2) 
+}}}
+That still doesnt' work, as `malg_1` has missing dates. Let us fill it, then: data falling on a date that was missing will be masked.
+{{{#!python numbers=disable
+>>> mser_1_filled = fill_missing_dates(mser_1)
+>>> (malg_1,malg_2) = align_series(mser_1_filled, mser_2) 
+}}}
+Now we can add the two series. Only the data that fall on dates common to the original, non-aligned series will be actually added, the others will be masked. After all, we are adding masked arrays.
+{{{#!python numbers=disable
+>>> mser_3 = malg_1 + malg_2
+}}}
+We could have filled the initial series first:
+{{{#!python numbers=disable
+>>> mser_3 = filled(malg_1,0) + filled(malg_2,0)
+}}}
+Alternatively, we can force the series to start/end at some given dates
+{{{#!python numbers=disable
+>>> (malg_1,malg_2) = aligned(mser_1_filled, mser2, 
+>>>                           start_date='2004-06', end_date='2006-06')
+}}}
+
+
+==== TimeSeries Conversion ====
+
+To convert a TimeSeries to another frequency, use the `convert` method or function. The optional argument `func` must be a function that acts on a 1D masked array and returns a scalar. 
+{{{#!python numbers=disable
+>>> mseries = series.convert('M',func=ma.average)
+}}}
+If `func` is not specified, the default value `'auto'` is used instead. In that case,
+the conversion function is estimated from the `observed` attribute of the series.
+For example, if `observed='SUMMED'`, then `func='auto'` is in fact `func=sum`.
+{{{#!python  numbers=disable
+>>> mseries_default = series.convert('M')
+}}}
+If `func` is None, the convert method/function returns a 2D array, where each row corresponds to the new frequency, and the columns to the original data. In our example, `convert` will return a 2D array with 23 columns, as there are at most 23 business days per month.
+{{{#!python numbers=disable
+>>> mseries_2d = series.convert('M',func=None)
+}}}
+When converting from a lower frequency to a higher frequency, an extra argument `position` is required. The value of the argument is either 'START' or 'END', and determines where the data point will be placed in the period. In the future, interpolation methods will be supported to fill in the resulting masked values.
+
+Let us create a second series, this time with a monthly frequency, starting 110 months ago.
+{{{#!python numbers=disable
+>>> data = N.random.uniform(-100,100,100).astype(np.float_)
+>>> today = TS.today.asfreq('M') - 110
+>>> nseries = TS.TimeSeries(data, freq='m', observed='END',start_date=today)
+>>> sixtymonthsago = today-60
+>>> nseries[sixtymonthsago:sixtymonthsago+10] = 12
+}}}
+


Property changes on: trunk/Lib/sandbox/timeseries/examples/example.wiki
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/Lib/sandbox/timeseries/readme.txt
===================================================================
--- trunk/Lib/sandbox/timeseries/readme.txt	2007-01-23 05:45:43 UTC (rev 2590)
+++ trunk/Lib/sandbox/timeseries/readme.txt	2007-01-23 08:21:33 UTC (rev 2591)
@@ -4,7 +4,7 @@
    code requires access to a couple of the header files included with this module when compiling
 2. Only tested with numpy 1.0.1
 3. Only tested with Python 2.4.x
-4. Only tested on Windows Platform
+4. Only tested on Windows and x86_64 Platform
 5. Requires maskedarray from the sandbox (not the standard masked array module with numpy)
    
 

Modified: trunk/Lib/sandbox/timeseries/tdates.py
===================================================================
--- trunk/Lib/sandbox/timeseries/tdates.py	2007-01-23 05:45:43 UTC (rev 2590)
+++ trunk/Lib/sandbox/timeseries/tdates.py	2007-01-23 08:21:33 UTC (rev 2591)
@@ -337,7 +337,7 @@
         if self.freq == "A":
             fmt =  "%Y"
         elif self.freq in ("B","D"):
-            fmt =  "%d-%b-%y"
+            fmt =  "%d-%b-%Y"
         elif self.freq == "M":
             fmt =  "%b-%Y"
         elif self.freq == "Q":
@@ -541,14 +541,15 @@
                 index = self.find_dates(index)       
             except AttributeError:
                 pass     
-        r = ndarray.__getitem__(self, index)
-
+        r = ndarray.__getitem__(self, index)
         if not hasattr(r, "size"):
-            if type(r) == types.IntType: return Date(self.freq, value=r)
-            else: return r
-        elif r.size == 1:
+            if isinstance(r, int): 
+                return Date(self.freq, value=r)
+            else: 
+                return r
+        elif r.size == 1:
             # Only one element, and it's not a scalar: we have a DateArray of size 1
-            if len(r.shape) > 0:
+            if len(numeric.shape(r)) > 0:
                 r = r.item()
             return Date(self.freq, value=r)
         else:




More information about the Scipy-svn mailing list