Hi Cody,

Please, always use the PyTables mailing list so that other people would be 
able to help you too.  Thanks!

A Thursday 21 May 2009 19:13:27 escriguéreu:
> Hi Fracesc,
>
> Sorry to bother you, but I have a question that I could not answer using
> the documentation and I hope you can.
>
> I am trying to append data to a table with a nested data structure. My
> table is structured something like this (except with more nested types):
>
> class Specimen(IsDescription):
>     idnumber    = Int64Col()
>     species    = StringCol(64)
>     collector    = StringCol(64)
>     colnum    = StringCol(16)
>     colyear    = UInt16Col()
>     notes    = StringCol(256)
>
>     class Flower(IsDescription):
>         idnumber    = Int64Col()
>         obj_id        = Int16Col()
>         nstamens    = Int8Col()
>         nstyles        = Int8Col()
>         notes        = StringCol(256)
>
> Creating the table and entering the fields in the specimen table is no
> problem. I have done that, so my table now has lots of specimens. Now I
> want to go back and append rows representing the flower data onto each
> specimen. Each specimen has numerous flowers, so I need a way to append the
> rows, instead of just updating or modifying them. I have a lot of flower
> (and other structural) measurements, so I wanted to write a script to do
> this automatically
>
> This is where I'm stuck. If I use a row iterator to find the appropriate
> specimen for each flower, I can't append rows to the table. I can use the
> iterator to get the row id for the correct specimen (or use getWhereList),
> but even with the row id I can't seem to find any methods that allow me to
> append rows *within* the table's nested datastructures; I can only append
> to the end of the table. I can access and modify the nested fields using
> the PyTables naming schema (e.g. specimens/Flower/...) but I haven't
> figured out how this would allow me to add data for more than one flower
> for each specimen, because every modify or update call just overwrites the
> last.
>
> And I missing something? I feel like either a) there is some simple
> solution to this problem that I have overlooked, or b) I am making some
> incorrect assumptions about what is possible in this architeture and
> therefore a solution will require a completely different approach.

Well, I think you are confusing concepts, yes.  A nested table is made of rows 
with nested *fields*, which is a different concept than genuine nested 
*tables*.  So, whenever you want to add info to a nested table, you have to 
add an entire row, filling *all* the necessary fields.  I agree that the 
'nested table' term used in PyTables' manual can be a bit misleading, but 
that's the name we've been using for years, and I don't think this is going to 
change.

If what you need is a table made of genuine nested tables, a node hierarchy 
would fit better for your uses.  For example:

/Specimens (Group)
    Specimen (Table)
    Flowers (Group)
        Flower (Table)

where you have defined a 'Specimens' Group  that contains a 'Specimen' Table 
specifying the different properties of your specimens.  Inside the 'Specimens' 
group, you also have the 'Flowers' Group that follows a similar structure.  
Also, you can add other 'Flowers' Group siblings for other categories.

Hope that helps,

>
> I would be very appreciative if you could help clarify how I might overcome
> this problem!
>
> Thanks,
>
> Cody Hinchliff
> PhD Candidate
> Washington State University
> Pullman, WA 99164-4236

-- 
Francesc Alted

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to