Changeset 1204
- Timestamp:
- 08/07/08 00:52:15 (4 months ago)
- Files:
-
- trunk/timeseries/scikits/timeseries/tdates.py (modified) (6 diffs)
- trunk/timeseries/scikits/timeseries/tseries.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/timeseries/scikits/timeseries/tdates.py
r1151 r1204 98 98 99 99 def prevbusday(day_end_hour=18, day_end_min=0): 100 """Returns the previous business day (Monday-Friday) at business frequency. 100 """ 101 Returns the previous business day (Monday-Friday) at business frequency. 101 102 102 103 Parameters … … 111 112 now('Business') will be returned. Otherwise, now('Business')-1 will be 112 113 returned. 113 """ 114 115 """ 114 116 tempDate = dt.datetime.now() 115 117 dateNum = tempDate.hour + float(tempDate.minute)/60 … … 177 179 178 180 class DateArray(ndarray): 179 """Defines a ndarray of dates, as ordinals. 180 181 When viewed globally (array-wise), DateArray is an array of integers. 182 When viewed element-wise, DateArray is a sequence of dates. 183 For example, a test such as : 184 >>> DateArray(...) = value 185 will be valid only if value is an integer, not a Date 186 However, a loop such as : 187 >>> for d in DateArray(...): 188 accesses the array element by element. Therefore, `d` is a Date object. 181 """ 182 Defines a ndarray of dates, as ordinals. 183 184 When viewed globally (array-wise), DateArray is an array of integers. 185 When viewed element-wise, DateArray is a sequence of dates. 186 For example, a test such as : 187 >>> DateArray(...) = value 188 will be valid only if value is an integer, not a Date 189 However, a loop such as : 190 >>> for d in DateArray(...): 191 accesses the array element by element. Therefore, `d` is a Date object. 189 192 """ 190 193 def __new__(cls, dates=None, freq=None, copy=False): … … 320 323 @property 321 324 def qyear(self): 322 """For quarterly frequency dates, returns the year corresponding to the 323 year end (start) month. When using QTR or QTR-E based quarterly 324 frequencies, this is the fiscal year in a financial context. 325 326 For non-quarterly dates, this simply returns the year of the date.""" 325 """ 326 For quarterly frequency dates, returns the year corresponding to the 327 year end (start) month. When using QTR or QTR-E based quarterly 328 frequencies, this is the fiscal year in a financial context. 329 330 For non-quarterly dates, this simply returns the year of the date. 331 332 """ 327 333 328 334 return self.__getdateinfo__('F') … … 400 406 # 401 407 def asfreq(self, freq=None, relation="END"): 402 """Converts the dates to another frequency. 403 404 *Parameters*: 408 """ 409 410 Converts the dates to another frequency. 411 412 Parameters 413 ---------- 405 414 freq : {freq_spec} 406 415 Frequency to convert the DateArray to. Accepts any valid frequency … … 414 423 For example, if converting a monthly date to a daily date, specifying 415 424 'START' ('END') would result in the first (last) day in the month. 416 """ 425 426 """ 417 427 # Note: As we define a new object, we don't need caching 418 428 if freq is None or freq == _c.FR_UND: trunk/timeseries/scikits/timeseries/tseries.py
r1203 r1204 879 879 original series (unlike the `convert` method). 880 880 881 *Parameters*: 881 Parameters 882 ---------- 882 883 freq : {freq_spec} 883 884 relation : {'END', 'START'} (optional) 884 885 885 *Returns*: 886 a new TimeSeries with the .dates DateArray at the specified frequency (the 887 .asfreq method of the .dates property will be called). The data in the 886 Returns 887 ------- 888 A new TimeSeries with the .dates DateArray at the specified frequency (the 889 `.asfreq` method of the .dates property will be called). The data in the 888 890 resulting series will be a VIEW of the original series. 889 891 890 *Notes*: 892 Notes 893 ----- 891 894 The parameters are the exact same as for DateArray.asfreq , please see the 892 895 __doc__ string for that method for details on the parameters and how the … … 899 902 #..................................................... 900 903 def transpose(self, *axes): 901 """Returns a view of the series with axes transposed 902 903 *Parameters*: 904 *axes : {integers} 905 the axes to swap 906 907 *Returns*: 908 a VIEW of the series with axes for both the data and dates transposed 909 910 *Notes*: 904 """ 905 Returns a view of the series with axes transposed 906 907 Parameters 908 ---------- 909 axes : {integers} 910 The axes to swap 911 912 Returns 913 ------- 914 A VIEW of the series with axes for both the data and dates transposed 915 916 Notes 917 ----- 911 918 If no axes are given, the order of the axes are switches. For a 2-d array, 912 919 this is the usual matrix transpose. If axes are given, they describe how … … 937 944 938 945 def filled(self, fill_value=None): 939 """Returns an array of the same class as `_data`, with masked values 940 filled with `fill_value`. Subclassing is preserved. 946 """ 947 948 Returns an array of the same class as `_data`, with masked values 949 filled with `fill_value`. Subclassing is preserved. 941 950 942 951 Parameters … … 951 960 952 961 def tolist(self): 953 """Returns the dates and data portion of the TimeSeries "zipped" up in 954 a list of standard python objects (eg. datetime, int, etc...).""" 962 """ 963 Returns the dates and data portion of the TimeSeries "zipped" up in 964 a list of standard python objects (eg. datetime, int, etc...). 965 966 """ 955 967 if self.ndim > 0: 956 968 return zip(self.dates.tolist(), self.series.tolist()) … … 961 973 # Pickling 962 974 def __getstate__(self): 963 "Returns the internal state of the TimeSeries, for pickling purposes." 975 """ 976 977 Returns the internal state of the TimeSeries, for pickling purposes. 978 """ 964 979 # raise NotImplementedError,"Please use timeseries.archive/unarchive instead.""" 965 980 state = (1, … … 977 992 # 978 993 def __setstate__(self, state): 979 """Restores the internal state of the TimeSeries, for pickling purposes. 994 """ 995 996 Restores the internal state of the TimeSeries, for pickling purposes. 980 997 `state` is typically the output of the ``__getstate__`` output, and is a 5-tuple: 981 998 … … 1600 1617 #............................................................................... 1601 1618 def tshift(series, nper, copy=True): 1602 """Returns a series of the same size as `series`, with the same 1603 start_date and end_date, but values shifted by `nper`. 1604 1605 *Parameters*: 1606 series : {TimeSeries} 1619 """ 1620 Returns a series of the same size as `series`, with the same `start_date` 1621 and `end_date`, but values shifted by `nper`. 1622 1623 Parameters 1624 ---------- 1625 series : TimeSeries 1607 1626 TimeSeries object to shift. Ignore this parameter if calling this as a 1608 1627 method. 1609 nper : {int}1628 nper : int 1610 1629 number of periods to shift. Negative numbers shift values to the 1611 1630 right, positive to the left 1612 copy : {True, False} (optional)1631 copy : {True, False}, optional 1613 1632 copies the data if True, returns a view if False. 1614 1633 1615 *Example*: 1616 >>> series = time_series([0,1,2,3], start_date=Date(freq='A', year=2005)) 1617 >>> series 1618 timeseries(data = [0 1 2 3], 1619 dates = [2005 ... 2008], 1620 freq = A-DEC) 1621 >>> tshift(series, -1) 1622 timeseries(data = [-- 0 1 2], 1623 dates = [2005 ... 2008], 1624 freq = A-DEC) 1625 >>> pct_change = 100 * (series/series.tshift(-1, copy=False) - 1) 1626 """ 1634 Example 1635 ------- 1636 >>> series = time_series([0,1,2,3], start_date=Date(freq='A', year=2005)) 1637 >>> series 1638 timeseries(data = [0 1 2 3], 1639 dates = [2005 ... 2008], 1640 freq = A-DEC) 1641 >>> tshift(series, -1) 1642 timeseries(data = [-- 0 1 2], 1643 dates = [2005 ... 2008], 1644 freq = A-DEC) 1645 >>> pct_change = 100 * (series/series.tshift(-1, copy=False) - 1) 1646 1647 """ 1627 1648 newdata = masked_array(np.empty(series.shape, dtype=series.dtype), 1628 1649 mask=True) … … 1654 1675 #............................................................................... 1655 1676 def pct(series, nper=1): 1656 """Returns the rolling percentage change of the series. 1657 1658 *Parameters*: 1677 """ 1678 Returns the rolling percentage change of the series. 1679 1680 Parameters 1681 ---------- 1659 1682 series : {TimeSeries} 1660 1683 TimeSeries object to to calculate percentage chage for. Ignore this … … 1663 1686 number of periods for percentage change 1664 1687 1665 *Notes*: 1666 series of integer types will be upcast 1688 Notes 1689 ----- 1690 Series of integer types will be upcast 1667 1691 1.0 == 100% in result 1668 1692 1669 *Example*: 1670 >>> series = time_series([2.,1.,2.,3.], start_date=Date(freq='A', year=2005)) 1671 >>> series.pct() 1672 timeseries([-- -0.5 1.0 0.5], 1673 dates = [2005 ... 2008], 1674 freq = A-DEC) 1675 >>> series.pct(2) 1676 timeseries([-- -- 0.0 2.0], 1677 dates = [2005 ... 2008], 1678 freq = A-DEC) 1679 """ 1693 Examples 1694 -------- 1695 >>> series = time_series([2.,1.,2.,3.], start_date=Date(freq='A', year=2005)) 1696 >>> series.pct() 1697 timeseries([-- -0.5 1.0 0.5], 1698 dates = [2005 ... 2008], 1699 freq = A-DEC) 1700 >>> series.pct(2) 1701 timeseries([-- -- 0.0 2.0], 1702 dates = [2005 ... 2008], 1703 freq = A-DEC) 1704 1705 """ 1680 1706 _dtype = _get_type_num_double(series.dtype) 1681 1707 if _dtype != series.dtype: … … 1692 1718 #............................................................................... 1693 1719 def fill_missing_dates(data, dates=None, freq=None, fill_value=None): 1694 """Finds and fills the missing dates in a time series. The data 1695 corresponding to the initially missing dates are masked, or filled to 1696 `fill_value`. 1697 1698 *Parameters*: 1720 """ 1721 Finds and fills the missing dates in a time series. The data 1722 corresponding to the initially missing dates are masked, or filled to 1723 `fill_value`. 1724 1725 Parameters 1726 ---------- 1699 1727 data : {TimeSeries, ndarray} 1700 1728 Initial array of data. … … 1707 1735 Default value for missing data. If Not specified, the data are just 1708 1736 masked. 1709 """ 1737 1738 """ 1710 1739 # Check the frequency ........ 1711 1740 orig_freq = freq
