TimeSeries concatenate
I'm having trouble with concatenate in scikits.timeseries. I can't find (timeseries) concatenate documented, but I did find an example from a few years ago (http://projects.scipy.org/scipy/changeset/3570), so maybe this isn't supported. Here's what I get when I try to use the timeseries concatenate. In [82]: import scikits.timeseries as ts In [83]: ts1 = ts.time_series(data=[1,2,3], start_date=ts.now('d')) In [84]: ts2 = ts.time_series(data=[4,5,6], start_date=ts.now('d')+1) In [85]: ts.concatenate(ts1, ts2) --------------------------------------------------------------------------- <type 'exceptions.AttributeError'> Traceback (most recent call last) /Users/Shared/Develop/Financial/LakMerc/Mercury/tests/<ipython console> in <module>() /Library/Frameworks/Python.framework/Versions/2.5.2001/lib/python2.5/ site-packages/scikits/timeseries/tseries.py in concatenate(series, axis, remove_duplicates, fill_missing) 1950 """ 1951 # Get the common frequency, raise an error if incompatibility -> 1952 common_f = _compare_frequencies(*series) 1953 # Concatenate the order of series 1954 sidx = np.concatenate([np.repeat(i,len(s)) /Library/Frameworks/Python.framework/Versions/2.5.2001/lib/python2.5/ site-packages/scikits/timeseries/tseries.py in _compare_frequencies(*series) 284 frequencies. 285 """ --> 286 unique_freqs = np.unique([x.freqstr for x in series]) 287 try: 288 common_freq = unique_freqs.item() <type 'exceptions.AttributeError'>: 'numpy.int32' object has no attribute 'freqstr'
This was user error, of course. I needed an extra set of parens: ts.concatenate( (ts1, ts2) ) Question: What happens to duplicate dates? It seems that the data in the first series is used. Is that the rule? thanks, -robert On May 22, 2009, at 7:02 AM, Robert Ferrell wrote:
I'm having trouble with concatenate in scikits.timeseries. I can't find (timeseries) concatenate documented, but I did find an example from a few years ago (http://projects.scipy.org/scipy/changeset/3570), so maybe this isn't supported.
Here's what I get when I try to use the timeseries concatenate.
In [82]: import scikits.timeseries as ts
In [83]: ts1 = ts.time_series(data=[1,2,3], start_date=ts.now('d'))
In [84]: ts2 = ts.time_series(data=[4,5,6], start_date=ts.now('d')+1)
In [85]: ts.concatenate(ts1, ts2) --------------------------------------------------------------------------- <type 'exceptions.AttributeError'> Traceback (most recent call last)
/Users/Shared/Develop/Financial/LakMerc/Mercury/tests/<ipython console> in <module>()
/Library/Frameworks/Python.framework/Versions/2.5.2001/lib/python2.5/ site-packages/scikits/timeseries/tseries.py in concatenate(series, axis, remove_duplicates, fill_missing) 1950 """ 1951 # Get the common frequency, raise an error if incompatibility -> 1952 common_f = _compare_frequencies(*series) 1953 # Concatenate the order of series 1954 sidx = np.concatenate([np.repeat(i,len(s))
/Library/Frameworks/Python.framework/Versions/2.5.2001/lib/python2.5/ site-packages/scikits/timeseries/tseries.py in _compare_frequencies(*series) 284 frequencies. 285 """ --> 286 unique_freqs = np.unique([x.freqstr for x in series]) 287 try: 288 common_freq = unique_freqs.item()
<type 'exceptions.AttributeError'>: 'numpy.int32' object has no attribute 'freqstr'
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
Question: What happens to duplicate dates? It seems that the data in the first series is used. Is that the rule?
One thing I would recommend (which is not obvious to new python users many times) is to check the function doc strings using the built in "help" function (see below). So to answer your question, yes that is the rule IF the `remove_duplicates` parameter is set to "True" (which is the default). - Matt
import scikits.timeseries as ts help(ts.concatenate) Help on function concatenate in module scikits.timeseries.tseries:
concatenate(series, axis=0, remove_duplicates=True, fill_missing=False) Joins series together. The series are joined in chronological order. Duplicated dates are handled with the `remove_duplicates` parameter. If `remove_duplicate` is False, duplicated dates are saved. Otherwise, only the first occurence of the date is conserved. Parameters ---------- series : {sequence} Sequence of time series to join axis : {0, None, int}, optional Axis along which to join remove_duplicates : {False, True}, optional Whether to remove duplicated dates. fill_missing : {False, True}, optional Whether to fill the missing dates with missing values. Examples -------- >>> a = time_series([1,2,3], start_date=now('D')) >>> b = time_series([10,20,30], start_date=now('D')+1) >>> c = concatenate((a,b)) >>> c._series masked_array(data = [ 1 2 3 30], mask = False, fill_value=999999)
Thanks for the gentle reminder about help(). Sometimes I remember - hopefully more often now. That does indeed have exactly the information I was looking for. -robert On May 22, 2009, at 2:16 PM, Matt Knox wrote:
Question: What happens to duplicate dates? It seems that the data in the first series is used. Is that the rule?
One thing I would recommend (which is not obvious to new python users many times) is to check the function doc strings using the built in "help" function (see below). So to answer your question, yes that is the rule IF the `remove_duplicates` parameter is set to "True" (which is the default).
- Matt
import scikits.timeseries as ts help(ts.concatenate) Help on function concatenate in module scikits.timeseries.tseries:
concatenate(series, axis=0, remove_duplicates=True, fill_missing=False) Joins series together.
The series are joined in chronological order. Duplicated dates are handled with the `remove_duplicates` parameter. If `remove_duplicate` is False, duplicated dates are saved. Otherwise, only the first occurence of the date is conserved.
Parameters ---------- series : {sequence} Sequence of time series to join axis : {0, None, int}, optional Axis along which to join remove_duplicates : {False, True}, optional Whether to remove duplicated dates. fill_missing : {False, True}, optional Whether to fill the missing dates with missing values.
Examples --------
a = time_series([1,2,3], start_date=now('D')) b = time_series([10,20,30], start_date=now('D')+1) c = concatenate((a,b)) c._series masked_array(data = [ 1 2 3 30], mask = False, fill_value=999999)
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
participants (2)
-
Matt Knox
-
Robert Ferrell