Added hooke.util.yaml fixing YAML/NumPy type issues (by dropping data).
[hooke.git] / hooke / curve.py
index 5a32e6d59b8cd2e94902f00e8708d4762cffeb98..12ac5eb98a2cb1cd2339d36d6edb69c16f9e5c82 100644 (file)
@@ -87,6 +87,14 @@ class Data (numpy.ndarray):
            [ 20.,  21.]])
     >>> z.info
     {'columns': ['distance (m)', 'force (N)']}
+
+    The data-type is also YAMLable (see :mod:`hooke.util.yaml`).
+
+    >>> import yaml
+    >>> print yaml.dump(d)
+    null
+    ...
+    <BLANKLINE>
     """
     def __new__(subtype, shape, dtype=numpy.float, buffer=None, offset=0,
                 strides=None, order=None, info=None):
@@ -183,7 +191,7 @@ class Curve (object):
     <Curve path>
     >>> z.command_stack[-1].arguments['curve'] == z
     True
-    >>> print yaml.dump(c)
+    >>> print yaml.dump(c)  # doctest: +REPORT_UDIFF
     &id001 !!python/object:hooke.curve.Curve
     command_stack: !!python/object/new:hooke.command_stack.CommandStack
       listitems:
@@ -211,7 +219,7 @@ class Curve (object):
 
     YAML still works, though.
 
-    >>> print yaml.dump(c.command_stack)
+    >>> print yaml.dump(c.command_stack)  # doctest: +REPORT_UDIFF
     &id001 !!python/object/new:hooke.command_stack.CommandStack
     listitems:
     - !!python/object:hooke.engine.CommandMessage
@@ -227,16 +235,7 @@ class Curve (object):
     <BLANKLINE>
     """
     def __init__(self, path, info=None):
-        #the data dictionary contains: {name of data: list of data sets [{[x], [y]}]
-        self.name = None
-        self.set_path(path)
-        self.driver = None
-        self.data = None
-        if info == None:
-            info = {}
-        self.info = info
-        self.command_stack = CommandStack()
-        self._hooke = None  # Hooke instance for Curve.load()
+        self.__setstate__({'path':path, 'info':info})
 
     def __str__(self):
         return str(self.__unicode__())
@@ -258,9 +257,15 @@ class Curve (object):
         return state
 
     def __setstate__(self, state):
-        self.name = self._hooke = None
+        # .data contains: {name of data: list of data sets [{[x], [y]}]
+        # ._hooke contains a Hooke instance for Curve.load()
+        self.name = self.driver = self.data = self._hooke = None
+        self.info = {}
+        self.command_stack = CommandStack()
         for key,value in state.items():
             setattr(self, key, value)
+        if self.info == None:
+            self.info = {}
         self.set_path(state.get('path', None))
 
     def set_hooke(self, hooke=None):