python - Ordering of nested structures in PyTable table -


suppose have following pytable column descriptor:

import numpy np import tables pt  class date_t(pt.isdescription):     year    = pt.int32col(shape=(), dflt=2013, pos=0)     month   = pt.int32col(shape=(), dflt=1,    pos=1)     day     = pt.int32col(shape=(), dflt=1,    pos=2)  class info(pt.isdescription):     col1       = pt.int32col(shape=(), dflt=0, pos=0)     startdate  = date_t()      birthdate  = date_t()      col2       = pt.int32col(shape=(), dflt=0, pos=3)     enddate    = date_t()      col3       = pt.int32col(shape=(), dflt=0, pos=5)     col4       = pt.int32col(shape=(), dflt=0, pos=6)  

how can specify position of 'startdate', 'birthdate', , 'enddate'?
thought like:

startdate = date_t(pos=1) birthdate = date_t(pos=2) 

and redefine date_t class as:

class date_t(pt.isdescription):     def __init__(self, pos):         self._v_pos = pos     year    = pt.int32col(shape=(), dflt=2013, pos=0)     month   = pt.int32col(shape=(), dflt=1,    pos=1)     day     = pt.int32col(shape=(), dflt=1,    pos=2) 

but gives me error:
typeerror: object.new() takes no parameters

any ideas?

in hackish way, can change class attributes of info after defined.

class info(pt.isdescription):     col1       = pt.int32col(shape=(), dflt=0, pos=0)     startdate  = date_t()      birthdate  = date_t()      col2       = pt.int32col(shape=(), dflt=0, pos=3)     enddate    = date_t()      col3       = pt.int32col(shape=(), dflt=0, pos=5)     col4       = pt.int32col(shape=(), dflt=0, pos=6)   info.columns['startdate']._v_pos = 1 info.columns['birthdate']._v_pos = 2 info.columns['enddate']._v_pos   = 3 

there's function in pytables called descr_from_dtype() creates table description (possibly nested) numpy dtype. not import automatically when 1 runs from tables import *, have import explicitly. function may come in handy when having trouble syntax nested tables.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -