
    d7                        d 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mZ dZ	  e            Z	 i Z	 i Z	  ej        d          Zd	 Zd
 Zd Zd Zd Zd Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z  G d de          Z!d Z" e"ed          Z# e"ed          Z$ e"ed           Z% e"ed!          Z& e"e d          Z' e"e d          Z( e"e d           Z) e"e d!          Z* e+ed"          r e"e!d          Z, e"e!d           Z- e"e!d!          Z. e+ed#          r e"e!d$          Z/ e+ed%          r e"e!d&          Z0 G d' d(e          Z1 G d) d*e1e          Z2e2xZ3xZ4Z5 e+ed+          re2Z6 e+ed,          re2Z7 G d- d.e          Z8 G d/ d0e8          Z9 G d1 d2e8          Z: G d3 d4e          Z; G d5 d6e          Z< G d7 d8          Z= G d9 d:e=          Z> G d; d<e>          Z? G d= d>e>          Z@ G d? d@e>          ZAdS )Az-Atom classes for describing dataset contents.    N   SizeType)Enum)FlavorWarningreStructuredTextz^([a-z]+)([0-9]*)$c                    t                               |           }|st          d| z            |                                \  }}d}|r6t	          |          }t          |d          \  }}|rt          d|z            ||fS )a\  Split a PyTables type into a PyTables kind and an item size.

    Returns a tuple of (kind, itemsize). If no item size is present in the type
    (in the form of a precision), the returned item size is None::

        >>> split_type('int32')
        ('int', 4)
        >>> split_type('string')
        ('string', None)
        >>> split_type('int20')
        Traceback (most recent call last):
        ...
        ValueError: precision must be a multiple of 8: 20
        >>> split_type('foo bar')
        Traceback (most recent call last):
        ...
        ValueError: malformed type: 'foo bar'

    zmalformed type: %rN   z%precision must be a multiple of 8: %d)_type_rematch
ValueErrorgroupsintdivmod)typer   kind	precisionitemsize	remainders         +lib/python3.11/site-packages/tables/atom.py
split_typer   %   s    * NN4  E 6-4555llnnOD)H *	NN	$Y22) 	*D() * * *(    c           	      R    t          |          }t          d| d|d|d          S )Ninvalid item size for kind ````: z; it must be one of ``z``)sortedr   )r   r   	itemsizesisizess       r   _invalid_itemsize_errorr   H   s;    IF:xxx1 2 2 2r   c                 >    t          |           d         }|d|fd}|S )z2Return a constructor for an abstract `Atom` class.r    c                     | j         t          v sJ 	 t          | j                  |         }n4# t          $ r' t          | j         |t          | j                            w xY w|| _        |                    | ||           d S N)r   atom_mapKeyErrorr   	__class____init__)selfr   shapedflt	atomclasss        r   r'   z%_abstract_atom_init.<locals>.__init__T   s    yH$$$$	? +H5II 	? 	? 	?)$)X*249*=? ? ?	? #4-----s	   + 1A)r   )deftypedefvaluedefitemsizer'   s       r   _abstract_atom_initr/   O   s8     W%%a(K +2H . . . . Or   c                 X   t          | t          j        t          f          r| dk     rt	          d| z            | f} 	 t          |           } n # t          $ r t          d|           w xY wt          |           dk    rt	          d|           t          d | D                       S )zCCheck that the `shape` is safe to be used and return it as a tuple.r   z&shape value must be greater than 0: %dz&shape must be an integer or sequence:     z)shapes with rank > 32 are not supported: c              3   4   K   | ]}t          |          V  d S r#   r   .0ss     r   	<genexpr>z#_normalize_shape.<locals>.<genexpr>t   s(      ,,!,,,,,,r   )
isinstancenpintegerr   r   tuple	TypeErrorlenr)   s    r   _normalize_shaper>   `   s     %"*c*++ 199E$% & & &$e $ $ $i 5# $ $ 	$$ 5zzBAAAC C 	C ,,e,,,,,,s   A A+c                    | d} |j         }	 t          j        | |          }nP# t          $ rC t          j        |           }|j        |j        k    r t          j        | |j                   }Y nw xY w|j        dk    r|d         }|S )z8Return `value` as a valid default of NumPy type `dtype`.Nr   dtyper!   )baser8   arrayr   r)   )valuerA   	basedtypedefaultrC   s        r   _normalize_defaultrG   w   s    
 }
I8(5	222 8 8 8;)/))(5	7778 }"+Ns   $ A
A10A1c                       fd}|S )aH  Dispatch comparisons to a method of the *other* object.

    Returns a new *rich comparison* method which dispatches calls to
    the method `other_method_name` of the *other* object.  If there is
    no such method in the object, ``False`` is returned.

    This is part of the implementation of a double dispatch pattern.
    c                 `    	 t          |          }n# t          $ r Y dS w xY w ||           S )NF)getattrAttributeError)r(   otherother_methodother_method_names      r   dispatched_cmpz'_cmp_dispatcher.<locals>.dispatched_cmp   sL    	"5*;<<LL 	 	 	55	|D!!!s    
""r!   )rN   rO   s   ` r   _cmp_dispatcherrP      s$    " " " " " r   c                   "     e Zd ZdZ fdZ xZS )MetaAtomz~Atom metaclass.

    This metaclass ensures that data about atom classes gets inserted
    into the suitable registries.

    c                    t                                          |||           |                    d          }|                    d          }|                    d          }|                    d          }|r|r
|t          |<   |rt                              |           |r|rt          |d          s| t          |<   d S |r
i t          |<   |r6t          |d          r(| j        }| t          |         t          |          <   d S d S d S )Nr   r   r   _deftype__int__)
superr'   getdeftype_from_kind	all_typesaddhasattrr$   r   r   )	clsnamebasesdict_r   r   type_r,   r&   s	           r   r'   zMetaAtom.__init__   s&   ue,,,yy  99Z((		&!!))J'' 	.G 	.&-d# 	!MM%    	H 	WXy%A%A 	 !HTNF 	 HTN 	0)44 	08D,/HTN3x==)))	0 	0 	0 	0r   )__name__
__module____qualname____doc__r'   __classcell__)r&   s   @r   rR   rR      sB         0 0 0 0 0 0 0 0 0r   rR   c                      e Zd ZdZed             Zedd            Zedd            Zedd            Zedd            Z	e
d	             Ze
d
             Ze
d             Zd Zd Z ed          Zd Zd Zd Zd ZdS )Atoma  Defines the type of atomic cells stored in a dataset.

    The meaning of *atomic* is that individual elements of a cell can
    not be extracted directly by indexing (i.e.  __getitem__()) the
    dataset; e.g. if a dataset has shape (2, 2) and its atoms have
    shape (3,), to get the third element of the cell at (1, 0) one
    should use dataset[1,0][2] instead of dataset[1,0,2].

    The Atom class is meant to declare the different properties of the
    *base element* (also known as *atom*) of CArray, EArray and
    VLArray datasets, although they are also used to describe the base
    elements of Array datasets. Atoms have the property that their
    length is always the same.  However, you can grow datasets along
    the extensible dimension in the case of EArray or put a variable
    number of them on a VLArray row. Moreover, they are not restricted
    to scalar values, and they can be *fully multidimensional
    objects*.

    Parameters
    ----------
    itemsize : int
        For types with a non-fixed size, this sets the size in
        bytes of individual items in the atom.
    shape : tuple
        Sets the shape of the atom. An integer shape of
        N is equivalent to the tuple (N,).
    dflt
        Sets the default value for the atom.

    The following are the public methods and attributes of the Atom class.

    Notes
    -----
    A series of descendant classes are offered in order to make the
    use of these element descriptions easier. You should use a
    particular Atom descendant class whenever you know the exact type
    you will need when writing your code. Otherwise, you may use one
    of the Atom.from_*() factory Methods.

    .. rubric:: Atom attributes

    .. attribute:: dflt

        The default value of the atom.

        If the user does not supply a value for an element while
        filling a dataset, this default value will be written to disk.
        If the user supplies a scalar value for a multidimensional
        atom, this value is automatically *broadcast* to all the items
        in the atom cell. If dflt is not supplied, an appropriate zero
        value (or *null* string) will be chosen by default.  Please
        note that default values are kept internally as NumPy objects.

    .. attribute:: dtype

        The NumPy dtype that most closely matches this atom.

    .. attribute:: itemsize

        Size in bytes of a single item in the atom.
        Specially useful for atoms of the string kind.

    .. attribute:: kind

        The PyTables kind of the atom (a string).

    .. attribute:: shape

        The shape of the atom (a tuple for scalar atoms).

    .. attribute:: type

        The PyTables type of the atom (a string).

        Atoms can be compared with atoms and other objects for
        strict (in)equality without having to compare individual
        attributes::

            >>> atom1 = StringAtom(itemsize=10)  # same as ``atom2``
            >>> atom2 = Atom.from_kind('string', 10)  # same as ``atom1``
            >>> atom3 = IntAtom()
            >>> atom1 == 'foo'
            False
            >>> atom1 == atom2
            True
            >>> atom2 != atom1
            False
            >>> atom1 == atom3
            False
            >>> atom3 != atom2
            True

    c                 J    | j         }|d|                    d                   S )zReturn the atom class prefix.Nrg   )ra   rfind)r\   cnames     r   prefixzAtom.prefix$  s(     )ekk&)))**r   r!   Nc                    t          |t                    rt          |t          j                  s2|t          j        vrt          d|          t          j        |         }|                     t          j        ||f          |          S )a  Create an Atom from a NumPy scalar type sctype.

        Optional shape and default value may be specified as the
        shape and dflt
        arguments, respectively. Information in the
        sctype not represented in an Atom is ignored::

            >>> import numpy as np
            >>> Atom.from_sctype(np.int16, shape=(2, 2))
            Int16Atom(shape=(2, 2), dflt=0)
            >>> Atom.from_sctype('S5', dflt='hello')
            Traceback (most recent call last):
            ...
            ValueError: unknown NumPy scalar type: 'S5'
            >>> Atom.from_sctype('float64')
            Float64Atom(shape=(), dflt=0.0)

        zunknown NumPy scalar type: )	r7   r   
issubclassr8   generic
sctypeDictr   
from_dtyperA   )r\   sctyper)   r*   s       r   from_sctypezAtom.from_sctype*  s|    ( 64(( 	+VRZ00	+R]** !Iv!I!IJJJ]6*F~~bh77>>>r   c                    |j         }|j        rt          d|z            |j        dk    rt          d|z            |j        dk    r$|j        }|                     d||j        |          S |j        dk    rat          j        dt                     |j        dz  }t          |          |j
        v s
J d	            |                     d||j        |          S |                     |j        |j        |          S )
a  Create an Atom from a NumPy dtype.

        An optional default value may be specified as the dflt
        argument. Information in the dtype not represented in an Atom is
        ignored::

            >>> import numpy as np
            >>> Atom.from_dtype(np.dtype((np.int16, (2, 2))))
            Int16Atom(shape=(2, 2), dflt=0)
            >>> Atom.from_dtype(np.dtype('float64'))
            Float64Atom(shape=(), dflt=0.0)

        Note: for easier use in Python 3, where all strings lead to the
        Unicode dtype, this dtype will also generate a StringAtom. Since
        this is only viable for strings that are castable as ascii, a
        warning is issued.

            >>> Atom.from_dtype(np.dtype('U20')) # doctest: +SKIP
            Atom.py:392: FlavorWarning: support for unicode type is very
                limited, and only works for strings that can be cast as ascii
            StringAtom(itemsize=20, shape=(), dflt=b'')

        z)compound data types are not supported: %rr!   z'nested data types are not supported: %rSstringUz^support for unicode type is very limited, and only works for strings that can be cast as ascii   z)something went wrong in handling unicode.)rB   namesr   r)   r   r   	from_kindwarningswarnr   str	from_typer]   )r\   rA   r*   rE   r   s        r   rp   zAtom.from_dtypeE  s   2 J	? 	&H$% & & &?b  F$% & & &>S   )H==8U[$GGG^s""M M') ) ) !)Q.Hx==IM111; 211==8U[$GGG}}Y^U[$???r   c                     |t           vrt          d|          t          |          \  }}|                     ||||          S )a  Create an Atom from a PyTables type.

        Optional shape and default value may be specified as the
        shape and dflt arguments, respectively::

            >>> Atom.from_type('bool')
            BoolAtom(shape=(), dflt=False)
            >>> Atom.from_type('int16', shape=(2, 2))
            Int16Atom(shape=(2, 2), dflt=0)
            >>> Atom.from_type('string40', dflt='hello')
            Traceback (most recent call last):
            ...
            ValueError: unknown type: 'string40'
            >>> Atom.from_type('Float64')
            Traceback (most recent call last):
            ...
            ValueError: unknown type: 'Float64'

        zunknown type: )rY   r   r   ry   )r\   r   r)   r*   r   r   s         r   r}   zAtom.from_typet  sO    , y  6d66777#D))h}}T8UD999r   c                    d|i}|t           vrt          d|          |dv rt          d|z            |:|t          vrt          d|z            t          |         }t          |          \  }}t           |         }t	          |d          r|}||d<   n||vrt          |||          ||         }|||d	<    |d
i |S )a  Create an Atom from a PyTables kind.

        Optional item size, shape and default value may be
        specified as the itemsize, shape and dflt
        arguments, respectively. Bear in mind that not all atoms support
        a default item size::

            >>> Atom.from_kind('int', itemsize=2, shape=(2, 2))
            Int16Atom(shape=(2, 2), dflt=0)
            >>> Atom.from_kind('int', shape=(2, 2))
            Int32Atom(shape=(2, 2), dflt=0)
            >>> Atom.from_kind('int', shape=1)
            Int32Atom(shape=(1,), dflt=0)
            >>> Atom.from_kind('string', dflt=b'hello')
            Traceback (most recent call last):
            ...
            ValueError: no default item size for kind ``string``
            >>> Atom.from_kind('Float')
            Traceback (most recent call last):
            ...
            ValueError: unknown kind: 'Float'

        Moreover, some kinds with atypical constructor signatures
        are not supported; you need to use the proper
        constructor::

            >>> Atom.from_kind('enum') #doctest: +ELLIPSIS
            Traceback (most recent call last):
            ...
            ValueError: the ``enum`` kind is not supported...

        r)   zunknown kind: )enumzHthe ``%s`` kind is not supported; please use the appropriate constructorNz$no default item size for kind ``%s``r   r   r*   r!   )r$   r   rX   r   r[   r   )	r\   r   r   r)   r*   kwargsr`   kdatar+   s	            r   ry   zAtom.from_kind  s"   F 5!x6d66777 8 F#$ % % %
 ,,, !G#'"( ) ) )%d+E'..ND(5&!! 	(I!)F:u$$-dHeDDDhI!F6Ny""6"""r   c                     | j         j        S )z Total size in bytes of the atom.)rA   r   r(   s    r   sizez	Atom.size  s     z""r   c                 h    t          | j        j                  | j        j        j         dd         z   S )z,String type to be used in numpy.rec.array().r   N)r|   rA   r)   rB   r   s    r   
recarrtypezAtom.recarrtype  s,     4:#$$tz':122'>>>r   c                 *    t          | j                  S )zDThe number of dimensions of the atom.

        .. versionadded:: 2.4)r<   r)   r   s    r   ndimz	Atom.ndim  s    
 4:r   c                 $   t          | d          st          d| j        j        z            t	          |          x| _        }	 t          d |D                       }t          j        ||f          x| _        }	 t          ||          | _
        d S )Nr   z=``%s`` is an abstract class; please use one of its subclassesc              3   4   K   | ]}t          |          V  d S r#   )r   r3   s     r   r6   z Atom.__init__.<locals>.<genexpr>  s(      ..1A......r   )r[   NotImplementedErrorr&   ra   r>   r)   r:   r8   rA   rG   r*   )r(   nptyper)   r*   npshaperA   s         r   r'   zAtom.__init__  s    tV$$ 	A% 'I(,(?'@ A A A .e444
U? .......Xvw&7888
UB&tU33			 		r   c                     d| j          d| j        }t          | j        j        d          sd| j         d| }| j        j         d| dS )Nzshape=, dflt=rU   z	itemsize=z, ())r)   r*   r[   r&   r   ra   )r(   argss     r   __repr__zAtom.__repr__  se    8
884988t~.	:: 	76t}6666D.)33D3333r   _is_equal_to_atomc                 .    |                      |           S r#   )__eq__)r(   rL   s     r   __ne__zAtom.__ne__  s    ;;u%%%%r   c                 n    |                                  }|                    |            | j        di |S )a  Get a copy of the atom, possibly overriding some arguments.

        Constructor arguments to be overridden must be passed as
        keyword arguments::

            >>> atom1 = Int32Atom(shape=12)
            >>> atom2 = atom1.copy()
            >>> print(atom1)
            Int32Atom(shape=(12,), dflt=0)
            >>> print(atom2)
            Int32Atom(shape=(12,), dflt=0)
            >>> atom1 is atom2
            False
            >>> atom3 = atom1.copy(shape=(2, 2))
            >>> print(atom3)
            Int32Atom(shape=(2, 2), dflt=0)
            >>> atom1.copy(foobar=42) #doctest: +ELLIPSIS
            Traceback (most recent call last):
            ...
            TypeError: ...__init__() got an unexpected keyword argument 'foobar'

        r!   )_get_init_argsupdater&   )r(   overridenewargss      r   copyz	Atom.copy  s?    . %%''x   t~(((((r   c                      t          j         j                  }|j        }d |                                D             } fd|D             S )zGet a dictionary of instance constructor arguments.

        This implementation works on classes which use the same names
        for both constructor arguments and instance attributes.

        c                 4    g | ]\  }}|j         |j        u |S r!   )r   POSITIONAL_OR_KEYWORD)r4   argps      r   
<listcomp>z'Atom._get_init_args.<locals>.<listcomp>1  s5     6 6 6Q6Q444 444r   c                 >    i | ]}|d k    |t          |          S r   )rJ   )r4   r   r(   s     r   
<dictcomp>z'Atom._get_init_args.<locals>.<dictcomp>4  s*    IIIC3&==WT3''===r   )inspect	signaturer'   
parametersitems)r(   r   r   r   s   `   r   r   zAtom._get_init_args(  se     %dm44	)
6 6*"2"2"4"4 6 6 6 JIII4IIIIr   c                     | j         |j         k    oA| j        |j        k    o1| j        |j        k    o!t          j        | j        |j        k              S ))Is this object equal to the given `atom`?)r   r)   r   r8   allr*   r(   atoms     r   r   zAtom._is_equal_to_atom6  sQ     	TY& 34:+C 3MT]23F49	122	4r   )r!   Nr#   )Nr!   N)ra   rb   rc   rd   classmethodrk   rr   rp   r}   ry   propertyr   r   r   r'   r   rP   r   r   r   r   r   r!   r   r   rg   rg      s       \ \| + + [+
 ? ? ? [?4 ,@ ,@ ,@ [,@\ : : : [:4 A# A# A# [A#F # # X# ? ? X?   X  04 4 4 _011F& & &) ) )6J J J4 4 4 4 4r   rg   )	metaclassc                   @    e Zd ZdZdZdZdZed             ZdefdZ	dS )
StringAtomzjDefines an atom of type string.

    The item size is the *maximum* length in characters of strings.

    ru   r   c                 $    | j         j        j        S z*Size in bytes of a sigle item in the atom.rA   rB   r   r   s    r   r   zStringAtom.itemsizeI       z''r   r!   c                     t          |d          rt          |          dk     rt          ddd|d          t                              | d|z  ||           d S )NrU   r   r   ru   r   z; it must be a positive integerzS%d)r[   r   r   rg   r'   r(   r   r)   r*   s       r   r'   zStringAtom.__init__N  so    x++ 	5s8}}q/@/@* ((((4 5 5 5 	dEH,eT:::::r   N)
ra   rb   rc   rd   r   r   	_defvaluer   r   r'   r!   r   r   r   r   >  sc          DDI( ( X( (*	 ; ; ; ; ; ;r   r   c                   2    e Zd ZdZdZdZdZdZdZdefdZ	dS )	BoolAtomzDefines an atom of type bool.boolr   bool8Fr!   c                 J    t                               | | j        ||           d S r#   rg   r'   r   r(   r)   r*   s      r   r'   zBoolAtom.__init___  "    dDIud33333r   N)
ra   rb   rc   rd   r   r   r   rT   r   r'   r!   r   r   r   r   V  sL        ''DHDHIi 4 4 4 4 4 4r   r   c                   :    e Zd ZdZdZdZdZdZ eee          Z	dS )IntAtomz5Defines an atom of a signed integral type (int kind).r   Tint32r   N
ra   rb   rc   rd   r   signedrT   r   r/   r'   r!   r   r   r   r   c  s:        ??DFHI""8Y77HHHr   r   c                   :    e Zd ZdZdZdZdZdZ eee          Z	dS )UIntAtomz9Defines an atom of an unsigned integral type (uint kind).uintFuint32r   Nr   r!   r   r   r   r   m  s:        CCDFHI""8Y77HHHr   r   c                   6    e Zd ZdZdZdZdZ eee          ZdS )	FloatAtomz6Defines an atom of a floating point type (float kind).floatfloat64        N	ra   rb   rc   rd   r   rT   r   r/   r'   r!   r   r   r   r   w  s5        @@DHI""8Y77HHHr   r   c                     d|                                  |dz  fz  }|                                }||d|z  d}d| j        fd}||d<   t          d|z  | f|          S )	zMCreate a numeric atom class with the given `baseclass` and an
    `itemsize`.%s%dr
   zDefines an atom of type ``%s``.)r   r   rd   r!   c                 J    t                               | | j        ||           d S r#   r   r   s      r   r'   z'_create_numeric_class.<locals>.__init__  r   r   r'   z%sAtom)rk   lowerr   r   )	baseclassr   rk   r`   	classdictr'   s         r   _create_numeric_classr     s     y''))8a<88FLLNNE%u=EG GI  i&9 4 4 4 4$Ij6!I<;;;r      rw   r
   float16float96   float128   c                   t   e Zd ZdZdZdZdZddgZed             Z	e
                    d           e
                    d            eed	          r*e
                    d	           e                    d
            eed          r*e
                    d           e                    d           defdZdS )ComplexAtoma  Defines an atom of kind complex.

    Allowed item sizes are 8 (single precision) and 16 (double precision). This
    class must be used instead of more concrete ones to avoid confusions with
    numarray-like precision specifications used in PyTables 1.X.

    complex
complex128y                r
   r   c                 $    | j         j        j        S r   r   r   s    r   r   zComplexAtom.itemsize  r   r   	complex64
complex192   
complex256r1   r!   c                     || j         vrt          d|| j                   d| j        |dz  fz  | _        t                              | | j        ||           d S )Nr   r   r
   )_isizesr   r   r   rg   r'   r   s       r   r'   zComplexAtom.__init__  sZ    4<''))Xt|LLLdiA66	dDIud33333r   N)ra   rb   rc   rd   r   rT   r   r   r   r   rY   rZ   r[   r8   appendr'   r!   r   r   r   r     s          DHI"gG( ( X( MM+MM,wr<   l###rwr<   l###r')	 4 4 4 4 4 4r   r   c                   (    e Zd ZdZdej        fdZdS )_ComplexErrorAtomz:Reminds the user to stop using the old complex atom names.r!   c                      t          d          )Nzto avoid confusions with PyTables 1.X complex atom names, please use ``ComplexAtom(itemsize=N)``, where N=8 for single precision complex atoms, and N=16 for double precision complex atoms)r;   r   s      r   r'   z_ComplexErrorAtom.__init__  s    :; ; 	;r   N)ra   rb   rc   rd   r   r   r'   r!   r   r   r   r     s6        DDk&; ; ; ; ; ; ;r   r   r   r   c                   6    e Zd ZdZdZdZdZ eee          ZdS )TimeAtoma5  Defines an atom of time type (time kind).

    There are two distinct supported types of time: a 32 bit integer value and
    a 64 bit floating point value. Both of them reflect the number of seconds
    since the Unix epoch. This atom has the property of being stored using the
    HDF5 time datatypes.

    timetime32r   Nr   r!   r   r   r   r     s;          DHI""8Y77HHHr   r   c                   *    e Zd ZdZdZdZdZdefdZdS )
Time32AtomzDefines an atom of type time32.rw   r   r   r!   c                 @    t                               | d||           d S )Nr   rg   r'   r   s      r   r'   zTime32Atom.__init__  s     dGUD11111r   Nra   rb   rc   rd   r   r   r   r'   r!   r   r   r   r     sB        ))HDIi 2 2 2 2 2 2r   r   c                   *    e Zd ZdZdZdZdZdefdZdS )
Time64AtomzDefines an atom of type time64.r
   time64r   r!   c                 @    t                               | d||           d S )Nr   r   r   s      r   r'   zTime64Atom.__init__  s     dIud33333r   Nr   r!   r   r   r   r     sB        ))HDIi 4 4 4 4 4 4r   r   c                   l    e Zd ZdZdZdZed             Zd Zd Z	d Z
d Zdd	Zd
 Z ed          ZdS )EnumAtomad  Description of an atom of an enumerated type.

    Instances of this class describe the atom type used to store enumerated
    values. Those values belong to an enumerated type, defined by the first
    argument (enum) in the constructor of the atom, which accepts the same
    kinds of arguments as the Enum class (see :ref:`EnumClassDescr`).  The
    enumerated type is stored in the enum attribute of the atom.

    A default value must be specified as the second argument (dflt) in the
    constructor; it must be the *name* (a string) of one of the enumerated
    values in the enumerated type. When the atom is created, the corresponding
    concrete value is broadcast and stored in the dflt attribute (setting
    different default values for items in a multidimensional atom is not
    supported yet). If the name does not match any value in the enumerated
    type, a KeyError is raised.

    Another atom must be specified as the base argument in order to determine
    the base type used for storing the values of enumerated values in memory
    and disk. This *storage atom* is kept in the base attribute of the created
    atom. As a shorthand, you may specify a PyTables type instead of the
    storage atom, implying that this has a scalar shape.

    The storage atom should be able to represent each and every concrete value
    in the enumeration. If it is not, a TypeError is raised. The default value
    of the storage atom is ignored.

    The type attribute of enumerated atoms is always enum.

    Enumerated atoms also support comparisons with other objects::

        >>> enum = ['T0', 'T1', 'T2']
        >>> atom1 = EnumAtom(enum, 'T0', 'int8')  # same as ``atom2``
        >>> atom2 = EnumAtom(enum, 'T0', Int8Atom())  # same as ``atom1``
        >>> atom3 = EnumAtom(enum, 'T0', 'int16')
        >>> atom4 = Int8Atom()
        >>> atom1 == enum
        False
        >>> atom1 == atom2
        True
        >>> atom2 != atom1
        False
        >>> atom1 == atom3
        False
        >>> atom1 == atom4
        False
        >>> atom4 != atom1
        True

    Examples
    --------

    The next C enum construction::

        enum myEnum {
            T0,
            T1,
            T2
        };

    would correspond to the following PyTables
    declaration::

        >>> my_enum_atom = EnumAtom(['T0', 'T1', 'T2'], 'T0', 'int32')

    Please note the dflt argument with a value of 'T0'. Since the concrete
    value matching T0 is unknown right now (we have not used explicit concrete
    values), using the name is the only option left for defining a default
    value for the atom.

    The chosen representation of values for this enumerated atom uses unsigned
    32-bit integers, which surely wastes quite a lot of memory. Another size
    could be selected by using the base argument (this time with a full-blown
    storage atom)::

        >>> my_enum_atom = EnumAtom(['T0', 'T1', 'T2'], 'T0', UInt8Atom())

    You can also define multidimensional arrays for data elements::

        >>> my_enum_atom = EnumAtom(
        ...    ['T0', 'T1', 'T2'], 'T0', base='uint32', shape=(3,2))

    for 3x2 arrays of uint32.

    r   c                 $    | j         j        j        S z+Size in bytes of a single item in the atom.r   r   s    r   r   zEnumAtom.itemsized  r   r   c                    |j         dk    rt          d|z            |j        }d | j        D             }	 t	          j        |          }n# t          $ r t          d          w xY w	 t	          j        ||j                  }n# t          $ r t          d          w xY w|j        dd         |j        k    rt          d	          |	                                |	                                k    rt          d
          |j        j         dvrt          d          t          |j                  dk    rt          d          dS )zCheck the `base` storage atom.r   z4can not use an enumerated atom as a storage atom: %rc                     g | ]\  }}|S r!   r!   )r4   r]   rD   s      r   r   z'EnumAtom._checkbase.<locals>.<listcomp>s  s    999mtUE999r   z(concrete values are not uniformly-shapedr@   zIstorage atom type is incompatible with concrete values in the enumerationr   NzLstorage atom shape does not match that of concrete values in the enumerationzHstorage atom type lacks precision for concrete values in the enumeration)iuz@only integer concrete values are supported for the moment, sorryz?only scalar concrete values are supported for the moment, sorry)r   r;   rA   r   r8   rC   r   rB   r)   tolistr   r<   )r(   rB   rE   pyvaluesnpgenvaluesnpvaluess         r   
_checkbasezEnumAtom._checkbasei  s    9 46:; < < <
 J	99ty999	H(8,,KK 	H 	H 	HFGGG	H	Bx9>BBBHH 	B 	B 	B A B B B	B >!""00 A B B B?? 2 2 4 444 A B B B >j00% 'L M M Mx~""% 'L M M M #"s   A A&*B B c                 P    t          | j        | j        | j        | j                  S )z3Get a dictionary of instance constructor arguments.)r   r*   rB   r)   )dictr   _defnamerB   r)   r   s    r   r   zEnumAtom._get_init_args  s,     $*6 6 6 	6r   c                     dS )r   Fr!   r   s     r   r   zEnumAtom._is_equal_to_atom  s	     ur   c                     | j         |j         k    oA| j        |j        k    o1t          j        | j        |j        k              o| j        |j        k    S )z-Is this object equal to the given `enumatom`?)r   r)   r8   r   r*   rB   )r(   enumatoms     r   _is_equal_to_enumatomzEnumAtom._is_equal_to_enumatom  sQ     	X]* /tzX^/K /F49566/I.	0r   r!   c                    t          |t                    st          |          }|| _        t          |t                    rt                              |          }|                     |           || _        ||         }|| _        g g }}|D ]/\  }}	|	                    |           |	                    |	           0| j        j
        }
|| _        t          j        ||
j                  | _        t                              | |
||           d S )Nr@   )r7   r   r   r|   rg   r}   r  rB   r  r   rA   _namesr8   rC   _valuesr'   )r(   r   r*   rB   r)   rF   rx   valuesr]   rD   rE   s              r   r'   zEnumAtom.__init__  s    $%% 	::D	dC   	(>>$''D	t* Bv! 	! 	!MT5LLMM%    IO	xin===dIug66666r   c           	      H    d| j         d| j        d| j        d| j        d	S )NzEnumAtom(enum=r   z, base=z, shape=r   )r   r  rB   r)   r   s    r   r   zEnumAtom.__repr__  s1     999dmmmTYYY


D 	Er   r  Nr!   )ra   rb   rc   rd   r   r   r   r   r  r   r   r  r'   r   rP   r   r!   r   r   r   r     s        S Sv DD( ( X(!M !M !MF6 6 6  
0 0 07 7 7 74E E E _455FFFr   r   c                   F    e Zd ZdZdZdZdZdZed             Z	d
dZ
d	 ZdS )ReferenceAtomzSDefines an atom of type object to read references.
    This atom is read-only.
    	referenceobjectNoneTypeNc                 $    | j         j        j        S r   r   r   s    r   r   zReferenceAtom.itemsize  r   r   r!   c                 T    t                               | | j        || j                   d S r#   )rg   r'   r   r   )r(   r)   s     r   r'   zReferenceAtom.__init__  s$    dDIudn=====r   c                     d| j          dS )NzReferenceAtom(shape=r   r=   r   s    r   r   zReferenceAtom.__repr__  s    3dj3333r   r  )ra   rb   rc   rd   r   r   rT   r   r   r   r'   r   r!   r   r   r  r    sp          DDHI( ( X(> > > >4 4 4 4 4r   r  c                   $    e Zd ZdZd Zd Zd ZdS )
PseudoAtoma  Pseudo-atoms can only be used in ``VLArray`` nodes.

    They can be recognised because they also have `kind`, `type` and
    `shape` attributes, but no `size`, `itemsize` or `dflt` ones.
    Instead, they have a `base` atom which defines the elements used
    for storage.
    c                      d| j         j        z  S )Nz%s())r&   ra   r   s    r   r   zPseudoAtom.__repr__  s    ///r   c                     t           )z1Convert an `object_` into an array of base atoms.r   r(   object_s     r   toarrayzPseudoAtom.toarray  
     "!r   c                     t           )z0Convert an `array` of base atoms into an object.r"  r(   rC   s     r   	fromarrayzPseudoAtom.fromarray  r&  r   N)ra   rb   rc   rd   r   r%  r)  r!   r   r   r  r    sK         0 0 0" " "
" " " " "r   r  c                   "    e Zd ZdZdZd Zd ZdS )_BufferedAtomz@Pseudo-atom which stores data as a buffer (flat array of uints).r!   c                     |                      |          }t          j        || j        j        t          |                    }|S )NbufferrA   r)   )	_tobufferr8   ndarrayrB   rA   r<   )r(   r$  buffer_rC   s       r   r%  z_BufferedAtom.toarray	  s?    ..))
'!$W/ / /r   c                     t           )z#Convert an `object_` into a buffer.r"  r#  s     r   r/  z_BufferedAtom._tobuffer  r&  r   N)ra   rb   rc   rd   r)   r%  r/  r!   r   r   r+  r+    s=        JJE  " " " " "r   r+  c                   :    e Zd ZdZdZdZ e            Zd Zd Z	dS )VLStringAtomu  Defines an atom of type ``vlstring``.

    This class describes a *row* of the VLArray class, rather than an atom. It
    differs from the StringAtom class in that you can only add *one instance of
    it to one specific row*, i.e. the :meth:`VLArray.append` method only
    accepts one object when the base atom is of this type.

    This class stores bytestrings. It does not make assumptions on the
    encoding of the string, and raw bytes are stored as is. To store a string
    you will need to *explicitly* convert it to a bytestring before you can
    save them::

        >>> s = 'A unicode string: hbar = ℏ'
        >>> bytestring = s.encode('utf-8')
        >>> VLArray.append(bytestring) # doctest: +SKIP

    For full Unicode support, using VLUnicodeAtom (see :ref:`VLUnicodeAtom`) is
    recommended.

    Variable-length string atoms do not accept parameters and they cause the
    reads of rows to always return Python bytestrings.  You can regard vlstring
    atoms as an easy way to save generic variable length strings.

    vlstringc                     t          |t                    rt          j        dt                     n't          |t
                    st          d|          t          j        |          S )Nz6Storing non bytestrings in VLStringAtom is deprecated.object is not a string: )	r7   r|   rz   r{   DeprecationWarningbytesr;   r8   string_r#  s     r   r/  zVLStringAtom._tobuffer3  sp    gs## 	DM ();= = = =GU++ 	DBwBBCCCz'"""r   c                 *    |                                 S r#   )tobytesr(  s     r   r)  zVLStringAtom.fromarray;  s    }}r   N
ra   rb   rc   rd   r   r   	UInt8AtomrB   r/  r)  r!   r   r   r4  r4    sS         2 DD9;;D# # #    r   r4  c                   @    e Zd ZdZdZdZ e            Zd Zd Z	d Z
dS )VLUnicodeAtoma0  Defines an atom of type vlunicode.

    This class describes a *row* of the VLArray class, rather than an atom.  It
    is very similar to VLStringAtom (see :ref:`VLStringAtom`), but it stores
    Unicode strings (using 32-bit characters a la UCS-4, so all strings of the
    same length also take up the same space).

    This class does not make assumptions on the encoding of plain input
    strings.  Plain strings are supported as long as no character is out of the
    ASCII set; otherwise, you will need to *explicitly* convert them to Unicode
    before you can save them.

    Variable-length Unicode atoms do not accept parameters and they cause the
    reads of rows to always return Python Unicode strings.  You can regard
    vlunicode atoms as an easy way to save variable length Unicode strings.

    	vlunicodec                 V   t          |t                    rt          j        dt                     n't          |t
                    st          d|          t          |          }t          j        |d          }t          j	        || j
        j        t          |                    S )N3Storing bytestrings in VLUnicodeAtom is deprecated.r7  rv   r@   r-  )r7   r9  rz   r{   r8  r|   r;   r8   rC   r0  rB   rA   r<   )r(   r$  ustruarrs       r   r%  zVLUnicodeAtom.toarray]  s    gu%% 	DM ();= = = =GS)) 	DBwBBCCC7||xC(((ztyc$iiA A A 	Ar   c                     t          |t                    rt          j        dt                     n't          |t
                    st          d|          t          j        |          S )NrC  r7  )	r7   r9  rz   r{   r8  r|   r;   r8   unicode_r#  s     r   r/  zVLUnicodeAtom._tobufferh  sr     gu%% 	DM ();= = = =GS)) 	DBwBBCCC{7###r   c                     t          |          }|dk    rdS |                    d|z                                            S )Nr    zU%d)r<   viewitem)r(   rC   lengths      r   r)  zVLUnicodeAtom.fromarrays  s=    UQ;;2zz%&.))..000r   N)ra   rb   rc   rd   r   r   
UInt32AtomrB   r%  r/  r)  r!   r   r   r@  r@  ?  se         $ DD:<<D	A 	A 	A	$ 	$ 	$1 1 1 1 1r   r@  c                   :    e Zd ZdZdZdZ e            Zd Zd Z	dS )
ObjectAtoma  Defines an atom of type object.

    This class is meant to fit *any* kind of Python object in a row of a
    VLArray dataset by using pickle behind the scenes. Due to the fact that
    you can not foresee how long will be the output of the pickle
    serialization (i.e. the atom already has a *variable* length), you can only
    fit *one object per row*. However, you can still group several objects in a
    single tuple or list and pass it to the :meth:`VLArray.append` method.

    Object atoms do not accept parameters and they cause the reads of rows to
    always return Python objects. You can regard object atoms as an easy way to
    save an arbitrary number of generic Python objects in a VLArray dataset.

    r  c                 @    t          j        |t           j                  S r#   )pickledumpsHIGHEST_PROTOCOLr#  s     r   r/  zObjectAtom._tobuffer  s    |GV%<===r   c                 h    |j         dk    rd S t          j        |                                          S )Nr   )r   rQ  loadsr<  r(  s     r   r)  zObjectAtom.fromarray  s,     :??4|EMMOO,,,r   Nr=  r!   r   r   rO  rO  z  sS          DD9;;D> > >- - - - -r   rO  )Brd   rer   rz   numpyr8   utilsr   	misc.enumr   rQ  
exceptionsr   __docformat__setrY   r$   rX   compiler   r   r   r/   r>   rG   rP   r   rR   rg   r   r   r   r   r   r   Int8Atom	Int16Atom	Int32Atom	Int64Atomr>  
UInt16AtomrM  
UInt64Atomr[   Float16AtomFloat32AtomFloat64AtomFloat96AtomFloat128Atomr   r   Complex32AtomComplex64AtomComplex128AtomComplex192AtomComplex256Atomr   r   r   r   r  r  r+  r4  r@  rO  r!   r   r   <module>rn     s   3 3 				                    % % % % % %" 9CEE	     : 2:+,,     F2 2 2  "- - -.  .  &!0 !0 !0 !0 !0t !0 !0 !0Hv4 v4 v4 v4 v4X v4 v4 v4 v4r; ; ; ; ; ; ; ;0
4 
4 
4 
4 
4t 
4 
4 
48 8 8 8 8d 8 8 88 8 8 8 8t 8 8 88 8 8 8 8 8 8 8< < < ! !,,!!'1--	!!'1--	!!'1--	!!(A..	""8Q//
""8Q//
""8Q//

72y 6''	155K##Iq11##Iq11
72y 7''	266K
72z 8((B77L(4 (4 (4 (4 (4$ (4 (4 (4V; ; ; ; ;t ; ; ; ; 2C B B
72| '&N
72| '&N8 8 8 8 8t 8 8 8 2 2 2 2 2 2 2 24 4 4 4 4 4 4 4w6 w6 w6 w6 w6t w6 w6 w6@4 4 4 4 4D 4 4 4P" " " " " " " "." " " " "J " " ""' ' ' ' '= ' ' 'T81 81 81 81 81M 81 81 81v- - - - - - - - - -r   