[Scipy-svn] r2799 - in trunk/Lib/sandbox/timeseries: . io plotlib tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Wed Feb 28 23:43:15 EST 2007
Author: pierregm
Date: 2007-02-28 22:43:08 -0600 (Wed, 28 Feb 2007)
New Revision: 2799
Added:
trunk/Lib/sandbox/timeseries/.project
Modified:
trunk/Lib/sandbox/timeseries/extras.py
trunk/Lib/sandbox/timeseries/io/__init__.py
trunk/Lib/sandbox/timeseries/parser.py
trunk/Lib/sandbox/timeseries/plotlib/__init__.py
trunk/Lib/sandbox/timeseries/readme.txt
trunk/Lib/sandbox/timeseries/reportlib.py
trunk/Lib/sandbox/timeseries/setup.py
trunk/Lib/sandbox/timeseries/tests/test_misc.py
trunk/Lib/sandbox/timeseries/tests/test_timeseries.py
trunk/Lib/sandbox/timeseries/tseries.py
Log:
tseries : fixed pickling w/ multi-variables
Added: trunk/Lib/sandbox/timeseries/.project
===================================================================
--- trunk/Lib/sandbox/timeseries/.project 2007-03-01 04:05:32 UTC (rev 2798)
+++ trunk/Lib/sandbox/timeseries/.project 2007-03-01 04:43:08 UTC (rev 2799)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>scipy_svn_timeseries</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.python.pydev.PyDevBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.python.pydev.pythonNature</nature>
+ </natures>
+</projectDescription>
Modified: trunk/Lib/sandbox/timeseries/extras.py
===================================================================
--- trunk/Lib/sandbox/timeseries/extras.py 2007-03-01 04:05:32 UTC (rev 2798)
+++ trunk/Lib/sandbox/timeseries/extras.py 2007-03-01 04:43:08 UTC (rev 2799)
@@ -4,12 +4,12 @@
:author: Pierre GF Gerard-Marchant & Matt Knox
:contact: pierregm_at_uga_dot_edu - mattknox_ca_at_hotmail_dot_com
-:version: $Id: tcore.py 2752 2007-02-22 20:50:12Z mattknox_ca $
+:version: $Id$
"""
-__author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author: mattknox_ca $)"
+__author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author$)"
__version__ = '1.0'
-__revision__ = "$Revision: 2752 $"
-__date__ = '$Date: 2007-02-22 15:50:12 -0500 (Thu, 22 Feb 2007) $'
+__revision__ = "$Revision$"
+__date__ = '$Date$'
__all__ = [
'forward_fill', 'backward_fill', 'interp_masked1d',
Property changes on: trunk/Lib/sandbox/timeseries/extras.py
___________________________________________________________________
Name: svn:keywords
+ Date
Author
Revision
Id
Property changes on: trunk/Lib/sandbox/timeseries/io/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Date
Author
Revision
Id
Property changes on: trunk/Lib/sandbox/timeseries/parser.py
___________________________________________________________________
Name: svn:keywords
+ Date
Author
Revision
Id
Property changes on: trunk/Lib/sandbox/timeseries/plotlib/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Date
Author
Revision
Id
Property changes on: trunk/Lib/sandbox/timeseries/readme.txt
___________________________________________________________________
Name: svn:keywords
+ Date
Author
Revision
Id
Modified: trunk/Lib/sandbox/timeseries/reportlib.py
===================================================================
--- trunk/Lib/sandbox/timeseries/reportlib.py 2007-03-01 04:05:32 UTC (rev 2798)
+++ trunk/Lib/sandbox/timeseries/reportlib.py 2007-03-01 04:43:08 UTC (rev 2799)
@@ -3,7 +3,7 @@
:author: Pierre GF Gerard-Marchant & Matt Knox
:contact: pierregm_at_uga_dot_edu - mattknox_ca_at_hotmail_dot_com
-:version: $Id: tdates.py 2641 2007-01-30 18:40:17Z mattknox_ca $
+:version: $Id$
Ideas borrowed from:
@@ -52,10 +52,10 @@
html_o.write("</table>")
"""
-__author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author: mattknox_ca $)"
+__author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author$)"
__version__ = '1.0'
-__revision__ = "$Revision: 2641 $"
-__date__ = '$Date: 2007-01-30 13:40:17 -0500 (Tue, 30 Jan 2007) $'
+__revision__ = "$Revision$"
+__date__ = '$Date$'
import sys
import operator, types, copy
Property changes on: trunk/Lib/sandbox/timeseries/reportlib.py
___________________________________________________________________
Name: svn:keywords
+ Date
Author
Revision
Id
Modified: trunk/Lib/sandbox/timeseries/setup.py
===================================================================
--- trunk/Lib/sandbox/timeseries/setup.py 2007-03-01 04:05:32 UTC (rev 2798)
+++ trunk/Lib/sandbox/timeseries/setup.py 2007-03-01 04:43:08 UTC (rev 2799)
@@ -1,7 +1,7 @@
#!/usr/bin/env python
__version__ = '1.0'
-__revision__ = "$Revision: 37 $"
-__date__ = '$Date: 2006-12-08 14:30:29 -0500 (Fri, 08 Dec 2006) $'
+__revision__ = "$Revision$"
+__date__ = '$Date$'
import os
from os.path import join
Property changes on: trunk/Lib/sandbox/timeseries/setup.py
___________________________________________________________________
Name: svn:keywords
+ Date
Author
Revision
Id
Modified: trunk/Lib/sandbox/timeseries/tests/test_misc.py
===================================================================
--- trunk/Lib/sandbox/timeseries/tests/test_misc.py 2007-03-01 04:05:32 UTC (rev 2798)
+++ trunk/Lib/sandbox/timeseries/tests/test_misc.py 2007-03-01 04:43:08 UTC (rev 2799)
@@ -4,12 +4,12 @@
:author: Pierre Gerard-Marchant & Matt Knox
:contact: pierregm_at_uga_dot_edu & mattknox_ca_at_hotmail_dot_com
-:version: $Id: test_timeseries.py 2578 2007-01-17 19:25:10Z mattknox_ca $
+:version: $Id$
"""
-__author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author: mattknox_ca $)"
+__author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author$)"
__version__ = '1.0'
-__revision__ = "$Revision: 2578 $"
-__date__ = '$Date: 2007-01-17 14:25:10 -0500 (Wed, 17 Jan 2007) $'
+__revision__ = "$Revision$"
+__date__ = '$Date$'
import numpy as N
from numpy import bool_, complex_, float_, int_, object_
Property changes on: trunk/Lib/sandbox/timeseries/tests/test_misc.py
___________________________________________________________________
Name: svn:keywords
+ Date
Author
Revision
Id
Modified: trunk/Lib/sandbox/timeseries/tests/test_timeseries.py
===================================================================
--- trunk/Lib/sandbox/timeseries/tests/test_timeseries.py 2007-03-01 04:05:32 UTC (rev 2798)
+++ trunk/Lib/sandbox/timeseries/tests/test_timeseries.py 2007-03-01 04:43:08 UTC (rev 2799)
@@ -348,7 +348,7 @@
assert_array_equal(shift_negative, shift_negative_result)
assert_array_equal(shift_positive, shift_positive_result)
-
+ #
def test_convert(self):
"""Test convert function
@@ -390,10 +390,9 @@
Date(freq='b', year=2005, month=6, day=1).asfreq('M'))
assert_equal(highToLow.end_date,
(Date(freq='b', year=2005, month=6, day=1) + 99).asfreq('M'))
-
+ #
def test_fill_missing_dates(self):
"""Test fill_missing_dates function"""
-
_start = Date(freq='m', year=2005, month=1)
_end = Date(freq='m', year=2005, month=4)
@@ -406,7 +405,6 @@
assert(filled_ser.isfull())
assert(not filled_ser.has_duplicated_dates())
assert_equal(filled_ser.size, _end - _start + 1)
-
#
def test_maskperiod(self):
"Test mask_period"
@@ -426,13 +424,24 @@
inplace=False)
assert_equal(mask._mask, [1,1,1,1,1,0,0,0,0,0,0,0,1,1,1])
#
- def pickling(self):
+ def test_pickling(self):
"Tests pickling/unpickling"
(series, data, dates) = self.d
- tmp = maskedarray.loads(series.dumps())
- assert_equal(tmp._data, series._data)
- assert_equal(tmp._dates, series._dates)
- assert_equal(tmp._mask, series._mask)
+ import cPickle
+ series_pickled = cPickle.loads(series.dumps())
+ assert_equal(series_pickled._dates, series._dates)
+ assert_equal(series_pickled._data, series._data)
+ assert_equal(series_pickled._mask, series._mask)
+ #
+ data = masked_array(N.matrix(range(10)).T, mask=[1,0,0,0,0]*2)
+ dates = date_array(start_date=thisday('D'), length=10)
+ series = time_series(data,dates=dates)
+ series_pickled = cPickle.loads(series.dumps())
+ assert_equal(series_pickled._dates, series._dates)
+ assert_equal(series_pickled._data, series._data)
+ assert_equal(series_pickled._mask, series._mask)
+ assert(isinstance(series_pickled._data, N.matrix))
+
def test_empty_timeseries(self):
"Tests that empty TimeSeries are handled properly"
Modified: trunk/Lib/sandbox/timeseries/tseries.py
===================================================================
--- trunk/Lib/sandbox/timeseries/tseries.py 2007-03-01 04:05:32 UTC (rev 2798)
+++ trunk/Lib/sandbox/timeseries/tseries.py 2007-03-01 04:43:08 UTC (rev 2799)
@@ -29,6 +29,7 @@
import numpy
from numpy import ndarray
from numpy.core import bool_, complex_, float_, int_, object_
+from numpy.core.multiarray import dtype
import numpy.core.fromnumeric as fromnumeric
import numpy.core.numeric as numeric
import numpy.core.umath as umath
@@ -292,7 +293,7 @@
_defaultobserved = None
_genattributes = ['fill_value', 'observed']
def __new__(cls, data, dates=None, mask=nomask,
- freq=None, observed=None, start_date=None,
+ freq=None, observed=None, start_date=None, length=None,
dtype=None, copy=False, fill_value=None,
keep_mask=True, small_mask=True, hard_mask=False, **options):
maparms = dict(copy=copy, dtype=dtype, fill_value=fill_value,
@@ -315,6 +316,8 @@
else:
dshape = _data.shape
if len(dshape) > 0:
+ if length is None:
+ length = dshape[0]
newdates = date_array(start_date=start_date, length=dshape[0],
freq=freq)
else:
@@ -688,7 +691,55 @@
for attr in attrlist:
if not attr in exclude:
setattr(self, attr, getattr(oldseries, attr))
+ #......................................................
+ # Pickling
+ def __getstate__(self):
+ "Returns the internal state of the TimeSeries, for pickling purposes."
+ # raise NotImplementedError,"Please use timeseries.archive/unarchive instead."""
+ state = (1,
+ self.shape,
+ self.dtype,
+ self.flags.fnc,
+ self._data.tostring(),
+ getmaskarray(self).tostring(),
+ self._fill_value,
+ self._dates.shape,
+ numeric.asarray(self._dates).tostring(),
+ self.freq,
+ )
+ return state
+ #
+ def __setstate__(self, state):
+ """Restores the internal state of the TimeSeries, for pickling purposes.
+ `state` is typically the output of the ``__getstate__`` output, and is a 5-tuple:
+ - class name
+ - a tuple giving the shape of the data
+ - a typecode for the data
+ - a binary string for the data
+ - a binary string for the mask.
+ """
+ (ver, shp, typ, isf, raw, msk, flv, dsh, dtm, frq) = state
+ super(TimeSeries, self).__setstate__((ver, shp, typ, isf, raw, msk, flv))
+ self._dates.__setstate__((dsh, dtype(int_), isf, dtm))
+ self._dates.freq = frq
+#
+ def __reduce__(self):
+ """Returns a 3-tuple for pickling a MaskedArray."""
+ return (_tsreconstruct,
+ (self.__class__, self._baseclass,
+ self.shape, self._dates.shape, self.dtype, self._fill_value),
+ self.__getstate__())
+
+def _tsreconstruct(genclass, baseclass, baseshape, dateshape, basetype, fill_value):
+ """Internal function that builds a new TimeSeries from the information stored
+ in a pickle."""
+ # raise NotImplementedError,"Please use timeseries.archive/unarchive instead."""
+ _series = ndarray.__new__(baseclass, baseshape, basetype)
+ _dates = ndarray.__new__(DateArray, dateshape, int_)
+ _mask = ndarray.__new__(ndarray, baseshape, bool_)
+ return genclass.__new__(genclass, _series, dates=_dates, mask=_mask,
+ dtype=basetype, fill_value=fill_value)
def _attrib_dict(series, exclude=[]):
"""this function is used for passing through attributes of one
@@ -828,61 +879,7 @@
#####---------------------------------------------------------------------------
#---- --- Archiving ---
#####---------------------------------------------------------------------------
-def _tsreconstruct(baseclass, datesclass, baseshape, basetype, fill_value):
- """Internal function that builds a new TimeSeries from the information stored
-in a pickle."""
-# raise NotImplementedError,"Please use timeseries.archive/unarchive instead."""
- _series = ndarray.__new__(ndarray, baseshape, basetype)
- _dates = ndarray.__new__(datesclass, baseshape, int_)
- _mask = ndarray.__new__(ndarray, baseshape, bool_)
- return baseclass.__new__(baseclass, _series, dates=_dates, mask=_mask,
- dtype=basetype, fill_value=fill_value)
-#
-def _tsgetstate(a):
- "Returns the internal state of the TimeSeries, for pickling purposes."
-# raise NotImplementedError,"Please use timeseries.archive/unarchive instead."""
- records = a.asrecords()
- state = (1,
- a.shape,
- a.dtype,
- a.freq,
- records.flags.fnc,
- a.fill_value,
- records
- )
- return state
-#
-def _tssetstate(a, state):
- """Restores the internal state of the TimeSeries, for pickling purposes.
-`state` is typically the output of the ``__getstate__`` output, and is a 5-tuple:
- - class name
- - a tuple giving the shape of the data
- - a typecode for the data
- - a binary string for the data
- - a binary string for the mask.
- """
- (ver, shp, typ, frq, isf, flv, rec) = state
- a.fill_value = flv
- a._dates = a._dates.__class__(rec['_dates'], freq=frq)
- (a._dates).__tostr = None
- _data = rec['_series'].view(typ)
- _mask = rec['_mask'].view(MA.MaskType)
- a._series = masked_array(_data, mask=_mask)
-# a._data.shape = shp
-# a._dates.shape = shp
-# a._mask = rec['_mask'].view(MA.MaskType)
-# a._mask.shape = shp
-#
-def _tsreduce(a):
- """Returns a 3-tuple for pickling a MaskedArray."""
- return (_tsreconstruct,
- (a.__class__, a.dates.__class__, (0,), 'b', -9999),
- a.__getstate__())
-#
-TimeSeries.__getstate__ = _tsgetstate
-TimeSeries.__setstate__ = _tssetstate
-TimeSeries.__reduce__ = _tsreduce
#TimeSeries.__dump__ = dump
#TimeSeries.__dumps__ = dumps
@@ -1413,18 +1410,25 @@
pass
assert_equal(ser3d.transpose(0,2,1).shape, (5,2,3))
- if 1:
- data = dates
-
- series = time_series(data, dates)
- assert(isinstance(series, TimeSeries))
- assert_equal(series._dates, dates)
- assert_equal(series._data, data)
- assert_equal(series.freqstr, 'D')
+ if 1:
+ dlist = ['2007-01-%02i' % i for i in range(1,11)]
+ dates = date_array_fromlist(dlist)
+ data = masked_array(numeric.arange(10), mask=[1,0,0,0,0]*2, dtype=float_)
+ series = time_series(data, dlist)
+ #
+ import cPickle
+ series_pickled = cPickle.loads(series.dumps())
+ assert_equal(series_pickled._dates, series._dates)
+ assert_equal(series_pickled._data, series._data)
+ assert_equal(series_pickled._mask, series._mask)
+ #
+ data = masked_array(N.matrix(range(10)).T, mask=[1,0,0,0,0]*2)
+ dates = date_array(start_date=thisday('D'), length=10)
+ series = time_series(data,dates=dates)
+ series_pickled = cPickle.loads(series.dumps())
+ assert_equal(series_pickled._dates, series._dates)
+ assert_equal(series_pickled._data, series._data)
+ assert_equal(series_pickled._mask, series._mask)
+ assert(isinstance(series_pickled._data, N.matrix))
- series[5] = MA.masked
-
- # ensure that series can be represented by a string after masking a value
- # (there was a bug before that prevented this from working when using a
- # DateArray for the data)
- strrep = str(series)
+
\ No newline at end of file
More information about the Scipy-svn
mailing list