In [1]:
import pandas as pd
import numpy as np

from dataobject import DataObject

In [28]:
class MyObject(DataObject):

    _tables = ['data']
    _params = ['noise']
    
    defaults = {'noise':0.5}
    
    def __init__(self, npts=100, noise=0.5, **kwargs):

        t = np.arange(npts)
        f = np.random.randn(npts)*noise
        
        data = pd.DataFrame({'t':t, 'f':f})
        
        kwargs['noise'] = noise
        kwargs['data'] = data
        
        super(MyObject, self).__init__(**kwargs)
        
class AnotherObject(MyObject):
    
    _tables = ['moredata'] + MyObject._tables
    
    def __init__(self, npts=50, **kwargs):
        
        f = np.random.random(npts)
        kwargs['moredata'] = pd.DataFrame({'f':f})
        super(AnotherObject, self).__init__(**kwargs)

In [40]:
AnotherObject._tables


Out[40]:
['moredata', 'data']

In [36]:
d3 = AnotherObject()

In [18]:
d3.save_hdf('testd.h5')

In [19]:
d4 = AnotherObject.load_hdf('testd.h5')

In [24]:
d3.data.head()


Out[24]:
f t
0 0.309384 0
1 0.585847 1
2 0.882885 2
3 -0.322994 3
4 0.269419 4

In [25]:
d4.data.head()


Out[25]:
f t
0 0.309384 0
1 0.585847 1
2 0.882885 2
3 -0.322994 3
4 0.269419 4

In [3]:
d = MyObject()

In [4]:
d.save_hdf('testd.h5', overwrite=True)

In [5]:
d2 = MyObject.load_hdf('testd.h5')

In [6]:
d2.noise


Out[6]:
0.5

In [7]:
d2.data.head()


Out[7]:
f t
0 -0.314054 0
1 -0.392221 1
2 0.206492 2
3 0.363538 3
4 -0.653195 4

In [8]:
d.data.head()


Out[8]:
f t
0 -0.314054 0
1 -0.392221 1
2 0.206492 2
3 0.363538 3
4 -0.653195 4

In [ ]: