# statsmodels/scikits.timeseries-sandbox forked from pierregm/scikits.timeseries-sandbox

* Fix pickling of DateArrays (to keep the frequency)

1 parent 362745c commit 96a9d6bbe38b62e504b25b552101dad43c48dc46 pierregm committed Dec 19, 2009
85 scikits/timeseries/lib/moving_funcs.py
 @@ -148,13 +148,18 @@ def _moving_func(data, cfunc, kwargs): #............................................................................... def _mov_sum(data, span, dtype=None, type_num_double=False): - """ helper function for calculating moving sum. Resulting dtype can be -determined in one of two ways. See C-code for more details.""" + """ + Helper function for calculating moving sum. + Resulting dtype can be determined in one of two ways. + See C-code for more details. + """ kwargs = {'span':span, 'type_num_double':type_num_double} if dtype is not None: kwargs['dtype'] = dtype return _moving_func(data, MA_mov_sum, kwargs) -#............................................................................... + + + def mov_sum(data, span, dtype=None): """ Calculates the moving sum of a series. @@ -166,10 +171,12 @@ def mov_sum(data, span, dtype=None): %(dtype)s %(movfuncresults)s - """ + """ % _doc_parameters return _mov_sum(data, span, dtype=dtype) -#............................................................................... + + + def mov_median(data, span, dtype=None): """ Calculates the moving median of a series. @@ -181,14 +188,16 @@ def mov_median(data, span, dtype=None): %(dtype)s %(movfuncresults)s - """ + """ % _doc_parameters kwargs = {'span':span} if dtype is not None: kwargs['dtype'] = dtype return _moving_func(data, MA_mov_median, kwargs) -#............................................................................... + + + def mov_min(data, span, dtype=None): """ Calculates the moving minimum of a series. @@ -200,14 +209,16 @@ def mov_min(data, span, dtype=None): %(dtype)s %(movfuncresults)s - """ + """ % _doc_parameters kwargs = {'span':span} if dtype is not None: kwargs['dtype'] = dtype return _moving_func(data, MA_mov_min, kwargs) -#............................................................................... + + + def mov_max(data, span, dtype=None): """ Calculates the moving max of a series. @@ -219,14 +230,16 @@ def mov_max(data, span, dtype=None): %(dtype)s %(movfuncresults)s - """ + """ % _doc_parameters kwargs = {'span':span} if dtype is not None: kwargs['dtype'] = dtype return _moving_func(data, MA_mov_max, kwargs) -#............................................................................... + + + def mov_average(data, span, dtype=None): """Calculates the moving average of a series. @@ -237,10 +250,12 @@ def mov_average(data, span, dtype=None): %(dtype)s %(movfuncresults)s - """ + """ % _doc_parameters return _mov_sum(data, span, dtype=dtype, type_num_double=True)/span mov_mean = mov_average -#............................................................................... + + + def mov_var(data, span, dtype=None, ddof=0): """ Calculates the moving variance of a 1-D array. @@ -253,9 +268,11 @@ def mov_var(data, span, dtype=None, ddof=0): %(ddof)s %(movfuncresults)s - """ + """ % _doc_parameters return _mov_cov(data, data, span, ddof, dtype=dtype) -#............................................................................... + + + def mov_std(data, span, dtype=None, ddof=0): """ Calculates the moving standard deviation of a 1-D array. @@ -268,9 +285,11 @@ def mov_std(data, span, dtype=None, ddof=0): %(ddof)s %(movfuncresults)s -""" + """ % _doc_parameters return sqrt(mov_var(data, span, dtype=dtype, ddof=ddof)) -#............................................................................... + + + def _mov_cov(x, y, span, ddof, dtype=None): # helper function denom = span - ddof @@ -284,6 +303,7 @@ def _mov_cov(x, y, span, ddof, dtype=None): return sum_prod/denom - (sum_x * sum_y) / (span*denom) + def mov_cov(x, y, span, bias=0, dtype=None): """ Calculates the moving covariance of two 1-D arrays. @@ -296,10 +316,12 @@ def mov_cov(x, y, span, bias=0, dtype=None): %(dtype)s %(movfuncresults)s - """ + """ % _doc_parameters - if bias==0: ddof = 1 - else: ddof = 0 + if bias==0: + ddof = 1 + else: + ddof = 0 return _mov_cov(x, y, span, ddof, dtype=dtype) #............................................................................... @@ -315,7 +337,7 @@ def mov_corr(x, y, span, dtype=None): %(dtype)s %(movfuncresults)s - """ + """ % _doc_parameters sum_x = _mov_sum(x, span, dtype=dtype, type_num_double=True) sum_y = _mov_sum(y, span, dtype=dtype, type_num_double=True) @@ -330,7 +352,9 @@ def mov_corr(x, y, span, dtype=None): _stddev_y = sqrt(sum_prod/span - (sum_y ** 2) / (span ** 2)) return _covar / (_stddev_x * _stddev_y) -#............................................................................... + + + def mov_average_expw(data, span, tol=1e-6, dtype=None): """ Calculates the exponentially weighted moving average of a series. @@ -349,7 +373,8 @@ def mov_average_expw(data, span, tol=1e-6, dtype=None): %(dtype)s %(movfuncexpwresults)s - """ + """ % _doc_parameters + kwargs = {'span':span} if dtype is not None: kwargs['dtype'] = dtype @@ -362,7 +387,9 @@ def mov_average_expw(data, span, tol=1e-6, dtype=None): result._mask = np.where(marker > tol, True, mask) return result -#............................................................................. + + + def cmov_window(data, span, window_type): """ Applies a centered moving window of type ``window_type`` and size ``span`` @@ -411,8 +438,8 @@ def cmov_window(data, span, window_type): -------- Only ``boxcar`` has been thoroughly tested so far... + """ % _doc_parameters -""" from scipy.signal import convolve, get_window data = marray(data, copy=True, subok=True) @@ -434,6 +461,8 @@ def cmov_window(data, span, window_type): data._mask[:k] = data._mask[-k:] = True return data + + def cmov_average(data, span): """ Computes the centered moving average of size ``span`` on the data. @@ -449,12 +478,8 @@ def cmov_average(data, span): Noting ``k=span//2``, the ``k`` first and ``k`` last data are always masked. If ``data`` has a missing value at position ``i``, then the result has missing values in the interval ``[i-k:i+k+1]``. -""" + """ % _doc_parameters return cmov_window(data, span, 'boxcar') cmov_mean = cmov_average -if __doc__ is not None: - for mf in __all__: - mf_obj = locals()[mf] - mf_obj.__doc__ = mf_obj.__doc__ % _doc_parameters
2 scikits/timeseries/lib/plotlib.py
 @@ -1121,7 +1121,7 @@ def set_datelimits(self, start_date=None, end_date=None): """ errmsg = "The use of 'set_datelimits' is deprecated. "\ "Please use 'set_dlim' instead" - warnings.DepreciationWarning(errmsg) + warnings.warn(errmsg, DeprecationWarning) return self.set_dlim(start_date, end_date) # set_datelims = set_datelimits
48 scikits/timeseries/lib/tests/test_avcf.py
 @@ -34,20 +34,42 @@ def __init__(self,*args,**kwargs): 63, 46, 56, 44, 44, 52, 38, 46, 36, 49, 35, 44, 59, 65, 65, 56, 66, 53, 61, 52, 51, 48, 54, 49, 49, 61,nan,nan, 68, 44, 40, 27, 28, 25, 24, 24] - self.mdeaths = [2134,1863,1877,1877,1492,1249,1280,1131,1209,1492,1621, - 1846,2103,2137,2153,1833,1403,1288,1186,1133,1053,1347, - 1545,2066,2020,2750,2283,1479,1189,1160,1113, 970, 999, - 1208,1467,2059,2240,1634,1722,1801,1246,1162,1087,1013, - 959,1179,1229,1655,2019,2284,1942,1423,1340,1187,1098, - 1004, 970,1140,1110,1812,2263,1820,1846,1531,1215,1075, - 1056, 975, 940,1081,1294,1341] - self.fdeaths = [901, 689, 827, 677, 522, 406, 441, 393, 387, 582, 578, - 666, 830, 752, 785, 664, 467, 438, 421, 412, 343, 440, - 531, 771, 767,1141, 896, 532, 447, 420, 376, 330, 357, - 445, 546, 764, 862, 660, 663, 643, 502, 392, 411, 348, - 387, 385, 411, 638, 796, 853, 737, 546, 530, 446, 431, - 362, 387, 430, 425, 679, 821, 785, 727, 612, 478, 429, + self.mdeaths = [2134, 1863, 1877, 1877, 1492, 1249, + 1280, 1131, 1209, 1492, 1621, 1846, + 2103, 2137, 2153, 1833, 1403, 1288, + 1186, 1133, 1053, 1347, 1545, 2066, + 2020, 2750, 2283, 1479, 1189, 1160, + 1113, 970, 999, 1208, 1467, 2059, + 2240, 1634, 1722, 1801, 1246, 1162, + 1087, 1013, 959, 1179, 1229, 1655, + 2019, 2284, 1942, 1423, 1340, 1187, + 1098, 1004, 970, 1140, 1110, 1812, + 2263, 1820, 1846, 1531, 1215, 1075, + 1056, 975, 940, 1081, 1294, 1341] + self.fdeaths = [901, 689, 827, 677, 522, 406, + 441, 393, 387, 582, 578, 666, + 830, 752, 785, 664, 467, 438, + 421, 412, 343, 440, 531, 771, + 767,1141, 896, 532, 447, 420, + 376, 330, 357, 445, 546, 764, + 862, 660, 663, 643, 502, 392, + 411, 348, 387, 385, 411, 638, + 796, 853, 737, 546, 530, 446, + 431, 362, 387, 430, 425, 679, + 821, 785, 727, 612, 478, 429, 405, 379, 393, 411, 487, 574] + self.ldeaths = [3035, 2552, 2704, 2554, 2014, 1655, + 1721, 1524, 1596, 2074, 2199, 2512, + 2933, 2889, 2938, 2497, 1870, 1726, + 1607, 1545, 1396, 1787, 2076, 2837, + 2787, 3891, 3179, 2011, 1636, 1580, + 1489, 1300, 1356, 1653, 2013, 2823, + 3102, 2294, 2385, 2444, 1748, 1554, + 1498, 1361, 1346, 1564, 1640, 2293, + 2815, 3137, 2679, 1969, 1870, 1633, + 1529, 1366, 1357, 1570, 1535, 2491, + 3084, 2605, 2573, 2143, 1693, 1504, + 1461, 1354, 1333, 1492, 1781, 1915,] self.mdeaths = ma.asarray(self.mdeaths) self.fdeaths = ma.asarray(self.fdeaths)
184 scikits/timeseries/lib/tests/test_tstables.py