Changeset 1050

Show
Ignore:
Timestamp:
06/22/08 16:41:09 (2 months ago)
Author:
mattknox_ca
Message:

in align_series, if series have missing dates, fill them first (rather than raising error)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/timeseries/scikits/timeseries/tseries.py

    r1048 r1050  
    13761376def align_series(*series, **kwargs): 
    13771377    """Aligns several TimeSeries, so that their starting and ending dates match. 
    1378     Series are resized and filled with mased values accordingly. 
     1378    Series are resized and filled with masked values accordingly. The resulting 
     1379    series have no missing dates (ie. series.isvalid() == True for each of the 
     1380    resulting series). 
    13791381 
    13801382    The function accepts two extras parameters: 
     
    13881390    unique_freqs = np.unique([x.freqstr for x in series]) 
    13891391    common_freq = _compare_frequencies(*series) 
    1390     valid_states = [x.isvalid() for x in series] 
    1391     if not np.all(valid_states): 
    1392         raise TimeSeriesError, \ 
    1393             "Cannot adjust a series with missing or duplicated dates." 
     1392 
     1393    # if any of the series have missing dates, fill them in first 
     1394    filled_series = [] 
     1395    for ser in series: 
     1396        if ser.isvalid(): 
     1397            filled_series.append(ser) 
     1398        else: 
     1399            filled_series.append(ser.fill_missing_dates()) 
    13941400 
    13951401    start_date = kwargs.pop('start_date', 
    1396                             min([x.start_date for x in series 
     1402                            min([x.start_date for x in filled_series 
    13971403                                     if x.start_date is not None])) 
    13981404    if isinstance(start_date,str): 
    13991405        start_date = Date(common_freq, string=start_date) 
    14001406    end_date = kwargs.pop('end_date', 
    1401                           max([x.end_date for x in series 
     1407                          max([x.end_date for x in filled_series 
    14021408                                   if x.end_date is not None])) 
    14031409    if isinstance(end_date,str): 
    14041410        end_date = Date(common_freq, string=end_date) 
    14051411 
    1406     return [adjust_endpoints(x, start_date, end_date) for x in series] 
     1412    return [adjust_endpoints(x, start_date, end_date) for x in filled_series] 
    14071413aligned = align_series 
    14081414