Hi Mike,

you'll need to add your new classes to the __all__ list in tables/__init__.py 
to have them appear via "from tables import *". They are available via "import 
tables" since tables/__init__.py imports everything from tables/atom.py with 
the line "from tables.atom import *".

However, there will be other changes that you will need to make. What do you 
think about forking https://github.com/PyTables/PyTables and applying your 
changes so we can take a look? One next place will be AtomToHDF5Type which does 
not handle your "link" kind:

def AtomToHDF5Type(atom, char *byteorder):
  cdef hid_t   tid
  cdef hsize_t *dims

  # Create the base HDF5 type
  if atom.type in PTTypeToHDF5:
    tid = H5Tcopy(PTTypeToHDF5[atom.type])
    # Fix the byteorder
    if atom.kind != 'time':
      set_order(tid, byteorder)
  elif atom.kind in PTSpecialKinds:
    # Special cases (the byteorder doesn't need to be fixed afterwards)
    if atom.type == 'complex64':
      tid = create_ieee_complex64(byteorder)
    elif atom.type == 'complex128':
      tid = create_ieee_complex128(byteorder)
    elif atom.kind == 'string':
      tid = H5Tcopy(H5T_C_S1);
      H5Tset_size(tid, atom.itemsize)
    elif atom.kind == 'bool':
      tid = H5Tcopy(H5T_STD_B8);
    elif atom.kind == 'enum':
      tid = enumToHDF5(atom, byteorder)
  else:
    raise TypeError("Invalid type for atom %s" % (atom,))

Cheers,
~Josh.

On Jun 23, 2011, at 1:41 AM, Tallhamer, Mike wrote:

> Here is some additional information on the issue...
> 
> I see that if I type the following in ipython...
> 
> [1] import tables
> 
> I do get access to tables.LinkAtom and tables.LinkCol
> 
> If I type...
> 
> [2] from tables import *
> 
> Neither LinkAtom or LinkCol are available. Furthermore, if I use
> tables.LinkCol in an IsDescription class and try to assign a string to
> it I get a TypeError like the one below. 
> 
> In [3]: class Test(IsDescription):
>   ...:     name = StringCol(100)
>   ...:     link_col = tables.LinkCol(100)
>   ...:
>   ...:
> 
> In [4]: h5file = openFile('mytables.h5','w')
> 
> In [5]: h5file.createTable('/', 'Test', Test, title='Test Table')
> 
> ------------------------------------------------------------------------
> ---
> TypeError                                 Traceback (most recent call
> last)
> 
> C:\tmp\<ipython console> in <module>()
> 
> C:\Python27\lib\site-packages\tables\file.pyc in createTable(self,
> where, name,
> description, title, filters, expectedrows, chunkshape, byteorder,
> createparents)
>    772                      description=description, title=title,
>    773                      filters=filters, expectedrows=expectedrows,
> --> 774                      chunkshape=chunkshape, byteorder=byteorder)
>    775
>    776
> 
> C:\Python27\lib\site-packages\tables\table.pyc in __init__(self,
> parentNode, name, description, title, filters, expectedrows, chunkshape,
> byteorder, _log)
>    590
>    591         super(Table, self).__init__(parentNode, name, new,
> filters,
> --> 592                                     byteorder, _log)
>    593
>    594
> 
> C:\Python27\lib\site-packages\tables\leaf.pyc in __init__(self,
> parentNode, name, new, filters, byteorder, _log)
>    289         # is a lazy property that automatically handles their
> loading.
> 
>    290
> --> 291         super(Leaf, self).__init__(parentNode, name, _log)
>    292
>    293
> 
> C:\Python27\lib\site-packages\tables\node.pyc in __init__(self,
> parentNode, name, _log)
>    294             #   Create or open the node and get its object ID.
> 
>    295             if new:
> --> 296                 self._v_objectID = self._g_create()
>    297             else:
>    298                 self._v_objectID = self._g_open()
> 
> C:\Python27\lib\site-packages\tables\table.pyc in _g_create(self)
>    745         # set because it is needed for setting attributes
> afterwards.
> 
>    746         self._v_objectID = self._createTable(
> --> 747             self._v_new_title, self.filters.complib or '',
> obversion )
>    748         self._v_recarray = None  # not useful anymore
>    749         self._rabyteorder = None # not useful anymore
> 
> C:\Python27\lib\site-packages\tables\tableExtension.pyd in
> tables.tableExtension.Table._createTable
> (tables\tableExtension.c:1822)()
> 
> C:\Python27\lib\site-packages\tables\utilsExtension.pyd in
> tables.utilsExtension.createNestedType (tables\utilsExtension.c:7912)()
> 
> C:\Python27\lib\site-packages\tables\utilsExtension.pyd in
> tables.utilsExtension.AtomToHDF5Type (tables\utilsExtension.c:5703)()
> 
> TypeError: Invalid type for atom LinkCol(itemsize=100, shape=(),
> dflt='', pos=0)
> 
> 
> 
> Any thoughts or ideas?
> 
> -Mike
> 
> 
> 
> -----Original Message-----
> 
> I would like to create my own atom class but appear to be doing
> something wrong. I basically just need a StringAtom but want to define a
> new class with a new PyTables 'kind' of 'link' instead of 'string.'
> 
> I have added the following code to the atom.py file...
> 
> class LinkAtom(Atom):
>    """
>    Defines an atom of type ``link``.
> 
>    The item size is the *maximum* length in characters of strings.
>    """
>    kind = 'link'
>    itemsize = property(
>        lambda self: self.dtype.base.itemsize,
>        None, None, "Size in bytes of a sigle item in the atom." )
>    type = 'string'
>    _defvalue = ''
> 
>    def __init__(self, itemsize, shape=(), dflt=_defvalue):
>        if not hasattr(itemsize, '__int__') or int(itemsize) < 0:
>            raise ValueError( "invalid item size for kind ``%s``: %r; "
>                              "it must be a positive integer"
>                              % ('string', itemsize) )
>        Atom.__init__(self, 'S%d' % itemsize, shape, dflt)
> 
> 
> However, when I run ipython and import tables a LinkAtom and by
> extension a LinkCol is not created. Can someone tell me what I'm doing
> wrong? This method of generating class in PyTables doesn't seen to be
> very intuitive and/or pythonic.
> 
> -Mike


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a 
definitive record of customers, application performance, security 
threats, fraudulent activity and more. Splunk takes this data and makes 
sense of it. Business sense. IT sense. Common sense.. 
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to