Anthony, 

It won't be in any source that you have because I'm trying to create it.

per my email below...

>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)

I was told this is how you create a new Atom class and by extension a new 
Column class via some pytables automagic class generation (not very pythonic in 
mho). What I'm trying to accomplish is to implement a table with a custom 
column type that that "points" to another node (e.g. like an EArray or VLArray) 
via an internal path to the actual object in the file. Right now I have to 
store the path as a string then search the table to retrieve the path which I 
then use to go and get the data array. I would like to add some type checking 
in the tableExtension.Row.__getitem__() method that simply checks for a LinkCol 
type (just like a StringCol holding my text path) and then returns the actual 
hdf5 node represented by the path instead of the path itself. In this way I can 
get all of the nice features of an indexed Table when it comes to searching for 
values within the records but can also retrieve large variable length datasets 
associated with each of the records. 

Thanks,
Mike

Message: 1
Date: Wed, 22 Jun 2011 20:20:02 -0500
From: Anthony Scopatz <scop...@gmail.com>
Subject: Re: [Pytables-users] Create new Atom Class
To: Discussion list for PyTables
        <pytables-users@lists.sourceforge.net>
Message-ID: <banlktin7qgyf4cduou4dtyolzfg7qv2...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hey Mike,

Hmmm I don't see LinkAtom or LinkCol anywhere in my source.
Can you try to determine which file they are coming from.  What
does type(LinkAtom) say?

Be Well
Anthony

On Wed, Jun 22, 2011 at 6:41 PM, Tallhamer, Mike <
mike.tallha...@usoncology.com> 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
</pre>The contents of this electronic mail message and any attachments are 
confidential, possibly privileged and intended for the addressee(s) 
only.<br>Only the addressee(s) may read, disseminate, retain or otherwise use 
this message. If received in error, please immediately inform the sender and 
then delete this message without disclosing its contents to anyone.</pre>

<<winmail.dat>>

------------------------------------------------------------------------------
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