
    d1                       d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z
 ddlZddlZddlmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZmZmZ ddlmZmZmZm Z! ddl"m#Z# ddl$m%Z%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: dZ;e;rddlm<Z< dZ=ej>        e?ej@        ejA        jB        ejC        ejA        jB        ejD        ejA        jB        ejE        ejA        jF        ejG        ejA        jB        ejH        ejA        jB        ejI        ejA        jF        ejJ        ejA        jF        ejK        eLejM        ejA        jN        ejO        ePejQ        ePejR        eSiZTeUeTejV        <    eWed          r
eLeTejX        <    eWed          rejA        jN        eTejY        <    eWed          rejA        jN        eTejZ        <    eWed          r
ePeTej[        <    eWed          r
ePeTej\        <    ej]         ed                    j^        j_        Z`d Zad Zbd Zcd Zdd Zed Zfd  Zgd! Zhd" Zid# Zjd$ Zk G d% d&el          Zm G d' d(ejn        e#          Zn G d) d*          Zo G d+ d,          ZpdS )-z Here is defined the Table class.    N)Path)perf_counter   )tableextension)ObjectCacheNumCache)Atom)compile_condition)	flavor_ofarray_as_internalinternal_to_flavor)is_idxlazyattrSizeType
NailedDict)Leaf)IsDescriptionDescriptionColdescr_from_dtype)	NodeErrorHDF5ExtErrorPerformanceWarningOldIndexWarningNoSuchNodeError)get_nested_field)	join_path
split_path)OldIndexdefault_index_filtersdefault_auto_indexIndexIndexesDescGIndexesTableGF)
show_statsz2.7float16float96float128
complex192
complex256c                     d| j         z  S Nz_i_%s)_v_name)nodes    ,lib/python3.11/site-packages/tables/table.py_index_name_ofr0   V   s    T\!!    c                 p    t          | j                  d         }t          |t          |                     S )Nr   )r   _v_pathnamer   r0   )r.   nodeParentPaths     r/   _index_pathname_ofr5   Z   s/     011!4N^^D%9%9:::r1   c                 <    t          t          |           |          S N)r   r5   )tablecolpathnames     r/   _index_pathname_of_columnr:   _   s    '..<<<r1   c                     d| z  S r,    )nodeNames    r/   _index_name_of_r>   h   s    Xr1   c                 `    t          |           \  }}t          |t          |                    S r7   )r   r   r>   )nodePathr4   r=   s      r/   _index_pathname_of_rA   l   s,    )(33NH^_X%>%>???r1   c                 <    t          t          |           |          S r7   )r   rA   )	tablePathr9   s     r/   _index_pathname_of_column_rD   q   s    (33[AAAr1   c                     | j         j        }| j        d         }|d         || j        j        z  z  }t          ||f| j        d          | _        t          |d         |d         d          | _        d| _	        d S )Nr   TABLE_MAX_SIZEztable chunk cacheITERSEQ_MAX_SLOTSITERSEQ_MAX_SIZEzIter sequence cacheF)
_v_fileparams_v_chunkshape_v_dtypeitemsizer   _chunkcacher   	_seqcache_dirtycache)selfrJ   	chunksizenslotss       r/   restorecacherT   u   s    \ F"1%I$%T]5K)KLF 3T] 35 5D (;!<!'(:!;!68 8DN Dr1   c                 8   t           rt                      }t           rt          d|           d| _        | j        rt          |            g }|                                D ]H\  }	}
t          |
t          j	                  r)|
                    |	|
                                f           I|t          |          |||ff}| j                            |          }|dk    r| j                            |          }t!          |          dk    rt#          g           S t          j        |d          }|||fd| j        dfk    r |||k    ||k     z  ||z
  |z  dk    z           }|                     |          S || _        |j        }|j        }i }d}t1          |          D ]\  }}|\  }}}||         }|j        }|
J d            |j        r
J d            |                    ||          }|                    |          }||z  }|j        dk    rF|dk    r@| j        d         }t?          j         | j        |z            }t          j!        |d	
          }n|"                                }||d|z  <   |j        dk    r1|dk    r+| j        #                    |g d           t#          g           S tI          j%        ||          }|&                                s+| j        #                    |g d           t#          g           S t           rt          d|           |S )NzEntering table_whereIndexedTr   int64dtyper   z the chosen column is not indexedz#the chosen column has a dirty indexboolshaperX   ze%dzExiting table_whereIndexed)'profileclockr%   
_use_indexrP   rT   items
isinstancenpndarrayappenditemtuplerO   getslotgetitemleniterarraynrowsitersequence_seqcache_keyindex_expressionsstring_expression	enumerateindexdirtyget_lookup_rangesearch	reduction
chunkshapemathceilzerosget_chunkmapsetitemneevaluateany)rQ   compiled	conditioncondvarsstartstopsteptrefvalueskeyvalueseqkeynslotseqidxexprsstrexprcmvarstcoordsiidxexprvaropslimscolrq   range_ncoordsnrowsinchunknchunkschunkmaps                                 r/   _table__where_indexedr      sJ    ww 80$777DO T Fnn&& / /
UeRZ(( 	/MM3

-...vd(;<FN""6**Ezzn$$U++s88q==88Ohs'***41dj!"444se|d
 #et3q8: ;C  %%% $ )H(GFG)) % %
7 S$sm	  "D   ;EE EEEE ''T22,,v&&7?aGqLL?1-Li
\ 9::GxgV<<<HH ))++H$uqy!1vr1---Bxx {7F++H<<>> vr1---Bxx 7/666Or1   c                 `    t          | j        t          |           d| j        z   d          }|S )NzIndexes container for table T)new)r$   	_v_parentr0   r3   )r8   itgroups     r/   create_indexes_tabler      s<    ..&)::F F FG Nr1   c                 4    t          | |d|z   |d          }|S )Nz&Indexes container for sub-description T)filtersr   )r#   )igroupdnameinamer   idgroups        r/   create_indexes_descrr      s/    058T# # #G Nr1   c                    | j         }| j        }| j        }	| j        }
| j        }|j        j        }|r4t          t          |          dt          | j	                  d          |	j        dd          dk    rt          d          |	j        dk    rt          d          |	j        dk    rt          d	          	  |t          |                    }n# t          $ r t!          |          }Y nw xY w|}d
}|
j        }|d
k    rc|                    d          }|D ]K}|d
k    r|}n|d|z   z  }	  ||j         d|           }*# t          $ r t'          ||||          }Y Hw xY w|	j        dk    sJ t)          j        t-          j        |	df                    }|j        }|j        |k    r|j        }t3          |||d|z  ||||||j        |          }|                    | j	        d           |j        dk    r%|                    | j	        d|j        dd          }nd}d|_        ||_        |j        |z
  |_        |                     |           |S )Nz for column 'zW' already exists. If you want to re-create it, please, try with reindex() method betterr   u8zDindexing 64-bit unsigned integer columns is not supported yet, sorrycz"complex columns can not be indexedr<   z+multidimensional columns can not be indexed /)r   zIndex for %s column)	atomtitlekindoptlevelr   tmp_direxpectedrows	byteorder
blocksizesTr   F)lastrowupdate)verbose)!namer8   rX   descrrq   rI   	_get_node
ValueErrorstrpathnameNotImplementedErrorr   	TypeErrorr[   r5   r   r   r3   splitr   r	   
from_dtypera   _v_expectedrowsrk   r"   r   _set_column_indexing_add_rows_to_indexrr   _indexedrows_unsaved_indexedrowsoptimize)rQ   r   r   r   r   r   r   r   r8   rX   r   rq   get_noder   r   r   r   inamesr   r   r   indexedrowss                         r/   _column__create_indexr      s   9DJEJEJEJE}&H  F%(ZZZZT]1C1C1C1CE F F 	F
 y}!*+ + 	+ zS<==={bEFFF.(-e4455 . . .&u--. GE H2~~$$ 	O 	OE{{u$O"(g&9#C#CE#C#CDD" O O O.wugNNO ;"?28UDM2233D (L{\!!{ D#d*!/	 	 	E 
t}d333
 {Q..M1ek4 / G G EK$E!&{!:E 
NN7N### s$   =C C21C21EE&%E&c                       e Zd ZdZd ZdS )_ColIndexesz1Provides a nice representation of column indexes.c                 n    d |                                  D             }dd                    |          z  S )z3Gives a detailed Description column representation.c                 $    g | ]\  }}d | d| S )z  "z": r<   ).0kvs      r/   
<listcomp>z(_ColIndexes.__repr__.<locals>.<listcomp>F  s-    :::TQ a  Q  :::r1   z{
  %s}z,
  )r_   join)rQ   reps     r/   __repr__z_ColIndexes.__repr__C  s6     ;:TZZ\\:::W\\#..//r1   N)__name__
__module____qualname____doc__r   r<   r1   r/   r   r   @  s)        ;;0 0 0 0 0r1   r   c                   F    e Zd ZdZdZed             Zed             Zed             Z	ed             Z
ed             Zed             Zed	             Zed
             Zed             Zej        d             Zed             Zed             Zed             Z	 	 	 dV fd	Z fdZd Zd Zd Zd Zd Zd Zd Zd Zd ZeZd Z d Z!dWd!Z"d" Z#d# Z$dXd$Z%	 	 dYd%Z&dZd&Z'	 	 d[d'Z(	 	 d[d(Z)	 	 d\d*Z*d+ Z+d, Z,	 	 d]d-Z-	 	 d^d.Z.dZd/Z/d0 Z0d_d1Z1d[d2Z2dXd3Z3dXd4Z4d5 Z5d6 Z6d7 Z7d8 Z8d9 Z9d: Z:d; Z;d< Z<dYd=Z=	 	 d[d>Z>	 	 d[d?Z?d`d@Z@dA ZAdZdBZBdC ZC fdDZD fdEZEda fdF	ZFdG ZGdH ZHdI ZIdJ ZJdK ZKdL ZLdM ZMdN ZNdO ZOdP ZP	 	 db fdQ	ZQ fdRZRdS ZSd` fdT	ZTdU ZU xZVS )cTablea  This class represents heterogeneous datasets in an HDF5 file.

    Tables are leaves (see the Leaf class in :ref:`LeafClassDescr`) whose data
    consists of a unidimensional sequence of *rows*, where each row contains
    one or more *fields*.  Fields have an associated unique *name* and
    *position*, with the first field having position 0.  All rows have the same
    fields, which are arranged in *columns*.

    Fields can have any type supported by the Col class (see
    :ref:`ColClassDescr`) and its descendants, which support multidimensional
    data.  Moreover, a field can be *nested* (to an arbitrary depth), meaning
    that it includes further fields inside.  A field named x inside a nested
    field a in a table can be accessed as the field a/x (its *path name*) from
    the table.

    The structure of a table is declared by its description, which is made
    available in the Table.description attribute (see :class:`Table`).

    This class provides new methods to read, write and search table data
    efficiently.  It also provides special Python methods to allow accessing
    the table as a normal sequence or array (with extended slicing supported).

    PyTables supports *in-kernel* searches working simultaneously on several
    columns using complex conditions.  These are faster than selections using
    Python expressions.  See the :meth:`Table.where` method for more
    information on in-kernel searches.

    Non-nested columns can be *indexed*.  Searching an indexed column can be
    several times faster than searching a non-nested one.  Search methods
    automatically take advantage of indexing where available.

    When iterating a table, an object from the Row (see :ref:`RowClassDescr`)
    class is used.  This object allows to read and write data one row at a
    time, as well as to perform queries which are not supported by in-kernel
    syntax (at a much lower speed, of course).

    Objects of this class support access to individual columns via *natural
    naming* through the :attr:`Table.cols` accessor.  Nested columns are
    mapped to Cols instances, and non-nested ones to Column instances.
    See the Column class in :ref:`ColumnClassDescr` for examples of this
    feature.

    Parameters
    ----------
    parentnode
        The parent :class:`Group` object.

        .. versionchanged:: 3.0
           Renamed from *parentNode* to *parentnode*.

    name : str
        The name of this node in its parent group.
    description
        An IsDescription subclass or a dictionary where the keys are the field
        names, and the values the type definitions. In addition, a pure NumPy
        dtype is accepted.  If None, the table metadata is read from disk,
        else, it's taken from previous parameters.
    title
        Sets a TITLE attribute on the HDF5 table entity.
    filters : Filters
        An instance of the Filters class that provides information about the
        desired I/O filters to be applied during the life of this object.
    expectedrows
        A user estimate about the number of rows that will be on table. If not
        provided, the default value is ``EXPECTED_ROWS_TABLE`` (see
        ``tables/parameters.py``).  If you plan to save bigger tables, try
        providing a guess; this will optimize the HDF5 B-Tree creation and
        management process time and memory used.
    chunkshape
        The shape of the data chunk to be read or written as a single HDF5 I/O
        operation. The filters are applied to those chunks of data. Its rank
        for tables has to be 1.  If ``None``, a sensible value is calculated
        based on the `expectedrows` parameter (which is recommended).
    byteorder
        The byteorder of the data *on-disk*, specified as 'little' or 'big'. If
        this is not specified, the byteorder is that of the platform, unless
        you passed a recarray as the `description`, in which case the recarray
        byteorder will be chosen.
    track_times
        Whether time data associated with the leaf are recorded (object
        access time, raw data modification time, metadata change time, object
        birth time); default True.  Semantics of these times depend on their
        implementation in the HDF5 library: refer to documentation of the
        H5O_info_t data structure.  As of HDF5 1.8.15, only ctime (metadata
        change time) is implemented.

        .. versionadded:: 3.4.3

    Notes
    -----
    The instance variables below are provided in addition to those in
    Leaf (see :ref:`LeafClassDescr`).  Please note that there are several
    col* dictionaries to ease retrieving information about a column
    directly by its path name, avoiding the need to walk through
    Table.description or Table.cols.


    .. rubric:: Table attributes

    .. attribute:: coldescrs

        Maps the name of a column to its Col description (see
        :ref:`ColClassDescr`).

    .. attribute:: coldflts

        Maps the name of a column to its default value.

    .. attribute:: coldtypes

        Maps the name of a column to its NumPy data type.

    .. attribute:: colindexed

        Is the column which name is used as a key indexed?

    .. attribute:: colinstances

        Maps the name of a column to its Column (see
        :ref:`ColumnClassDescr`) or Cols (see :ref:`ColsClassDescr`)
        instance.

    .. attribute:: colnames

        A list containing the names of *top-level* columns in the table.

    .. attribute:: colpathnames

        A list containing the pathnames of *bottom-level* columns in
        the table.

        These are the leaf columns obtained when walking the table
        description left-to-right, bottom-first. Columns inside a
        nested column have slashes (/) separating name components in
        their pathname.

    .. attribute:: cols

        A Cols instance that provides *natural naming* access to
        non-nested (Column, see :ref:`ColumnClassDescr`) and nested
        (Cols, see :ref:`ColsClassDescr`) columns.

    .. attribute:: coltypes

        Maps the name of a column to its PyTables data type.

    .. attribute:: description

        A Description instance (see :ref:`DescriptionClassDescr`)
        reflecting the structure of the table.

    .. attribute:: extdim

        The index of the enlargeable dimension (always 0 for tables).

    .. attribute:: indexed

        Does this table have any indexed columns?

    .. attribute:: nrows

        The current number of rows in the table.

    TABLEc                 *    t          j        |           S )z7The associated Row instance (see :ref:`RowClassDescr`).)r   RowrQ   s    r/   rowz	Table.row  s     !$'''r1   c                     | j         j        S )z9The NumPy ``dtype`` that most closely matches this table.)descriptionrL   r   s    r/   rX   zTable.dtype  s     ((r1   c                     | j         fS )zThe shape of this table.)rk   r   s    r/   r[   zTable.shape  s     
}r1   c                 $    | j         j        j        S )z+The size in bytes of each row in the table.)r   rL   rM   r   s    r/   rowsizezTable.rowsize  s     (11r1   c                      | j         | j        z  S )zThe size of this table's data in bytes when it is fully loaded into
        memory.  This may be used in combination with size_on_disk to calculate
        the compression ratio of the data.)rk   r   r   s    r/   size_in_memoryzTable.size_in_memory	  s    
 zDL((r1   c                 6    |                      | j                  S )zA buffer for doing I/O.)_get_container
nrowsinbufr   s    r/   _v_iobufzTable._v_iobuf  s     ""4?333r1   c                    | j                                         D ] }t          |t          j                  s|r n!dS |                     d          }| j                                         D ]\  }}t          ||          }||dd<   |S )z,The defaults for writing in recarray format.Nr   )coldfltsr   r`   ra   rb   r   r_   r   )rQ   coldfltwdfltscolnameras        r/   	_v_wdfltszTable._v_wdflts  s     }++-- 	 	G'2:.. '  4$$Q'' $ 3 3 5 5 	 	GW!&'22BBqqqEEr1   c                     g |                      d          }}| j        D ]>}t          ||          }|j        j        s |j        dk    r|                    |           ?t          |          S )z5The pathnames of unaligned, *unidimensional* columns.r   r   )r   colpathnamesr   flagsalignedndimrc   	frozenset)rQ   colunalignedrarrr9   carrs        r/   _colunalignedzTable._colunaligned(  sv      !4!4Q!7!7d, 	1 	1K#D+66D:% 1$)q..##K000&&&r1   c                     | j         ^	 | j                            t          |                     }|j        | _         | j         S # t
          $ r t          | _         | j         cY S w xY w| j         S )a  Automatically keep column indexes up to date?

        Setting this value states whether existing indexes should be
        automatically updated after an append operation or recomputed
        after an index-invalidating operation (i.e. removal and
        modification of rows).  The default is true.

        This value gets into effect whenever a column is altered.  If you
        don't have automatic indexing activated and you want to do an an
        immediate update use `Table.flush_rows_to_index()`; for an immediate
        reindexing of invalidated indexes, use `Table.reindex_dirty()`.

        This value is persistent.

        .. versionchanged:: 3.0
           The *autoIndex* property has been renamed into *autoindex*.
        )
_autoindexrI   r   r5   autor   r!   )rQ   
indexgroups     r/   	autoindexzTable.autoindex=  s~    ( ?"'!\334Ft4L4LMM

 #-/& # ' ' '"4&&&' ?"s   'A A#"A#c                     t          |          }	 | j                            t          |                     }n# t          $ r t          |           }Y nw xY w||_        || _        d S r7   )rY   rI   r   r5   r   r   r   r   )rQ   r   r  s      r/   r  zTable.autoindex^  sp    Dzz	4//0B40H0HIIJJ 	4 	4 	4-d33JJJ	4
s   '9 AAc                 *      fd j         D             S )z2List of pathnames of indexed columns in the table.c                 .    g | ]}j         |         |S r<   )
colindexedr   	_colpnamerQ   s     r/   r   z-Table.indexedcolpathnames.<locals>.<listcomp>l  s5     / / /?9-/	 / / /r1   )r   r   s   `r/   indexedcolpathnameszTable.indexedcolpathnamesi  s1    / / / /!%!2/ / / 	/r1   c                 D     t           fd j        D                       S )z5A dictionary with the indexes of the indexed columns.c              3   t   K   | ]2}j         |         |j                            |          j        fV  3d S r7   )r  cols_f_colrq   r  s     r/   	<genexpr>z#Table.colindexes.<locals>.<genexpr>s  s[       : :("oi8:Ity'7'7	'B'B'HI : : : : : :r1   )r   r   r   s   `r/   
colindexeszTable.colindexesp  s@      : : : :,0,=: : : : : 	:r1   c                 "    | j         j        dk    S )z%Whether some index in table is dirty.r   )_condition_cache
_nailcountr   s    r/   _dirtyindexeszTable._dirtyindexesw  s     $/!33r1   Nr   Tc           	      J   |d ux| _         }	 || _        	 || _        	 d| _        	 d | _        	 d | _        	 ||j        j        d         }|| _        	 t          d          | _
        	 d | _        	 g | _        	 g | _        	 i | _        	 d | _        	 d| _        	 d| _        	 d| _        	 g | _        	 d | _        	 g | _        	 g | _        	 i | _        	 i | _        	 i | _        	 i | _        	 i | _        	 i | _        	 d| _        	 d | _        	 d | _        	 |j        j        d         }tA          |          | _!        	 i | _"        	 d| _#        	 i | _$        	 d | _%        	 d | _&        	 d| _'        	 d | _(        	 |r6tS          |tT                    r!tW          ||j        j                  | _        n|rjtY          |          tY          tZ                    k    rEt]          |tZ                    r0 |            }tW          |j/        |j        j                  | _        n|rtS          |tV                    r|| _        |rK| j        DtS          |t`          j1                  r*te          ||j        j                  }|\  | _        | _        |r| j        	 tg          |          x| _(        }|dk    r t`          j4        5                    |          }ntm          ||          }t          |j7                  x| _
        }|dk    r|| _        te          |j1        |j        j                  }|\  | _        | _        n# tp          $ r Y nw xY w|r| j        tq          d          |r|tS          |tr          t`          j:        f          r|f}	 tw          |          }n-# tp          $ r  tq          d	tY          |          z            w xY wty          |          d
k    rt{          d|          tw          d |D                       | _        t}                      ?                    ||||||	|
           d S )Nr   EXPECTED_ROWS_TABLEFCOND_CACHE_SLOTST)ptparamspythonzthe ``description`` argument is not of a supported type: ``IsDescription`` subclass, ``Description`` instance, dictionary, or structured arrayzI`chunkshape` parameter must be an integer or sequence and you passed a %sr   z&`chunkshape` rank (length) must be 1: c              3   4   K   | ]}t          |          V  d S r7   )r   )r   ss     r/   r  z!Table.__init__.<locals>.<genexpr>%  s(      &G&Gqx{{&G&G&G&G&G&Gr1   )@_v_new_v_new_title_v_new_filtersextdim_v_recarray_rabyteorderrI   rJ   r   r   rk   r   _time64colnames_strcolnames	_colenumsrK   indexedr   r   _listoldindexesr   colnamesr   colinstances	coldescrscoltypes	coldtypesr   r  r^   _where_conditionrm   	CacheDictr  _exprvars_cache_enabled_indexing_in_queries_empty_array_cacherL   r  rP   _descflavorr`   dictr   typer   
issubclasscolumnsra   rX   r   r   recrj   r   sizer   intintegerre   rh   r   super__init__)rQ   
parentnoder   r   r   r   r   rv   r   _logtrack_timesr   	max_slotsr   tupflavornparrayrk   	__class__s                     r/   r:  zTable.__init__|  s   
 (t33c?!&%2K; =%-45JKL+Da[[
6	2!..M!H7-$%!E!3CN	 	 	"B?=@H $K!	 &-.@A	 )) 4 43!F,0)F"$$1		
  MF
  	+:k400 	+*;4>4F4M O  O  OD 	+d;''4+>+>>>$[-@@ ?  KMME*5=4>4F4M O  O  OD 	+Z[99 	+*D  	:4#++rx00 :&{0:0B0IK K K693 $"3  	:4#+:,5k,B,BB 6 X%% fll;77GG/VDDG%-gl%;%;;
U 199'.D$&w}0:0B0IK K K693 $"3"3    "  	34#+23 3 3  	H:)*sBJ&788 +(]
>":..

 > > >*,0,<,<=> > >> :!## j$.J"1 2 2 2!&&G&GJ&G&G&G!G!GDT3D$	& 	& 	& 	& 	&s   L+ +
L87L8<N *N6c                    | j         d c| _        | _         t                                                       t	          | | j                  | _        | j        | j        }}| j        j        D ]}|	                    |          ||<   | j
        rd | j        D             | _        d S t          |           }|| j        v }d}| j                            d          D ]}|j        }|rt#          | |          }	|	| j        v }
|
| j        |<   |
ru| j        	                    |          }|j        }t'          |t(                    rd}
d}| j                            |           n-|j        r| j                                         nd}
d| j        |<   |
rd| _        |r*t7          j        d| j        d| j        t:                     | j        r.|j        | _        | j         | j        z
  | _!        | j"        | _#        d S d S )Nc                     i | ]}|d S )Fr<   )r   cpns     r/   
<dictcomp>z+Table._g_post_init_hook.<locals>.<dictcomp>>  s    GGGcsEGGGr1   Fr   r2  Ttable ``z`` has column indexes with PyTables 1.x format. Unfortunately, this format is not supported in PyTables 2.x series. Note that you can use the ``ptrepack`` utility in order to recreate the indexes. The 1.x indexed columns found are: )$r0  _flavorr9  _g_post_init_hookColsr   r  r'  _v_pathnames_g_colr  r   r  r5   rI   _f_walkr3   r:   rq   r`   r   r%  rc   rr   r  nailr$  warningswarnr   	nelementsr   rk   r   r  r   )rQ   r'  r  r9   indexesgrouppathr   
oldindexescolobjr   	indexnamer$  columnindexobjrB  s                r/   rJ  zTable._g_post_init_hook*  sB    *.)94&d&!!### t/00	 ".	d+8 	A 	AK(,K(@(@L%%; 	GGT5FGGGDOF
 .d33!T\1
&..E.:: 	$ 	$F(G 15dGDD	#t|3+2( 9!Y--g66F%|H!(H55 9"'%)
,33G<<<< $> 9 166888+0( $# 	!MM !!!4#7#79  ! ! ! < 	- ( 2D(,
T5F(FD%"nDOOO		- 	-r1   c                 B   | j         j        }| j        }|d         }|dk    r||z  }||| j        d         z  z  }nd}| j        || j        d         k     r| j        d         }|dk    r7d}|d         |z  }||k    r$t	          j        d| j        |fz  t                     |S )z<Calculate the number of rows that fits on a PyTables buffer.IO_BUFFER_SIZEr   r   NBUFFER_TIMESa  The Table ``%s`` is exceeding the maximum recommended rowsize (%d bytes);
be ready to see PyTables asking for *lots* of memory and possibly slow
I/O.  You may want to reduce the rowsize by trimming the value of
dimensions that are orthogonal (and preferably close) to the *main*
dimension of this leave.  Alternatively, in case you have specified a
very small/large chunksize, you may want to increase/decrease it.)rI   rJ   r   rv   rP  rQ  r3   r   )rQ   rJ   r   
buffersizer   
maxrowsizes         r/   _calc_nrowsinbufzTable._calc_nrowsinbufs  s     $,,-
a<<#w.J *tq'999JJJ ?&DOA...!_Q/
 ??J/*<J## E "&!1: >? 12 2 2 r1   c                 v    |}|| j         v r| j         |         S t          j        d|          x| j         |<   }|S )Nr   rZ   )r/  ra   empty)rQ   rX   r   arrs       r/   _getemptyarrayzTable._getemptyarray  sQ    $)))*3//  XAS999:D#Jr1   c                 8    t          j        || j                  S )zJGet the appropriate buffer for data depending on table
        nestedness.rZ   )ra   r`  rL   )rQ   r[   s     r/   r   zTable._get_container  s    
 xe4=9999r1   c                 P    fd| j                             d          D             S )z/Returns a list containing 'type_' column names.c                 4    g | ]}|j         k    |j        S r<   )r2  r3   )r   rU  type_s     r/   r   z-Table._get_type_col_names.<locals>.<listcomp>  s3     ) ) );%'' "'''r1   r   )r   rN  )rQ   rf  s    `r/   _get_type_col_nameszTable._get_type_col_names  s?    ) ) ) )".66u==) ) ) 	)r1   c                 x    i }| j                             d          D ]}|j        dk    r|j        ||j        <   |S )z@Return mapping from enumerated column names to `Enum` instances.r   enum)r   rN  r   ri  r3   )rQ   enumMaprU  s      r/   _get_enum_mapzTable._get_enum_map  sK     &..u55 	: 	:F{f$$.4k*+r1   c                    | j         j        d         }t          | j        j                  |k    r$t          j        d| j        |fz  t                     | j	        [| 
                    | j	        | j                  | _	        t          | j	                  | j        k    rt          | j	                  | _        | j        +|                     | j        | j        | j                  | _        | j        t"          j        | _        |                                  |                     | j        | j        j        pdt.                    | _        d| _	        d| _        |                                 | _        | j         j        d         rP| j        j        }t;          | j                            d                    D ]\  }}d|z  } |||j                   | j        S )	zCreate a new table on disk.MAX_COLUMNSztable ``%s`` is exceeding the recommended maximum number of columns (%d); be ready to see PyTables asking for *lots* of memory and possibly slow I/ONr   PYTABLES_SYS_ATTRSr   rG  zFIELD_%d_FILL) rI   rJ   rh   r   _v_namesrP  rQ  r3   r   r  _g_fix_byteorder_datar   r   rK   _calc_chunkshaper   r   sys_cache_description_data_create_tabler  r   complib	obversion_v_objectidr^  r   _v_attrs_g__setattrrp   rN  dflt)rQ   
maxColumnsset_attrr   rU  	fieldnames         r/   	_g_createzTable._g_create  s   
 \(7
 )**Z77M( ,0+;Z*HI #$ $ $ '#99$:J:>:K M  MD4#$$t';;;'*4+;'<'<$%!%!6!6$dlDL"B "BD >! ]DN
 	$$&&&  --t|39r9F F  //11 <34 	1}0H&t'7'?'?U'?'K'KLL 1 1	6+a/	FK0000r1   c           
         |                                  \  | _        }}| j        | _        | j        j         }t          ||| j        j                  | _        |dk    r,| 	                    | j        | j
        | j
                  | _        n|f| _        |                                 | _        | j        j        d         rd| j                            d          v rd}| j        j        }| j                            d          D ]W}|j        }d|z  } ||          }	|	|	|_        n/t)          j        d
|d| j        d|j        d           |j        }	|dz  }X| j                            d          D ]B}
|
j        D ]8}|
j        |         }t1          |t2                    r|j        |
j        |j        <   9C|                                  | j        S )zOpens a table from disk and read the metadata on it.

        Creates an user description on the flight to easy the access to
        the actual data.

        )validater  r   rn  FIELD_0_FILLrr  r   rG  zFIELD_%s_FILLNz'could not load default value for the ``z`` column of table ``z``; using ``z
`` insteadr   r   )	_get_inforw  rk   r   rI   	_isPTFiler   rJ   r   rq  r   rK   r^  r   rx  _f_list__getattr__rN  r3   rz  rP  rQ  ro  _v_colobjectsr`   r   _v_dfltsr-   rs  )rQ   r   rR   r  r   get_attrobjcolr   r}  defvalr   r   s               r/   _g_openzTable._g_open  s    48>>3C3C0+y#z |--&{X040CE E E >>!%!6!6$dlDL"B "BD #,D//11 <34 	I!6!6u!=!====4".66E6BB  F$0G /! 3I%Xi00F)&,  *1$2B2B2B*0+++	'7 8 8 8
 "(FAA "-55=5II I IE % I I!&!4T!:%fc22 I=C[EN6>:I 	$$&&&r1   c                    t          | j        j                  | _        d | j                                        D             | _        |                     d          | _        |                     d          | _        | 	                                | _
        | j                            d          D ]@}|j        }|| j        |<   |j        | j        |<   |j        | j        |<   |j        | j        |<   A| j        j        | _        dS )a  Cache some data which is already in the description.

        Some information is extracted from `self.description` to build
        some useful (but redundant) structures:

        * `self.colnames`
        * `self.colpathnames`
        * `self.coldescrs`
        * `self.coltypes`
        * `self.coldtypes`
        * `self.coldflts`
        * `self._v_dtype`
        * `self._time64colnames`
        * `self._strcolnames`
        * `self._colenums`

        c                 <    g | ]}t          |d           |j        S )ro  )hasattrr3   )r   r   s     r/   r   z1Table._cache_description_data.<locals>.<listcomp>D  s:     - - - #3
++-O- - -r1   time64stringr   rG  N)listr   ro  r&  rN  r   rg  r!  r"  rk  r#  r3   r(  r2  r)  rX   r*  rz  r   rL   )rQ   rU  r   s      r/   rs  zTable._cache_description_data0  s   & T-677- -'+'7'?'?'A'A- - -
  $77AA 44X>>++-- &..E.:: 	1 	1F(G&,DN7#%+[DM'"&,lDN7#%+[DM'"" (1r1   c                     	 t          j        t          |                    d          | j                  S # t
          $ r t          d| j        d|d          w xY w)zGet the instance of the column with the given `colpathname`.

        If the column does not exist in the table, a `KeyError` is
        raised.

        r   rH  "`` does not have a column named ````)	functoolsreducegetattrr   r   AttributeErrorKeyErrorr3   )rQ   r9   s     r/   _get_column_instancezTable._get_column_instance[  s}    	>#**3//1AC C C 	> 	> 	>("...= > > >	>s	   25 &Ac                 X    | j         sdS | j                                         d| _         dS )zMForce queries not to use indexing.

        *Use only for testing.*

        NF)r.  r  rO  r   s    r/   _disable_indexing_in_queriesz"Table._disable_indexing_in_queriesl  s9     0 	F 	""$$$,1)))r1   c                 X    | j         rdS | j                                         d| _         dS )zIAllow queries to use indexing.

        *Use only for testing.*

        NT)r.  r  unnailr   s    r/   _enable_indexing_in_queriesz!Table._enable_indexing_in_queriesz  s7     , 	F$$&&&,0)))r1   r   c                    | j         }||vrXt          |          dk    rt          |          dd         D ]}||= t          |dd          }d |j        D             }|||<   n||         }i i }	}|"t          j        |          }
|
j        }|
j        }	| j	        }| j
        | j        }}i }|D ]Q}|||v r	||         }n=||v r	||         }n0|||v r	||         }n!|||	v r	|	|         }nt          d|z            t          |d          rz|j        d	d         d
k    rt          d|z            |j        |us|j        |k    rt%          d|d|d          |j        j        d	d         dk    rt          d|z            nst          |d          rt+          d|z            t-          |t(                    r(t/          j        |                    d                    }nt/          j        |          }|||<   S|S )a  Get the variables required by the `expression`.

        A new dictionary defining the variables used in the `expression`
        is returned.  Required variables are first looked up in the
        `uservars` mapping, then in the set of top-level columns of the
        table.  Unknown variables cause a `NameError` to be raised.

        When `uservars` is `None`, the local and global namespace where
        the API callable which uses this method is called is sought
        instead.  This mechanism will not work as expected if this
        method is not used *directly* from an API callable.  To disable
        this mechanism, just specify a mapping as `uservars`.

        Nested columns and columns from other tables are not allowed
        (`TypeError` and `ValueError` are raised, respectively).  Also,
        non-column variable values are converted to NumPy arrays.

        `depth` specifies the depth of the frame in order to reach local
        or global variables.

           N
   z<string>evalc                 @    g | ]}|d vr|t           j        j        v|S ))NoneFalseTrue)r|   expressions	functions)r   r   s     r/   r   z-Table._required_expr_vars.<locals>.<listcomp>  s@     A A A&???r~'??? ???r1   zname ``%s`` is not definedr   r   r<   z[variable ``%s`` refers to a multidimensional column, not yet supported in conditions, sorryvariable ``z3`` refers to a column which is not part of table ``r  r   zvariable ``%s`` refers to a 64-bit unsigned integer column, not yet supported in conditions, sorry; please use regular Python selections_v_colpathnameszDvariable ``%s`` refers to a nested column, not allowed in conditionsascii)r-  rh   r  compileco_namesrr  	_getframef_locals	f_globalsr'  rI   r3   	NameErrorr  r[   r   _table_file_table_pathr   rX   r   r   r`   ra   asarrayencode)rQ   
expressionuservarsdepthexprvarscacher   cexprexprvarsuser_localsuser_globals
user_framer'  tblfiletblpathreqvarsr   vals                    r/   _required_expr_varszTable._required_expr_vars  s   0 ,]**=!!C''m,,SbS1 ) )A%a((J
F;;EA Au~ A A AH )1M*%%$Z0H %'\ u--J$-K%/L(<)9  )	 )	C#xsm$$"3'!c[&8&8!#&!c\&9&9"3' <s BCCC sJ'' *9QRR=B&&-ACFGH H H O722722$*(+WWW&6 7 7 7 9=$,,-? BEEF F F - /00 	*02567 7 7
 c3'' **SZZ%8%899CC*S//CGCLLr1   c           	      <   g g }}g g }}|                                 D ]\  }}t          |d          r0|                    |           |                    |j                   E	 |                    |           |                    t          j                            |                     # t          $ r! t          d|d|j	        j
        d          w xY wt          |          t          |          }}t          |          t          |          }}|||||f}	|	S )zGet the condition cache key for `condition` with `condvars`.

        Currently, the key is a tuple of `condition`, column variables
        names, normal variables names, column paths and variable paths
        (all are tuples).

        r   r  z`` has data type ``z``, not allowed in conditions)r_   r  rc   r   r|   
necompilergetTyper   r   rX   r   re   )
rQ   r   r   r&  varnamescolpathsvartypesr   r  condkeys
             r/   _get_condition_keyzTable._get_condition_key  s0     (("..** 	= 	=JS#sJ'' =$$$----=OOC(((OOBM$9$9#$>$>????! = = =#)'*ssCINNN%< = = ==
 #8__eHoo("8__eHoo(h(HEs   #AB+++Cc                    | j         }|                     ||          }|                    |          }|r|                    |          S |\  }}}}}	t	          t          t          ||	                              }
g }|D ]`}||         }|j        j        }t          |         |
|<   | j
        r3| j        |j                 r!|j        j        s|                    |           at!          |          }t#          ||
|          }t%          |j                                      t%          |                    st+          d|d          |||<   |                    |          S )aY  Compile the `condition` and extract usable index conditions.

        This method returns an instance of ``CompiledCondition``.  See
        the ``compile_condition()`` function in the ``conditions``
        module for more information about the compilation process.

        This method makes use of the condition cache when possible.

        z0there are no columns taking part in condition ``r  )r  r  getwith_replaced_varsr1  r  ziprX   r2  _nxtype_from_nptyper.  r  r   rq   rr   rc   r   r
   set
parametersintersectionr   )rQ   r   r   	condcacher  r   r&  r  r  r  typemapindexedcolsr   r   coltypes                  r/   _compile_conditionzTable._compile_condition  s    )	)))X>>==)) 	9..x888 ?F;Hh(
 tC(334455 
	, 
	,G7#C inG27;GG 1 ,5,>Aio,""7+++,,$YEE 8&''44S]]CC 	C*6?iiB C C C &	'**8444r1   c                     |                      |d          |                     |          }fd|j        D             }t          |          S )aC  Will a query for the condition use indexing?

        The meaning of the condition and *condvars* arguments is the same as in
        the :meth:`Table.where` method. If condition can use indexing, this
        method returns a frozenset with the path names of the columns whose
        index is usable. Otherwise, it returns an empty list.

        This method is mainly intended for testing. Keep in mind that changing
        the set of indexed columns or their dirtiness may make this method
        return different values for the same arguments at different times.

           r  c                 *    g | ]}|         j         S r<   )r   )r   r   r   s     r/   r   z1Table.will_query_use_indexing.<locals>.<listcomp>S  s     NNNc8C=)NNNr1   )r  r  index_variablesr   )rQ   r   r   r   idxcolss     `  r/   will_query_use_indexingzTable.will_query_use_indexingA  s^     ++Ixq+II**9h??NNNNX5MNNN!!!r1   c                 4    |                      |||||          S )a  Iterate over values fulfilling a condition.

        This method returns a Row iterator (see :ref:`RowClassDescr`) which
        only selects rows in the table that satisfy the given condition (an
        expression-like string).

        The condvars mapping may be used to define the variable names appearing
        in the condition. condvars should consist of identifier-like strings
        pointing to Column (see :ref:`ColumnClassDescr`) instances *of this
        table*, or to other values (which will be converted to arrays). A
        default set of condition variables is provided where each top-level,
        non-nested column with an identifier-like name appears. Variables in
        condvars override the default ones.

        When condvars is not provided or None, the current local and global
        namespace is sought instead of condvars. The previous mechanism is
        mostly intended for interactive usage. To disable it, just specify a
        (maybe empty) mapping as condvars.

        If a range is supplied (by setting some of the start, stop or step
        parameters), only the rows in that range and fulfilling the condition
        are used. The meaning of the start, stop and step parameters is the
        same as for Python slices.

        When possible, indexed columns participating in the condition will be
        used to speed up the search. It is recommended that you place the
        indexed columns as left and out in the condition as possible. Anyway,
        this method has always better performance than regular Python
        selections on the table.

        You can mix this method with regular Python selections in order to
        support even more complex queries. It is strongly recommended that you
        pass the most restrictive condition as the parameter to this method if
        you want to achieve maximum performance.

        .. warning::

            When in the middle of a table row iterator, you should not
            use methods that can change the number of rows in the table
            (like :meth:`Table.append` or :meth:`Table.remove_rows`) or
            unexpected errors will happen.

        Examples
        --------

        ::

            passvalues = [ row['col3'] for row in
                           table.where('(col1 > 0) & (col2 <= 20)', step=5)
                           if your_function(row['col2']) ]
            print("Values that pass the cuts:", passvalues)

        .. note::

            A special care should be taken when the query condition includes
            string literals.

            Let's assume that the table ``table`` has the following
            structure::

                class Record(IsDescription):
                    col1 = StringCol(4)  # 4-character String of bytes
                    col2 = IntCol()
                    col3 = FloatCol()

            The type of "col1" corresponds to strings of bytes.

            Any condition involving "col1" should be written using the
            appropriate type for string literals in order to avoid
            :exc:`TypeError`\ s.

            The code below will fail with a :exc:`TypeError`::

                condition = 'col1 == "AAAA"'
                for record in table.where(condition):  # TypeError in Python3
                    # do something with "record"

            The reason is that in Python 3 "condition" implies a comparison
            between a string of bytes ("col1" contents) and a unicode literal
            ("AAAA").

            The correct way to write the condition is::

                condition = 'col1 == b"AAAA"'

        .. versionchanged:: 3.0
           The start, stop and step parameters now behave like in slice.

        )_where)rQ   r   r   r   r   r   s         r/   wherezTable.whereV  s    x {{9htTBBBr1   c           	         t           rt                      }t           rt          d|           |                     |||          \  }}}||k    rd| _        d| _        t          g           S |                     |d          |                     |          }|j	        r@t          | |||||          }t          |t          j                  sd| _        d| _        |S nd}fd|j        D             }	|j        |	|j        f| _        t#          j        |           }
t           rt          d|           |
                    ||||          S )	z(Low-level counterpart of `self.where()`.zEntering table._whereFN   r  c                      g | ]
}|         S r<   r<   )r   paramr   s     r/   r   z Table._where.<locals>.<listcomp>  s    AAAEAAAr1   zExiting table._where)r   )r\   r]   r%   _process_range_readr^   r+  ri   r  r  rn   r   r`   ra   rb   r  functionkwargsr   r   _iter)rQ   r   r   r   r   r   r   r   r   argsr   s     `        r/   r  zTable._where  sw     	77D 	6.555"66udDIIdD==#DO$(D!88O ++Ixq+II**9h?? % 	,h	8UD$H HHh
33   #((,%  HAAAAX-@AAA!)!2D(/ J && 	5-t444yydXy>>>r1   c                    |                                   d |                     |||||          D             }d| _        t          |          dk    r|d         |d         dz   }	}|	|z
  t          |          k    rWt	          j        t	          j        ||	          t	          j        |          k              }
|
r|                     ||	|          S | 	                    ||          S )ay  Read table data fulfilling the given *condition*.

        This method is similar to :meth:`Table.read`, having their common
        arguments and return values the same meanings. However, only the rows
        fulfilling the *condition* are included in the result.

        The meaning of the other arguments is the same as in the
        :meth:`Table.where` method.

        c                     g | ]	}|j         
S r<   nrowr   ps     r/   r   z$Table.read_where.<locals>.<listcomp>  ,     G G GQ!& G G Gr1   Nr   r   field)
_g_check_openr  r+  rh   ra   alltruearangerj   readread_coordinates)rQ   r   r   r  r   r   r   coordscstartcstopinc_seqs              r/   
read_wherezTable.read_where  s     	G G++i5$EEG G G $v;;??"1IvbzA~EFv~V,,*Ife,,0@0@@B B A99VU%9@@@$$VU333r1   c                 ~   |                                   |j                                         d | j        D             }|j        }d}	||                     |||||          }
n|                     |||          }
|
D ]+}|D ]}||         ||<   |                                 |	dz  }	,|                                 |	S )a  Append rows fulfilling the condition to the dstTable table.

        dstTable must be capable of taking the rows resulting from the query,
        i.e. it must have columns with the expected names and compatible
        types. The meaning of the other arguments is the same as in the
        :meth:`Table.where` method.

        The number of rows appended to dstTable is returned as a result.

        .. versionchanged:: 3.0
           The *whereAppend* method has been renamed into *append_where*.

        c                     g | ]}|S r<   r<   )r   colNames     r/   r   z&Table.append_where.<locals>.<listcomp>  s    ===G===r1   r   Nr   )	r  rI   _check_writabler   r   r  iterrowsrc   flush)rQ   dstTabler   r   r   r   r   colNamesdstRowrk   srcRowssrcRowr  s                r/   append_wherezTable.append_where  s      	 	((***
 >=4+<=== kk)XudDIIGGmmE466G 	 	F# 2 2"(/wMMOOOQJEEr1   Fc                 
   |                                   d |                     |||||          D             }t          j        |t                    }d| _        |rt          j        |          }t          || j                  S )a^  Get the row coordinates fulfilling the given condition.

        The coordinates are returned as a list of the current flavor.  sort
        means that you want to retrieve the coordinates ordered. The default is
        to not sort them.

        The meaning of the other arguments is the same as in the
        :meth:`Table.where` method.

        c                     g | ]	}|j         
S r<   r  r  s     r/   r   z(Table.get_where_list.<locals>.<listcomp>,  r  r1   rW   N)	r  r  ra   rj   r   r+  sortr   r@  )rQ   r   r   r  r   r   r   r  s           r/   get_where_listzTable.get_where_list  s     	G G++i5$EEG G G&111 $ 	%WV__F!&$+666r1   c                     t          |d          st          d          |                     ddd          \  }}}||k    st          |          dk    rt	          g           S t          j        |           }|                    ||||          S )z+Iterate over a sequence of row coordinates.__getitem__z=Wrong 'sequence' parameter type. Only sequences are suported.Nr   r  )r  r   _process_rangerh   ri   r   r   r  )rQ   sequencer   r   r   r   s         r/   rl   zTable.itersequence5  s     x// 	- , - - - #11$dCCdDLLc(mmq0088O &&yyd8y<<<r1   c                    t          |t                    r|}nOt          |t                    r| j                            |          }nt          dt          |          z            |j        r;|j        j	        dk    r+|r"|j        j
        st          d|d| d          |j        S t          d|d| d          )NzV`sortby` can only be a `Column` or string object, but you passed an object of type: %sfullzField `z-` must have associated a CSI index in table `z `, but the existing one is not. z0` must have associated a 'full' index in table `z`.)r`   Columnr   r  r  r   r2  
is_indexedrq   r   is_csir   )rQ   sortbycheckCSIicols       r/   _check_sortby_csizTable._check_sortby_csiL  s    ff%% 	GDD$$ 	G9##F++DD79=fFG G G ? 	3tz&88 &
 1 & j vvttt%& & & :*$*FFDDD23 3 3r1   c                    |                      ||          }|                     |||d          \  }}}||k    rd|k     s||k     rd|k    rt          g           S t          j        |           }|                    ||||          S )a  Iterate table data following the order of the index of sortby
        column.

        The sortby column must have associated a full index.  If you want to
        ensure a fully sorted order, the index must be a CSI one.  You may want
        to use the checkCSI argument in order to explicitly check for the
        existence of a CSI index.

        The meaning of the start, stop and step arguments is the same as in
        :meth:`Table.read`.

        .. versionchanged:: 3.0
           If the *start* parameter is provided and *stop* is None then the
           table is iterated from *start* to the last line.
           In PyTables < 3.0 only one element was returned.

        Fwarn_negstepr   r  )r  r  ri   r   r   r  )rQ   r  r  r   r   r   rq   r   s           r/   
itersortedzTable.itersortedb  s    ( &&vx88"11%t?D 2 F FdDLLQXX54<<AHH88O &&yyd5y999r1   c                     |                                   |                     ||          }||||         }|                     ||          S )a~  Read table data following the order of the index of sortby column.

        The sortby column must have associated a full index.  If you want to
        ensure a fully sorted order, the index must be a CSI one.  You may want
        to use the checkCSI argument in order to explicitly check for the
        existence of a CSI index.

        If field is supplied only the named column will be selected.  If the
        column is not nested, an *array* of the current flavor will be
        returned; if it is, a *structured array* will be used instead.  If no
        field is specified, all the columns will be returned in a structured
        array of the current flavor.

        The meaning of the start, stop and step arguments is the same as in
        :meth:`Table.read`.

        .. versionchanged:: 3.0
           The start, stop and step parameters now behave like in slice.

        )r  r  r  )	rQ   r  r  r  r   r   r   rq   r  s	            r/   read_sortedzTable.read_sorted  sQ    . 	&&vx88uT$'$$VU333r1   c                     |                      |||d          \  }}}||k    rd|k     s||k     rd|k    rt          g           S t          j        |           }|                    |||          S )a  Iterate over the table using a Row instance.

        If a range is not supplied, *all the rows* in the table are iterated
        upon - you can also use the :meth:`Table.__iter__` special method for
        that purpose. If you want to iterate over a given *range of rows* in
        the table, you may use the start, stop and step parameters.

        .. warning::

            When in the middle of a table row iterator, you should not
            use methods that can change the number of rows in the table
            (like :meth:`Table.append` or :meth:`Table.remove_rows`) or
            unexpected errors will happen.

        See Also
        --------
        tableextension.Row : the table row iterator and field accessor

        Examples
        --------

        ::

            result = [ row['var2'] for row in table.iterrows(step=5)
                                                    if row['var1'] <= 20 ]

        .. versionchanged:: 3.0
           If the *start* parameter is provided and *stop* is None then the
           table is iterated from *start* to the last line.
           In PyTables < 3.0 only one element was returned.

        Fr   r   )r  ri   r   r   r  )rQ   r   r   r   r   s        r/   r  zTable.iterrows  s    B #11%t?D 2 F FdDLLQXX54<<AHH88O &&yyd+++r1   c                 *    |                                  S )aY  Iterate over the table using a Row instance.

        This is equivalent to calling :meth:`Table.iterrows` with default
        arguments, i.e. it iterates over *all the rows* in the table.

        See Also
        --------
        tableextension.Row : the table row iterator and field accessor

        Examples
        --------

        ::

            result = [ row['var2'] for row in table if row['var1'] <= 20 ]

        Which is equivalent to::

            result = [ row['var2'] for row in table.iterrows()
                                                    if row['var1'] <= 20 ]

        )r  r   s    r/   __iter__zTable.__iter__  s    0 }}r1   c                 f   d}|rL|| j         vr6|| j        j        v r|}d}n0t          d                    ||                     | j         |         }||k    rd|k     s||k    r5d|k    r/||                     d          }|S t          j        d|          S t          t          |||                    }	|/|rt          j        |	|          }
n|                     |	          }
nv|j
        j        st          d          |r|j        |	z  }n
| j        |	z  }||j        k    rt          d|j         d| d          |j        d	         st          d
          |}
|dk    r|s|                     |||z
  |
           n'|r|dk    r	 | j                            |
||||           |r|
|         S |
S )z4Read a range of rows and return an in-memory object.NzField {} not found in table {}r   rZ   zGoutput array must be in system's byteorder or results will be incorrectzoutput array size invalid, got z bytes, need z bytesC_CONTIGUOUSzoutput array not C contiguousr      )r*  r   ro  r  formatr   ra   r`  rh   rangerX   isnativer   rM   r   nbytesr   _read_records_read_field_namer   	_fill_col)rQ   r   r   r   r  outselect_fielddtype_fieldnrark   resultbytes_requireds               r/   _readzTable._read  sS     	4DN**D,555#(L EE" %)*0&*=*=? ? ? #nU3 TMMa$hhETMMa$hh}))!,,
8!;7777E%t,,--; 4[AAA ,,U33 9% A  "@ A A A 6!,!5!=!%!5++  "H3: "H "H1?"H "H "H I I I9^, B !@AAAF 199U9 udUlF;;;;
  	Atbyyy HvudD%@@@ 	,''Mr1   c                 Z   |                                   |r|                     |           |4| j        dk    r)d                    | j                  }t	          |          |                     |||d          \  }}}|                     |||||          }t          || j                  S )a^  Get data in the table as a (record) array.

        The start, stop and step parameters can be used to select only
        a *range of rows* in the table. Their meanings are the same as
        in the built-in Python slices.

        If field is supplied only the named column will be selected.
        If the column is not nested, an *array* of the current flavor
        will be returned; if it is, a *structured array* will be used
        instead.  If no field is specified, all the columns will be
        returned in a structured array of the current flavor.

        Columns under a nested column can be specified in the field
        parameter by using a slash character (/) as a separator (e.g.
        'position/x').

        The out parameter may be used to specify a NumPy array to
        receive the output data.  Note that the array must have the
        same size as the data selected with the other parameters.
        Note that the array's datatype is not checked and no type
        casting is performed, so if it does not match the datatype on
        disk, the output will not be correct.

        When specifying a single nested column with the field parameter,
        and supplying an output buffer with the out parameter, the
        output buffer must contain all columns in the table.
        The data in all columns will be read into the output buffer.
        However, only the specified nested column will be returned from
        the method call.

        When data is read from disk in NumPy format, the output will be
        in the current system's byteorder, regardless of how it is
        stored on disk. If the out parameter is specified, the output
        array also must be in the current system's byteorder.

        .. versionchanged:: 3.0
           Added the *out* parameter.  Also the start, stop and step
           parameters now behave like in slice.

        Examples
        --------

        Reading the entire table::

            t.read()

        Reading record n. 6::

            t.read(6, 7)

        Reading from record n. 6 to the end of the table::

            t.read(6)

        NnumpyzXOptional 'out' argument may only be supplied if array flavor is 'numpy', currently is {}Fr   )r  _check_columnr@  r+  r   r  r8  r   )rQ   r   r   r   r  r2  msgra  s           r/   r  z
Table.read&  s    r 	 	&u%%%?t{g5589?9L9L C..  //tT=B 0 D DtT jjdE377!#t{333r1   c                 h   |                      |          }t          |          }||dk    rP|t          d| j                  k     r"| j        d|                                         }n|                     |          }|dk    rvt          |t          j	                  r+|j
        j        t          u r|j        j        r|j        j        st          j        |t"                    }|                     ||           |r7|dk    rt'          ||          }n |                     | j        |                   }|S )z?Private part of `read_coordinates()` with no flavor conversion.Nr   i  rW   )_point_selectionrh   minr   r   copyr   r`   ra   rb   rX   r2  _npsizetyper   
contiguousr   rj   r   _read_elementsr   rb  r*  )rQ   r  r  r   r6  s        r/   _read_coordinateszTable._read_coordinateso  s2    &&v..f++=GaKKT4?3333xx05577,,W55 Q;;vrz22 :L%44L+ 5L( 5 &999///  	D{{)&%88 ,,T^E-BCCr1   c                     |                                   |                     ||          }t          || j                  S )ag  Get a set of rows given their indexes as a (record) array.

        This method works much like the :meth:`Table.read` method, but it uses
        a sequence (coords) of row indexes to select the wanted columns,
        instead of a column range.

        The selected rows are returned in an array or structured array of the
        current flavor.

        )r  rD  r   r@  )rQ   r  r  r6  s       r/   r  zTable.read_coordinates  s=     	''66!&$+666r1   c                     |                      |           	 | j        |         S # t          $ r t          d|d| j        d          w xY w)ah  Get the enumerated type associated with the named column.

        If the column named colname (a string) exists and is of an enumerated
        type, the corresponding Enum instance (see :ref:`EnumClassDescr`) is
        returned. If it is not of an enumerated type, a TypeError is raised. If
        the column does not exist, a KeyError is raised.

        z	column ``z`` of table ``z`` is not of an enumerated type)r;  r#  r  r   r3   rQ   r   s     r/   get_enumzTable.get_enum  sp     	7###	/>'** 	/ 	/ 	/)77D,,,./ / /	/s	   $ &A
c                 .    |                      |          S )a  Get a column from the table.

        If a column called name exists in the table, it is read and returned as
        a NumPy object. If it does not exist, a KeyError is raised.

        Examples
        --------

        ::

            narray = table.col('var2')

        That statement is equivalent to::

            narray = table.read(field='var2')

        Here you can see how this method can be used as a shorthand for the
        :meth:`Table.read` method.

        r  )r  )rQ   r   s     r/   r   z	Table.col  s    , yyty$$$r1   c                    |                                   t          |          ryt          j        |          }|| j        k    rt          d          |dk     r
|| j        z  }|                     ||dz   d          \  }}}|                     |||          d         S t          |t                    rA|                     |j
        |j        |j                  \  }}}|                     |||          S t          |          t          t          fv st          |t           j                  r|                     |d          S t          d|          )a{  Get a row or a range of rows from the table.

        If key argument is an integer, the corresponding table row is returned
        as a record of the current flavor. If key is a slice, the range of rows
        determined by it is returned as a structured array of the current
        flavor.

        In addition, NumPy-style point selections are supported.  In
        particular, if key is a list of row coordinates, the set of rows
        determined by it is returned.  Furthermore, if key is an array of
        boolean values, only the coordinates where key is True are returned.
        Note that for the latter to work it is necessary that key list would
        contain exactly as many rows as the table has.

        Examples
        --------

        ::

            record = table[4]
            recarray = table[4:1000:2]
            recarray = table[[4,1000]]   # only retrieves rows 4 and 1000
            recarray = table[[True, False, ..., True]]

        Those statements are equivalent to::

            record = table.read(start=4)[0]
            recarray = table.read(start=4, stop=1000, step=2)
            recarray = table.read_coordinates([4,1000])
            recarray = table.read_coordinates([True, False, ..., True])

        Here, you can see how indexing can be used as a shorthand for the
        :meth:`Table.read` and :meth:`Table.read_coordinates` methods.

        Index out of ranger   r   NInvalid index or slice: )r  r   operatorrq   rk   
IndexErrorr  r  r`   slicer   r   r   r2  r  re   ra   rb   rD  )rQ   r   r   r   r   s        r/   r  zTable.__getitem__  sJ   J 	#;; 	A.%%C dj   !5666Qwwtz!"&"5"5c37A"F"FUD$99UD$//22U## 	A"&"5"5	38SX#/ #/UD$99UD$///#YY4-'':c2:+F+F'))#t444???@@@r1   c                    |                                   | j                                         t          |          rZt	          j        |          }|| j        k    rt          d          |dk     r
|| j        z  }|                     ||dz   d|g          S t          |t                    rB|                     |j        |j        |j                  \  }}}|                     ||||          S t          |          t           t"          fv st          |t$          j                  r|                     ||          S t          d|          )a  Set a row or a range of rows in the table.

        It takes different actions depending on the type of the *key*
        parameter: if it is an integer, the corresponding table row is
        set to *value* (a record or sequence capable of being converted
        to the table structure).  If *key* is a slice, the row slice
        determined by it is set to *value* (a record array or sequence
        capable of being converted to the table structure).

        In addition, NumPy-style point selections are supported.  In
        particular, if key is a list of row coordinates, the set of rows
        determined by it is set to value.  Furthermore, if key is an array of
        boolean values, only the coordinates where key is True are set to
        values from value.  Note that for the latter to work it is necessary
        that key list would contain exactly as many rows as the table has.

        Examples
        --------

        ::

            # Modify just one existing row
            table[2] = [456,'db2',1.2]

            # Modify two existing rows
            rows = numpy.rec.array([[457,'db1',1.2],[6,'de2',1.3]],
                                   formats='i4,a3,f8')
            table[1:30:2] = rows             # modify a table slice
            table[[1,3]] = rows              # only modifies rows 1 and 3
            table[[True,False,True]] = rows  # only modifies rows 0 and 2

        Which is equivalent to::

            table.modify_rows(start=2, rows=[456,'db2',1.2])
            rows = numpy.rec.array([[457,'db1',1.2],[6,'de2',1.3]],
                                   formats='i4,a3,f8')
            table.modify_rows(start=1, stop=3, step=2, rows=rows)
            table.modify_coordinates([1,3,2], rows)
            table.modify_coordinates([True, False, True], rows)

        Here, you can see how indexing can be used as a shorthand for the
        :meth:`Table.modify_rows` and :meth:`Table.modify_coordinates`
        methods.

        rK  r   r   rL  )r  rI   r  r   rM  rq   rk   rN  modify_rowsr`   rO  r  r   r   r   r2  r  re   ra   rb   modify_coordinates)rQ   r   r   r   r   r   s         r/   __setitem__zTable.__setitem__  sE   ^ 	$$&&&#;; 	A.%%C dj   !5666Qwwtz!##Cq!eW===U## 	A"&"5"5	38SX#/ #/UD$##E4u===#YY4-'':c2:+F+F'**3666???@@@r1   c                 4   |                      |           |                     |           |                                  | j        rR| xj        |z  c_        d| _        | j        r|                     d           dS |                     | j	                   dS dS )z,Update the indexes after a flushing of rows.TF_lastrowN)
_open_append_append_records_close_appendr$  r   rP   r  flush_rows_to_index_mark_columns_as_dirtyr   )rQ   wbufRAlenrowss      r/   _save_buffered_rowszTable._save_buffered_rowsN  s     	&!!!W%%%< 		?%%0%%#D~ ?((%(88888 ++D,=>>>>>		? 		?r1   c                 H   |                                   | j                                         | j        st	          dd          t          |d          r| j        j        s|j        | j        k    r|}n	 t          |          }|dk    rt          ||          }t          j                            || j                  }n5# t          $ r(}t!          dt#          |           d|d	          d
}~ww xY w|j        d         }|dk    r|                     ||           d
S d
S )a(  Append a sequence of rows to the end of the table.

        The rows argument may be any object which can be converted to
        a structured array compliant with the table structure
        (otherwise, a ValueError is raised).  This includes NumPy
        structured arrays, lists of tuples or array records, and a
        string or Python buffer.

        Examples
        --------

        ::

            import tables as tb

            class Particle(tb.IsDescription):
                name        = tb.StringCol(16, pos=1) # 16-character String
                lati        = tb.IntCol(pos=2)        # integer
                longi       = tb.IntCol(pos=3)        # integer
                pressure    = tb.Float32Col(pos=4)  # float  (single-precision)
                temperature = tb.FloatCol(pos=5)    # double (double-precision)

            fileh = tb.open_file('test4.h5', mode='w')
            table = fileh.create_table(fileh.root, 'table', Particle,
                                       "A table")

            # Append several rows in only one call
            table.append([("Particle:     10", 10, 0, 10 * 10, 10**2),
                          ("Particle:     11", 11, -1, 11 * 11, 11**2),
                          ("Particle:     12", 12, -2, 12 * 12, 12**2)])
            fileh.close()

        z.You cannot append rows to a non-chunked table.F)h5btrX   r  rW   zProws parameter cannot be converted into a recarray object compliant with table ''. The error was: <>Nr   )r  rI   r  _chunkedr   r  r   _v_is_nestedrX   r   r   ra   r5  rj   rL   	Exceptionr   r   r[   r^  )rQ   rowsr\  iflavorexcr]  s         r/   rc   zTable.append_  sf   F 	$$&&&} 	N@uN N N N D'"" 	K$1	K
dj(( FF
K#D//h&&,T7;;D d$-@@ K K K j:=d))))SSS"J K K KK ,q/Q;;$$VW55555 ;s   6AC 
C4#C//C4c                 t   	 t          |          }|dk    rt          ||          }t          |d          r(|j        dk    rt	          j        |g| j                  }n&t          j                            || j                  }n2# t          $ r%}t          d| j
        j        d|d          d}~ww xY w|S )	z*Try to convert the object into a recarray.r  r[   r<   rW   zOObject cannot be converted into a recarray object compliant with table format 'ra  rb  N)r   r   r  r[   ra   rj   rL   r5  re  r   r   _v_nested_descr)rQ   objrg  recarrrh  s        r/   _conv_to_recarrzTable._conv_to_recarr  s    	FnnG(""'W55sG$$ 	@b
 3%t}=== c?? 	F 	F 	F* #.>>>E F F F	F s   BB 
B5 B00B5c                    |t          d          S |                     |          }t          |          }t          |          |k     rt          d          |                     |          }t          |          dk    r|                     |||           |                     | j                   t          |          S )a8  Modify a series of rows in positions specified in coords.

        The values in the selected rows will be modified with the data given in
        rows.  This method returns the number of rows modified.

        The possible values for the rows argument are the same as in
        :meth:`Table.append`.

        Nr   @The value has not enough elements to fill-in the specified range)r   r>  rh   r   rm  _update_elements_reindexr   )rQ   r  rf  lcoordsrl  s        r/   rR  zTable.modify_coordinates  s     <A;; &&v..f++t99w 3 4 4 4 %%d++v;;??!!'66::: 	d'(((   r1   c                    |d}|t          d          S |d}|dk     rt          d          |dk     rt          d          ||t          |          dz
  |z  z   dz   }|                     |||          \  }}}|| j        k    rt          d          t          t          |||                    }t          |          |k    rt          d          |                     |          }t          |          }||z   | j        k    rt          d          |                     ||||           | 	                    | j
                   t          |          S )a  Modify a series of rows in the slice [start:stop:step].

        The values in the selected rows will be modified with the data given in
        rows.  This method returns the number of rows modified.  Should the
        modification exceed the length of the table, an IndexError is raised
        before changing data.

        The possible values for the rows argument are the same as in
        :meth:`Table.append`.

        Nr   r   #'start' must have a positive value.1'step' must have a value greater or equal than 1.AThis modification will exceed the length of the table. Giving up.z9The value has different elements than the specified range)r   r   rh   r  rk   rN  r,  rm  _update_recordsrq  r   )rQ   r   r   r   rf  rk   rl  r]  s           r/   rQ  zTable.modify_rows  s    <D<A;;=E199BCCC!88CE E E<CIIMT11A5D"11%tDDd$* 5 6 6 6 E%t,,--t99 / 0 0 0 %%d++f++7?TZ'' 1 2 2 2 	UD$777 	d'(((   r1   c                    |d}t          |t                    st          d          | j                                         |t          d          S |d}|dk     rt          d          |dk     rt          d          |                     |          }|j        j	        |j
                 g}	 t          |d          rE|j        j        dk    r5t          j                            ||	                              d          }nt%          |          }t'          ||          }n5# t(          $ r(}	t          d
t          |          d|	d          d}	~	ww xY w|                                }|j        dk    rd|_        ||t/          |          dz
  |z  z   dz   }|                     |||          \  }}}|| j        k    rt5          d          t/          t7          |||                    }
t/          |          |
k     rt          d          |                     |||          }t;          ||          }||dd<   |                     ||||           |                     |g           t          |
          S )a  Modify one single column in the row slice [start:stop:step].

        The colname argument specifies the name of the column in the
        table to be modified with the data given in column.  This
        method returns the number of rows modified.  Should the
        modification exceed the length of the table, an IndexError is
        raised before changing data.

        The *column* argument may be any object which can be converted
        to a (record) array compliant with the structure of the column
        to be modified (otherwise, a ValueError is raised).  This
        includes NumPy (record) arrays, lists of scalars, tuples or
        array records, and a string or Python buffer.

        Nr   z)The 'colname' parameter must be a string.r   rt  ru  rX   VrW   z\column parameter cannot be converted into a ndarray object compliant with specified column 'ra  rb  r<   r   rv  ro  ) r`   r   r   rI   r  r   r   r  r   rj  _v_posr  rX   r   ra   r5  rj   r  r   r   re  squeezer[   rh   r  rk   rN  r,  r8  r   rw  rq  )rQ   r   r   r   rW  r   r  r   rg  rh  rk   
mod_recarrmod_cols                r/   modify_columnzTable.modify_column	  s   " <D'3'' 	IGHHH$$&&&>A;;=E199BCCC!88CE E E **733!1&-@A	Ovw'' <FL,=,D,DfE::@@CC $F++*67;; 	O 	O 	O*<?KKKKN O O O	O !!<2FL<CKK!Ot33a7D"11%tDDd$* 5 6 6 6 E%t,,--v;; 3 4 4 4 ZZtT22
":w77
UD$
;;;wi   s   /A4D$ $
E.#EEc                    |d}t          |          t          t          fvrt          d          |t	          d          S |d}|dk     rt          d          |dk     rt          d          g }|D ]A}|                     |          }|                    |j        j	        |j
                            B	 t          |          }	|	dk    r2t          ||	          }t          j                            ||          }
n!t          j                            ||          }
n5# t"          $ r(}t          d	t%          |           d
|d          d}~ww xY w||t'          |
          dz
  |z  z   dz   }|                     |||          \  }}}|| j        k    rt-          d          t'          t/          |||                    }t'          |
          |k     rt          d          |                     |||          }t3          |
j        j                  D ]:\  }}t9          |||                   }|
|                                         |dd<   ;|                     ||||           |                     |           t	          |          S )a  Modify a series of columns in the row slice [start:stop:step].

        The names argument specifies the names of the columns in the
        table to be modified with the data given in columns.  This
        method returns the number of rows modified.  Should the
        modification exceed the length of the table, an IndexError
        is raised before changing data.

        The columns argument may be any object which can be converted
        to a structured array compliant with the structure of the
        columns to be modified (otherwise, a ValueError is raised).
        This includes NumPy structured arrays, lists of tuples or array
        records, and a string or Python buffer.

        Nr   z0The 'names' parameter must be a list of strings.r   rt  ru  r  rW   zScolumns parameter cannot be converted into a recarray object compliant with table 'ra  rb  rv  ro  ) r2  r  re   r   r   r   r  rc   r   rj  r{  r   r   ra   r5  rj   
fromarraysre  r   rh   r  rk   rN  r,  r8  rp   rX   namesr   r|  rw  rq  )rQ   r   r   r   r4  r  r   r   r  rg  recarrayrh  rk   r}  r   r   r~  s                    r/   modify_columnszTable.modify_columnse	  s   " <D;;tUm++NOOO?A;;=E199BCCC!88 - . . . 	J 	JG..w77FLL)9&-HIIII	G  ((G(""+GW==6<<u<==6,,WE,BB 	G 	G 	G*69$iiiiF G G G	G
 <CMMA-559D"11%tDDd$* 5 6 6 6 E%t,,--x==5   3 4 4 4 ZZtT22
 !566 	2 	2GAt&z58<<G!$//11GAAAJJUD$
;;;es   7A(D   
E*#EEc                 B   d}| j         r| j        }| j        }| j                                        D ]M\  }}|rF| j                            |          }|dk    r&|j        j        s| 	                    ||||d          }N| xj        |z  c_        | xj        |z  c_        |S )a
  Add remaining rows in buffers to non-dirty indexes.

        This can be useful when you have chosen non-automatic indexing
        for the table (see the :attr:`Table.autoindex` property in
        :class:`Table`) and you want to update the indexes on it.

        r   Tr   )
r$  r   r   r  r_   r  rM  rq   rr   r   )rQ   rV  	rowsaddedr   rk   r   r  r   s           r/   rZ  zTable.flush_rows_to_index	  s     	< 	+%E-E)-)>)>)@)@ J J%* J)**733Cqyyy$($;$;#UE8D %< %J %J	%%2%%*r1   c                    | j                             |          j        }|j        }|j        j        |z  }||z
  }	||z   |z
  dz   }
||
k     rA|                    |                     |||z   d|          g|           |	|z  }	||z  }||
k     A|rK|| j        k     r@|                    |                     || j        d|          g|           |	| j        |z
  z  }	|	S )z(Add more elements to the existing index.r   r  )	r  rM  rq   	slicesizesortedrk   rc   r8  append_last_row)rQ   r   r   rk   r   r   rq   r  startLRr   r   s              r/   r   zTable._add_rows_to_index	  s    	  ))/O	
 ,$y0ou}y(1,nnLLGWy%8!WEEF     9$Ky G nn  	0w++!!GTZG<<= "    4://Kr1   c                     |                      |||          \  }}}|                     |||          }|                     | j                   t	          |          S )a^  Remove a range of rows in the table.

        If only start is supplied, that row and all following will be deleted.
        If a range is supplied, i.e. both the start and stop parameters are
        passed, all the rows in the range are removed.

        .. versionchanged:: 3.0
           The start, stop and step parameters now behave like in slice.

        .. seealso:: remove_row()

        Parameters
        ----------
        start : int
            Sets the starting row to be removed. It accepts negative values
            meaning that the count starts from the end.  A value of 0 means the
            first row.
        stop : int
            Sets the last row to be removed to stop-1, i.e. the end point is
            omitted (in the Python range() tradition). Negative values are also
            accepted. If None all rows after start will be removed.
        step : int
            The step size between rows to remove.

            .. versionadded:: 3.0

        Examples
        --------

        Removing rows from 5 to 10 (excluded)::

            t.remove_rows(5, 10)

        Removing all rows starting from the 10th::

            t.remove_rows(10)

        Removing the 6th row::

            t.remove_rows(6, 7)

        .. note::

            removing a single row can be done using the specific
            :meth:`remove_row` method.

        )r  _remove_rowsrq  r   r   )rQ   r   r   r   rk   s        r/   remove_rowszTable.remove_rows	  s[    b #11%tDDd!!%t44d'(((r1   c                 :    |                      ||dz              dS )a  Removes a row from the table.

        Parameters
        ----------
        n : int
            The index of the row to remove.


        .. versionadded:: 3.0

        Examples
        --------

        Remove row 15::

            table.remove_row(15)

        Which is equivalent to::

            table.remove_rows(15, 16)

        .. warning::

            This is not equivalent to::

                table.remove_rows(15)

        r   )r   r   N)r  )rQ   ns     r/   
remove_rowzTable.remove_row
  s'    < 	qq1u-----r1   c                     t                                                       | j                            |            d| j        v rt          j        |           | j        d<   d S d S )Nr   )r9  _g_update_dependentr  _g_update_table_location__dict__r   r   )rQ   rB  s    r/   r  zTable._g_update_dependent>
  se    ##%%% 		**4000 DM!!#1#5d#;#;DM%    "!r1   c                    t          |           }t                                          ||           	 | j                            |          }| j        }t          |           }|                    ||           dS # t          $ r Y dS w xY w)z]Move this node in the hierarchy.

        This overloads the Node._g_move() method.

        N)r5   r9  _g_moverI   r   r   r0   r   )rQ   	newparentnewnameitgpathnamer   	newigroupnewinamerB  s          r/   r  zTable._g_moveH
  s     ).. 		7+++	1l,,[99G I%d++HOOIx00000  	 	 	DD	s   A< <
B
	B
c                     t          |           }	 | j                            |          }|                    d           d| _        n# t
          $ r Y nw xY wt                                          ||           d S )NT)	recursiveF)r5   rI   r   	_f_remover$  r   r9  	_g_remove)rQ   r  forcer  r   rB  s        r/   r  zTable._g_remove^
  s    (..	!l,,[99G --- DLL	  	 	 	D	 	)U+++++s   A
 

AAc                     | j         }t          |          ||         }}||k    rdS | j                                         |||<   t	          |                                          | _        dS )z3Mark the referred column as indexed or non-indexed.N)r  rY   r  clearmaxr   r$  )rQ   r9   r$  r  	isindexed
wasindexeds         r/   r   zTable._set_column_indexingl
  so     _
 $Wz+/F:	
""F 	##%%%"+
;:,,..//r1   c                     t          |          dk    sJ | j        r<| j        | j        }}|D ]-}||         r!|                    |          }d|j        _        ,dS dS )z+Mark column indexes in `colnames` as dirty.r   TN)rh   r$  r  r  rM  rq   rr   )rQ   r&  r  r  r   r   s         r/   r[  zTable._mark_columns_as_dirtyy
  s}     8}}q    < 	+#	J# + +g& +++g..C&*CIO	+ 	++ +r1   c                 
   | j         r{| j        | j        }}g }|D ]@}||         r6|                    |          }d|j        _        |                    |           A| j        r|r|                     d           d| _	        dS dS )z=Re-index columns in `colnames` if automatic indexing is true.Trr   N)
r$  r  r  rM  rq   rr   rc   r  _do_reindexrP   )rQ   r&  r  r  colstoindexr   r   s          r/   rq  zTable._reindex
  s     < 	$#	JK# 0 0g& 0++g..C&*CIO&&w///~ -+ -  t ,,,#D	$ 	$r1   c                     d}| j                                         D ]6\  }}|r/| j                            |          }|                    |          }7|dk    r|| _        | j        |z
  | _        t          |          S )z2Common code for `reindex()` and `reindex_dirty()`.r   )	r  r_   r  rM  r  r   rk   r   r   )rQ   rr   r   r   r  indexcols         r/   r  zTable._do_reindex
  s     %)_%:%:%<%< 	: 	:!Wj :9++G44&22599?? +D(,
[(@D%$$$r1   c                 2    |                      d           dS )zRecompute all the existing indexes in the table.

        This can be useful when you suspect that, for any reason, the
        index information for columns is no longer valid and want to
        rebuild the indexes on it.

        Fr  Nr  r   s    r/   reindexzTable.reindex
  s!     	u%%%%%r1   c                 2    |                      d           dS )aC  Recompute the existing indexes in table, *if* they are dirty.

        This can be useful when you have set :attr:`Table.autoindex`
        (see :class:`Table`) to false for the table and you want to
        update the indexes after a invalidating index operation
        (:meth:`Table.remove_rows`, for example).

        Tr  Nr  r   s    r/   reindex_dirtyzTable.reindex_dirty
  s!     	t$$$$$r1   c                    ||                      ||||           dS | j        }|}|dk     r| }|dz   |dz   }}||                     ||          }	t          ||||z            D ]U}
|
||z  z   }||k    r|}|| |
||         }n |	|
||         }|                     |          }|                    |           V|                                 dS )zCopy rows from self to objectNr   r   )_g_copy_rows_optimr   r  r,  r  rc   r  )rQ   objectr   r   r   r  r  lenbufabssteprq   start2stop2rf  r  s                 r/   _g_copy_rowszTable._g_copy_rows
  s   >##FE4>>>F!88eG(EAI4E**68<<EE46)9:: 	  	 FWv--Et||~F5-.veD01,,V44MM$r1   c                 b   | j         }|                    | j                   |j        }t	          ||||z            D ]]}|||z  z   }||k    r|}||z
  dz
  |z  dz   }	| j                            | j        |||d           |                    |	           ||	z  }^|                                 dS )z1Copy rows from self to object (optimized version)r   N)	r   rW  r   rk   r,  r   r1  rX  rY  )
rQ   r  r   r   r   r   	nrowsdestr  r  rk   s
             r/   r  zTable._g_copy_rows_optim
  s     _
DM***L	E4
):;; 	 	FTJ..Et||fnq(T1Q6EHt}feT4HHH ""5)))IIr1   c                     | j         |j         }}|D ]i}t          ||         t                    rL||         j        }|r=||         j        }||         }|                    |j        |j        |j        d           jdS )z>Generate index in `other` table for every indexed column here.N)r   r   r   r   )	r'  r`   r  r  rq   create_indexr   r   r   )rQ   otheroldcolsnewcolsr   oldcolindexedoldcolindexnewcols           r/   _g_prop_indexeszTable._g_prop_indexes
  s      ,e.@ 	C 	CG77+V44 C ' 0 ;  C")'"2"8K$W-F''(-8L + 3T ( C C C	C 	Cr1   c
           
         |
                     dd          }|
                     dd          }|
                     dd          }|                     ||||du           \  }}}t          t          |||                    }t	          ||| j        |||||	          }|                     ||||||           |j        |j        z  }|r| j	        r| 
                    |           ||fS )z2Private part of Leaf.copy() for each kind of leaf.r  NpropindexesFr  r   )r   r   r   rv   r<  )popr  rh   r,  r   r   r  rk   r   r$  r  )rQ   groupr   r   r   r   r   r   rv   r<  r  r  r  r  rk   newtabler.  s                    r/   _g_copy_with_statszTable._g_copy_with_stats
  s   
 Hd++jj66::j%00"664FdN 7 < <d E%t,,--d&6e!(u$."$ $ $ 	(E4vxHHH("22 	+4< 	+  ***&!!r1   c                 >     t                      j        ||||fi |S )a  Copy this table and return the new one.

        This method has the behavior and keywords described in
        :meth:`Leaf.copy`.  Moreover, it recognises the following additional
        keyword arguments.

        Parameters
        ----------
        sortby
            If specified, and sortby corresponds to a column with an index,
            then the copy will be sorted by this index.  If you want to ensure
            a fully sorted order, the index must be a CSI one.  A reverse
            sorted copy can be achieved by specifying a negative value for the
            step keyword.  If sortby is omitted or None, the original table
            order is used.
        checkCSI
            If true and a CSI index does not exist for the sortby column, an
            error will be raised.  If false (the default), it does nothing.
            You can use this flag in order to explicitly check for the
            existence of a CSI index.
        propindexes
            If true, the existing indexes in the source table are propagated
            (created) to the new one.  If false (the default), the indexes are
            not propagated.

        )r9  r@  )rQ   r  r  	overwritecreateparentsr  rB  s         r/   r@  z
Table.copy  s:    : uww|w	=D D<BD D 	Dr1   c                    | j                                         rd| j        v r| j                                         | j        rg| j        r`|                     d          }|dk    s)| j        | j	        k    sJ d| j        | j	        fz              | j
        r|                                  t                                                       dS )zFlush the table buffers.r   TrU  r   z{internal error: the number of indexed rows (%d) and rows in the table (%d) is not equal; please report this to the authors.N)rI   _iswritabler  r   _flush_buffered_rowsr$  r  rZ  r   rk   r  r  r9  r  )rQ   r  rB  s     r/   r  zTable.flush4  s     <##%% 	)%%--///| 
) 
) 44d4CC	 A~~):dj)H)H)H: )4:67 *I)H)H
 % )&&(((r1   c                    d| j         v r| j                                        dk    s | j        r;| j        r4| j        dk    s| j        r"t          j        d| j	        z  t                     | j         }d|v r|d= d|v r|d= dS dS )z*Code to be called before killing the node.r   r   aA  table ``%s`` is being preempted from alive nodes without its buffers being flushed or with some index being dirty.  This may lead to very ineficient use of resources and even to fatal errors in certain situations.  Please do a call to the .flush() or .reindex_dirty() methods on this table before start using other nodes.r   r   N)r  r   _get_unsaved_nrowsr$  r  r   r  rP  rQ  r3   r   )rQ   mydicts     r/   _g_pre_kill_hookzTable._g_pre_kill_hookI  s    ( dm##(C(C(E(E(I(I\ )J"n )J'!++t/A+M H "-/ 1CD D D z"&  {### ! r1   c                     | j         sd S |r|                                  | j        }||                                 t	                                          d           d S )NF)	_v_isopenr  r  _g_closer9  _f_close)rQ   r  r  rB  s      r/   r  zTable._f_closeo  se    ~ 	F  	JJLLL yMMOOO 	r1   c           	          | j         r@d}|t          |           | j        | j        | j        | j        t          | j                  fz  S t          |           d| j        d| j        d| j        S )z=This provides column metainfo in addition to standard __str__z`%s
  description := %r
  byteorder := %r
  chunkshape := %r
  autoindex := %r
  colindexes := %rz
  description := z
  byteorder := z
  chunkshape := )r$  r   r   r   rv   r  r   r  )rQ   r+  s     r/   r   zTable.__repr__  s     < 	OF SYY(8$.!_dn(99; ; ; TD,,,dnnndooO Or1   )Nr   NNNNTTrz  r7   )NNNN)NNN)NNNNN)NFNNN)FNNN)FNNNN)NN)T)FF)NNFF)Wr   r   r   r   
_c_classidr   r   rX   propertyr[   r   r   r   r   r   r  setterr	  r  r  r:  rJ  r^  rb  r   rg  rk  r~  r  rs  r  r;  r  r  r  r  r  r  r  r  r   r  r  rl   r  r"  r$  r  r'  r8  r  rD  r  rH  r   r  rS  r^  rc   rm  rR  rQ  r  r  rZ  r   r  r  r  r  r  r   r[  rq  r  r  r  r  r  r  r  r@  r  r  r  r   __classcell__)rB  s   @r/   r   r   J  s       c cL J( ( X(
 ) ) X)
   X 2 2 X2 ) ) X) 4 4 X4
   X" ' ' X'( # # X#@    / / X/ : : X: 4 4 X4
 6:/38<l& l& l& l& l& l&\G- G- G- G- G-R' ' 'R  : : :) ) )  6  6  6 p9  9  9 v)2 )2 )2V> > > )M2 2 2
1 
1 
1f f f fP  >25 25 25h" " " "* )-*.\C \C \C \C|%? %? %? %?N :>/34 4 4 46 ?C15% % % %N =B377 7 7 70= = =.3 3 3, +0/3: : : :< 9=044 4 4 48', ', ', ',R  4E E E ENG4 G4 G4 G4R       D7 7 7 7 / / /&% % %0:A :A :AxDA DA DAL? ? ?"A6 A6 A6F  2 !  !  !D5! 5! 5! 5!n 9=+/O O O Ob :>+/J J J JX   0  :6 6 6 6p. . .@< < < < <1 1 1 1 1,, , , , , ,0 0 0
+ 
+ 
+$ $ $$% % %	& 	& 	&
% 
% 
%  4  (C C C" " "6 <A D D D D D D@    *$$ $$ $$L           6O O O O O O Or1   r   c                   d    e Zd ZdZed             Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd ZdS )rK  a.  Container for columns in a table or nested column.

    This class is used as an *accessor* to the columns in a table or nested
    column.  It supports the *natural naming* convention, so that you can
    access the different columns as attributes which lead to Column instances
    (for non-nested columns) or other Cols instances (for nested columns).

    For instance, if table.cols is a Cols instance with a column named col1
    under it, the later can be accessed as table.cols.col1. If col1 is nested
    and contains a col2 column, this can be accessed as table.cols.col1.col2
    and so on. Because of natural naming, the names of members start with
    special prefixes, like in the Group class (see :ref:`GroupClassDescr`).

    Like the Column class (see :ref:`ColumnClassDescr`), Cols supports item
    access to read and write ranges of values in the table or nested column.


    .. rubric:: Cols attributes

    .. attribute:: _v_colnames

        A list of the names of the columns hanging directly
        from the associated table or nested column.  The order of
        the names matches the order of their respective columns in
        the containing table.

    .. attribute:: _v_colpathnames

        A list of the pathnames of all the columns under the
        associated table or nested column (in preorder).  If it does
        not contain nested columns, this is exactly the same as the
        :attr:`Cols._v_colnames` attribute.

    .. attribute:: _v_desc

        The associated Description instance (see
        :ref:`DescriptionClassDescr`).

    c                 @    | j                             | j                  S z7The parent Table instance (see :ref:`TableClassDescr`).)_v__tableFiler   _v__tablePathr   s    r/   _v_tablezCols._v_table  s     !++D,>???r1   c                    | j         }|j        |d<   |j        |d<   ||d<   |j        |d<   |j        j        |d<   |j        D ]>}||j        v rt          |||          ||<    t          ||j	        |                   ||<   ?d S )Nr  r  _v_desc_v_colnamesr  )
r  rI   r3   ro  r   rL  _v_typesr  rK  r  )rQ   r8   descmyDictr   s        r/   r:  zCols.__init__  s    "'-"'"3 y $}$)$5$B !M 	E 	EDt}$$%eT488t#E4+=d+CDDt		E 	Er1   c                     | j         }|j        |d<   |j        |d<   | j        D ]}||                             |           dS )>Updates the location information about the associated `table`.r  r  N)r  rI   r3   r  r  )rQ   r8   r  r   s       r/   r  zCols._g_update_table_location  s]     "'-"'"3 ' 	< 	<G7O44U;;;;	< 	<r1   c                 *    t          | j                  S )z-Get the number of top level columns in table.)rh   r  r   s    r/   __len__zCols.__len__  s     4#$$$r1   c           	          t          |t                    st          d|z            |                    d          dk    r:|| j        vr1|| j        vr(t          d| j        d| j        j	        d|d          | 
                    |          S )a2  Get an accessor to the column colname.

        This method returns a Column instance (see :ref:`ColumnClassDescr`) if
        the requested column is not nested, and a Cols instance (see
        :ref:`ColsClassDescr`) if it is.  You may use full column pathnames in
        colname.

        Calling cols._f_col('col1/col2') is equivalent to using cols.col1.col2.
        However, the first syntax is more intended for programmatic use.  It is
        also better if you want to access columns with names that are not valid
        Python identifiers.

        z6Parameter can only be an string. You passed object: %sr   r  zCols accessor ``.colsr  r  )r`   r   r   findr  r  r  r  r  r3   rM  rG  s     r/   r  zCols._f_col  s     '3'' 	4 )+23 4 4 4\\###D000t///("000$,2J2J2J%gg' ( ( (
 {{7###r1   c                 X    |                     d          }| }|D ]}|j        |         }|S )z5Like `self._f_col()` but it does not check arguments.r   )r   r  )rQ   r   r   r  r   s        r/   rM  zCols._g_col	  s<     s## 	( 	(E='DDr1   c                    | j         }|j        }t          |          rt          j        |          }||k    rt          d          |dk     r||z  }|                    ||dz   d          \  }}}| j        j        }|dk    r|	                    |||          d         S |	                    |||          d         }||         S t          |t                    r|                    |j        |j        |j                  \  }}}| j        j        }|dk    r|	                    |||          S |	                    |||          }	t          |	d          r|	                    |          S t#          |	|          S t%          d|          )a  Get a row or a range of rows from a table or nested column.

        If key argument is an integer, the corresponding nested type row is
        returned as a record of the current flavor. If key is a slice, the
        range of rows determined by it is returned as a structured array of the
        current flavor.

        Examples
        --------

        ::

            record = table.cols[4]  # equivalent to table[4]
            recarray = table.cols.Info[4:1000:2]

        Those statements are equivalent to::

            nrecord = table.read(start=4)[0]
            nrecarray = table.read(start=4, stop=1000, step=2).field('Info')

        Here you can see how a mix of natural naming, indexing and slicing can
        be used as shorthands for the :meth:`Table.read` method.

        rK  r   r   r   r  invalid index or slice: )r  rk   r   rM  rq   rN  r  r  r3   r  r`   rO  r   r   r   r  r  r   r   )
rQ   r   r8   rk   r   r   r   colgroupcrecord	crecarrays
             r/   r  zCols.__getitem__  s   2 #;; 	@.%%C e|| !5666Qwwu"'"6"6sC!GQ"G"GUD$|/H2~~zz%t44Q77**UD$77:x((U## 	@"'"6"6	38SX#/ #/UD$|/H2~~zz%t444!JJudD99	9g.. A$??8444+Ix@@@>s>>???r1   c                    | j         }|j        }t          |          rSt          j        |          }||k    rt          d          |dk     r||z  }|                    ||dz   d          \  }}}nRt          |t                    r+|                    |j	        |j
        |j                  \  }}}nt          d|          | j        j        }|dk    r|                    ||||           dS |                    |||||           dS )	a  Set a row or a range of rows in a table or nested column.

        If key argument is an integer, the corresponding row is set to
        value. If key is a slice, the range of rows determined by it is set to
        value.

        Examples
        --------

        ::

            table.cols[4] = record
            table.cols.Info[4:1000:2] = recarray

        Those statements are equivalent to::

            table.modify_rows(4, rows=record)
            table.modify_column(4, 1000, 2, colname='Info', column=recarray)

        Here you can see how a mix of natural naming, indexing and slicing
        can be used as shorthands for the :meth:`Table.modify_rows` and
        :meth:`Table.modify_column` methods.

        rK  r   r   r  r   )rf  )r   rW  N)r  rk   r   rM  rq   rN  r  r`   rO  r   r   r   r   r  r3   rQ  r  )	rQ   r   r   r8   rk   r   r   r   r  s	            r/   rS  zCols.__setitem__M  sF   4 #;; 	@.%%C e|| !5666Qwwu"'"6"6sC!GQ"G"GUD$$U## 	@"'"6"6	38SX#/ #/UD$$ >s>>??? <+r>>eT4e<<<<<tT8E   C C C C Cr1   c                    | j         D ]]}|                     |          }t          |t                    r|                                 | j        |= I|                                 ^| j                                         d S r7   )r  rM  r`   r  closer  r  r  )rQ   r   rU  s      r/   r  zCols._g_close  s~    # 	" 	"C[[%%F&&)) "M#&&!!!!r1   c           	          | j         j        }|rd|z   }| j         d| d| j        j         dt          | j                   dS )*The string representation for this object..r   (z), z columns)r  r3   r  rB  r   rh   r  )rQ   descpathnames     r/   __str__zCols.__str__  sp     |/ 	.-L% 3 3L 3 3N+3 3t'((3 3 3 	4r1   c                 X   | g}| j         D ]}t          | |          j        j        }|| j        j        v r8| j        j        |         }| j        j        f| j        j        |         j        z   }nd}d}|	                    d| d| | d| d           d
                    |          dz   S )1A detailed string representation for this object.r   r<   z  r  , )
)r  r  rB  r   r  	_v_dtypesr  rk   r[   rc   r   )rQ   linesr   	classnametcolr[   s         r/   r   zCols.__repr__  s     $ 	C 	CDd++5>It|---|-d3,.L*4067 %LLAdAAiAAA$AAABBBByy$&&r1   N)r   r   r   r   r  r  r:  r  r  r  rM  r  rS  r  r  r   r<   r1   r/   rK  rK    s        & &P @ @ X@E E E	< 	< 	<% % %
$ $ $8  8@ 8@ 8@t2C 2C 2Ch  	4 	4 	4' ' ' ' 'r1   rK  c                   *   e Zd ZdZed             Zed             Zed             Zed             Z	ed             Z
ed             Zed             Zed	             Zd
 Zd Zd Zd Zd Zd Z	 	 	 ddZ	 	 ddZd Zd Zd Zd Zd Zd Zd ZdS )r  a  Accessor for a non-nested column in a table.

    Each instance of this class is associated with one *non-nested* column of a
    table. These instances are mainly used to read and write data from the
    table columns using item access (like the Cols class - see
    :ref:`ColsClassDescr`), but there are a few other associated methods to
    deal with indexes.

    .. rubric:: Column attributes

    .. attribute:: descr

        The Description (see :ref:`DescriptionClassDescr`) instance of the
        parent table or nested column.

    .. attribute:: name

        The name of the associated column.

    .. attribute:: pathname

        The complete pathname of the associated column (the same as
        Column.name if the column is not inside a nested column).

    Parameters
    ----------
    table
        The parent table instance
    name
        The name of the column that is associated with this object
    descr
        The parent description object

    c                 :    | j         j        | j                 j        S )z6The NumPy dtype that most closely matches this column.)r   r  r   baser   s    r/   rX   zColumn.dtype  s     z#DI.33r1   c                 0    | j         j        | j                 S )z+The PyTables type of the column (a string).)r   r  r   r   s    r/   r2  zColumn.type  s     z"49--r1   c                 @    | j                             | j                  S r  )r  r   r  r   s    r/   r8   zColumn.table  s     ))$*:;;;r1   c                     t          | j        | j                  }	 | j                            |          }n# t
          $ r d}Y nw xY w|S )zxThe Index instance (see :ref:`IndexClassDescr`) associated with this
        column (None if the column is not indexed).N)rD   r  r   r  r   r   )rQ   	indexPathrq   s      r/   rq   zColumn.index  s^     /t/?OO		$..y99EE 	 	 	EEE	s   7 AAc                 0    | j         j        | j                 S r7   )r   r  r   r   s    r/   	_itemtypezColumn._itemtype  s    z#DI..r1   c                 V    | j         j        f| j        j        | j                 j        z   S )zThe shape of this column.)r8   rk   r   r  r   r[   r   s    r/   r[   zColumn.shape  s&     
 "TZ%9$)%D%JJJr1   c                     | j         dS dS )z/True if the column is indexed, false otherwise.NFT)rq   r   s    r/   r  zColumn.is_indexed  s     :54r1   c                     dS )z]"The dimension along which iterators work. Its value is 0 (i.e. the
        first dimension).r   r<   r   s    r/   maindimzColumn.maindim  s	     qr1   c                     |j         | _        |j        | _        || _        	 |j        |         j        | _        	 || _        d S r7   )rI   r  r3   r  r   r  r   r   )rQ   r8   r   r   s       r/   r:  zColumn.__init__  sJ     = ,	0+D1=	E
	* 	*r1   c                 6    |j         | _        |j        | _        dS )r  N)rI   r  r3   r  )rQ   r8   s     r/   r  zColumn._g_update_table_location  s     != ,r1   c                     | j         j        S )zqGet the number of elements in the column.

        This matches the length in rows of the parent table.

        )r8   rk   r   s    r/   r  zColumn.__len__  s     zr1   c                 h   | j         }t          |t                    rt          |          dk    r|d         }t	          |          rt          j        |          }||j        k    rt          d          |dk     r
||j        z  }|	                    ||dz   d          \  }}}|
                    |||| j                  d         S t          |t                    rG|	                    |j        |j        |j                  \  }}}|
                    |||| j                  S t!          d|z            )a  Get a row or a range of rows from a column.

        If key argument is an integer, the corresponding element in the column
        is returned as an object of the current flavor.  If key is a slice, the
        range of elements determined by it is returned as an array of the
        current flavor.

        Examples
        --------

        ::

            print("Column handlers:")
            for name in table.colnames:
                print(table.cols._f_col(name))
                print("Select table.cols.name[1]-->", table.cols.name[1])
                print("Select table.cols.name[1:2]-->", table.cols.name[1:2])
                print("Select table.cols.name[:]-->", table.cols.name[:])
                print("Select table.cols._f_col('name')[:]-->",
                                                table.cols._f_col('name')[:])

        The output of this for a certain arbitrary table is::

            Column handlers:
            /table.cols.name (Column(), string, idx=None)
            /table.cols.lati (Column(), int32, idx=None)
            /table.cols.longi (Column(), int32, idx=None)
            /table.cols.vector (Column(2,), int32, idx=None)
            /table.cols.matrix2D (Column(2, 2), float64, idx=None)
            Select table.cols.name[1]--> Particle:     11
            Select table.cols.name[1:2]--> ['Particle:     11']
            Select table.cols.name[:]--> ['Particle:     10'
             'Particle:     11' 'Particle:     12'
             'Particle:     13' 'Particle:     14']
            Select table.cols._f_col('name')[:]--> ['Particle:     10'
             'Particle:     11' 'Particle:     12'
             'Particle:     13' 'Particle:     14']

        See the :file:`examples/table2.py` file for a more complete example.

        r   r   rK  z*'%s' key type is not valid in this context)r8   r`   re   rh   r   rM  rq   rk   rN  r  r  r   rO  r   r   r   r   )rQ   r   r8   r   r   r   s         r/   r  zColumn.__getitem__   s<   V 

 c5!! 	c#hh!mma&C#;; 	D.%%C ek!! !5666Qwwu{""'"6"6sC!GQ"G"GUD$::eT4??BBU## 	D"'"6"6	38SX#/ #/UD$::eT4???<sBD D Dr1   c              #   ~  K   | j         }| j        j        }|j        j        d         |z  }t          j        |f| j                  }t          |           }t          dt          |           |          D ]I}t          ||z   |          }|d||z
           }|                    ||d| j        |           |E d{V  JdS )z(Iterate through all items in the column.rZ  r   r   )r  r2  N)r8   rX   rM   rI   rJ   ra   r`  r  rh   r,  r?  r  r   )	rQ   r8   rM   r   bufmax_row	start_rowend_row	buf_slices	            r/   r'  zColumn.__iter__f  s       
:&])*:;xG
h
~t~66d))q#d))Z88 	! 	!I)j0'::GAg	112IJJy'1DM$  & & &         	! 	!r1   c                 `   | j         }|j                                         t          |t                    rt          |          dk    r|d         }t          |          rat          j        |          }||j	        k    rt          d          |dk     r
||j	        z  }|                    ||dz   d|gg| j                  S t          |t                    rH|                    |j        |j        |j                  \  }}}|                    ||||| j                  S t%          d|z            )a  Set a row or a range of rows in a column.

        If key argument is an integer, the corresponding element is set to
        value.  If key is a slice, the range of elements determined by it is
        set to value.

        Examples
        --------

        ::

            # Modify row 1
            table.cols.col1[1] = -1

            # Modify rows 1 and 3
            table.cols.col1[1::2] = [2,3]

        Which is equivalent to::

            # Modify row 1
            table.modify_columns(start=1, columns=[[-1]], names=['col1'])

            # Modify rows 1 and 3
            columns = numpy.rec.fromarrays([[2,3]], formats='i4')
            table.modify_columns(start=1, step=2, columns=columns,
                                 names=['col1'])

        r   r   rK  zNon-valid index or slice: %s)r8   rI   r  r`   re   rh   r   rM  rq   rk   rN  r  r   rO  r  r   r   r   r   )rQ   r   r   r8   r   r   r   s          r/   rS  zColumn.__setitem__u  sB   < 
%%'''
 c5!! 	c#hh!mma&C#;; 	C.%%C ek!! !5666Qwwu{"&&sC!GQ).y$-A A AU## 	C"'"6"6	38SX#/ #/UD$&&udD',dm= = = ;cABBBr1      mediumNFc           	      &   g d}||vrt          d|z            t          |t                    r|dk     s|dk    rt          d          |t          }|,t	          t          | j        j                  j                  }n4t          |          	                                st          d| d          |7t          |t                    rt          |          d	k    rt          d
          t          | ||||||          }	t          |	          S )a  Create an index for this column.

        .. warning::

            In some situations it is useful to get a completely sorted
            index (CSI).  For those cases, it is best to use the
            :meth:`Column.create_csindex` method instead.

        Parameters
        ----------
        optlevel : int
            The optimization level for building the index.  The levels ranges
            from 0 (no optimization) up to 9 (maximum optimization).  Higher
            levels of optimization mean better chances for reducing the entropy
            of the index at the price of using more CPU, memory and I/O
            resources for creating the index.
        kind : str
            The kind of the index to be built.  It can take the 'ultralight',
            'light', 'medium' or 'full' values.  Lighter kinds ('ultralight'
            and 'light') mean that the index takes less space on disk, but will
            perform queries slower.  Heavier kinds ('medium' and 'full') mean
            better chances for reducing the entropy of the index (increasing
            the query speed) at the price of using more disk space as well as
            more CPU, memory and I/O resources for creating the index.

            Note that selecting a full kind with an optlevel of 9 (the maximum)
            guarantees the creation of an index with zero entropy, that is, a
            completely sorted index (CSI) - provided that the number of rows in
            the table does not exceed the 2**48 figure (that is more than 100
            trillions of rows).  See :meth:`Column.create_csindex` method for a
            more direct way to create a CSI index.
        filters : Filters
            Specify the Filters instance used to compress the index.  If None,
            default index filters will be used (currently, zlib level 1 with
            shuffling).
        tmp_dir
            When kind is other than 'ultralight', a temporary file is created
            during the index build process.  You can use the tmp_dir argument
            to specify the directory for this temporary file.  The default is
            to create it in the same directory as the file containing the
            original table.

        )
ultralightlightr$  r  z&Kind must have any of these values: %sr   	   z6Optimization level must be an integer in the range 0-9NzTemporary directory 'z' does not exist   z3_blocksizes must be a tuple with exactly 4 elements)r   r`   r7  r    r   r   r  filenameparentis_dirre   rh   r   r   )
rQ   r   r   r   r   _blocksizes	_testmode_verbosekindsidxrowss
             r/   r  zColumn.create_index  sD   ^ :99uEMNNN8S)) 	*AA ) * * *?+G?$t/899@AAGG==''))  EGEEE   #U33 $7:;7G7G17L7L ( ) ) )'hg(/hH H   r1   c           	      :    |                      dd|||||          S )a  Create a completely sorted index (CSI) for this column.

        This method guarantees the creation of an index with zero entropy, that
        is, a completely sorted index (CSI) -- provided that the number of rows
        in the table does not exceed the 2**48 figure (that is more than 100
        trillions of rows).  A CSI index is needed for some table methods (like
        :meth:`Table.itersorted` or :meth:`Table.read_sorted`) in order to
        ensure completely sorted results.

        For the meaning of filters and tmp_dir arguments see
        :meth:`Column.create_index`.

        Notes
        -----
        This method is equivalent to
        Column.create_index(optlevel=9, kind='full', ...).

        r  r(  )r   r   r   r   r-  r.  r/  )r  )rQ   r   r   r-  r.  r/  s         r/   create_csindexzColumn.create_csindex  s4    *   !Wg#y8 ! M M 	Mr1   c                 ,   | j         }d}|r	|j        sd}|p|rn| j                                         |j        }|j        }|j        }d|_        |                                 t          | 	                    |||                    S t          d          S )z4Common code for reindex() and reindex_dirty() codes.TFN)r   r   r   r   )
rq   rr   r  r  r   r   r   r  r   r  )rQ   rr   rq   dodirtyr   r   r   s          r/   r  zColumn._do_reindex  s     
 	 	G,,...:D~HmG  EKOOD--Hg . ? ? @ @ @ A;;r1   c                 2    |                      d           dS )a
  Recompute the index associated with this column.

        This can be useful when you suspect that, for any reason,
        the index information is no longer valid and you want to rebuild it.

        This method does nothing if the column is not indexed.

        Fr  Nr  r   s    r/   r  zColumn.reindex'  s!     	u%%%%%r1   c                 2    |                      d           dS )a\  Recompute the associated index only if it is dirty.

        This can be useful when you have set :attr:`Table.autoindex` to false
        for the table and you want to update the column's index after an
        invalidating index operation (like :meth:`Table.remove_rows`).

        This method does nothing if the column is not indexed.

        Tr  Nr  r   s    r/   r  zColumn.reindex_dirty3  s!     	t$$$$$r1   c                     | j                                          | j        r=| j        }|                                 | j                            | j        d           dS dS )zRemove the index associated with this column.

        This method does nothing if the column is not indexed. The removed
        index can be created again by calling the :meth:`Column.create_index`
        method.

        FN)r  r  r  rq   r  r8   r   r   )rQ   rq   s     r/   remove_indexzColumn.remove_index@  si     	((*** ? 	BJEOOJ++DM5AAAAA	B 	Br1   c                 8    | j                                          dS )zClose this column.N)r  r  r   s    r/   r  zColumn.closeQ  s     	r1   c                     | j          d| j                            dd           d| j        j         | j         d| j        j        | j                  d| j	         dS )r  z.cols.r   r  r  r  z, idx=r  )
r  r   replacerB  r   r[   r   r  r   rq   r   s    r/   r  zColumn.__str__V  s     # G G4=+@+@c+J+J G GN+G-1ZG G:&ty1G G9=G G G 	Hr1   c                      t          |           S )r  )r   r   s    r/   r   zColumn.__repr__]  s     4yyr1   )r#  r$  NNNFF)NNNFF)r   r   r   r   r   rX   r2  r  r8   rq   r  r[   r  r  r:  r  r  r  r'  rS  r  r3  r  r  r  r9  r  r  r   r<   r1   r/   r  r    s       ! !F 4 4 X4
 . . X.
 < < X<   X / / X/ K K XK   X   X

* 
* 
*- - -     DD DD DDL! ! !8C 8C 8Ct ?C?D#E! E! E! E!N 48CHM M M M2  0
& 
& 
&% % %B B B"  
H H H    r1   r  )qr   r  rw   rM  rr  rP  pathlibr   timer   r]   numexprr|   r:  ra   r   r   lrucacheextensionr   r   r   r	   
conditionsr
   r@  r   r   r   utilsr   r   r   r   r,  leafr   r   r   r   r   r   
exceptionsr   r   r   r   r   utilsextensionr   pathr   r   rq   r   r    r!   r"   r#   r$   r\   r%   rv  bool_rY   int8r  int_int16int32rV   long_uint8uint16uint32uint64float32floatfloat64double	complex64complex
complex128bytes_bytesr  r   str_r  r&   r'   r(   r)   r*   rj   rX   r2  rA  r0   r5   r:   r>   rA   rD   rT   r   r   r   r   r1  r   r   rK  r  r<   r1   r/   <module>r\     s*   & &       



        & & & & & &               4 4 4 4 4 4 4 4       ) ) ) ) ) ) D D D D D D D D D D F F F F F F F F F F F F       L L L L L L L L L L L L              - , , , , , ' ' ' ' ' ' ' '               
 
 "!!!!!! 	
 HdGR]Hbm Hbm Hbm!Hbm Ir}!Ir}"Ir}"JJ$L'M7Iu "  # BG 
72y ,&+
#
72y ;&(m&:
#
72z <')}';$
72| 1)0&
72| 1)0& bhxx{{##)." " "; ; ;
= = =  @ @ @
B B B
 
 
N N Nb    [ [ [|0 0 0 0 0$ 0 0 0T)O T)O T)O T)O T)ON $ T)O T)O T)OnRJ' J' J' J' J' J' J' J'Zr r r r r r r r r rr1   