Saturday, August 15, 2009

Frequency Conversion UFunc

The interesting thing about the astype() frequency conversion is the second argument. astype operates on a narray of datetime64 (or timedelta64) types and accepts one argument of a string representing a dtype (either datetime64[X] or timedelta64[X]). I don't know what Generic UFunc to use to handle these inputs. Most ufuncs operate on inputs like narray of floats + narray of floats to result an narray of floats. This ufunc takes an array of datetime64 and a string.

Looks like more internal NumPy work.

2 comments:

  1. is the frequency conversion function going to support a "relation" parameter like in the asfreq function in the scikits.timeseries package? This optional parameter is used when going from a lower frequency to a higher frequency (eg. monthly to daily) so you can specify if you want the result to be the first period or last period (eg. first day of month or last day of month).

    It may not be obvious at first what one would use this for, but my typical example would be when "comparing" a daily series like a stock price index to some general economic data like inflation or gdp. Rather than using the lowest frequency of the input series, one could use the highest frequency and then "forward fill" or somehow interpolate the lower frequency series after converting them.

    ReplyDelete
  2. I noticed the "relation" parameter when I was looking through TimeSeries. I was thinking about that and custom "start" dates for things like weeks (instead of making the default "Sunday".

    They're great ideas, and like you said, very helpful in some situations. I'll look into working them sometime down the road.

    ReplyDelete