
    Kg                       d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlZddlmZ dd	lmZmZmZ dd
lmZmZmZ ddlmZ ddlmZ ddl m!Z!m"Z"m#Z#m$Z$ erddl%m&Z& ejN                  e(e)   ejT                  ejV                     f   Z,e
e-e.e/e,f   Z0ddZ1ddZ2 ed      dd       Z3ddZ4ddZ5ddZ6 G d de	      Z7 G d de      Z8y)zHere is defined the Leaf class.    )annotationsN)AnyLiteral
NamedTupleUnionTYPE_CHECKING)Path)	lru_cache   )Node)
byteorderslazyattrSizeType)check_flavorinternal_flavortoarray)	alias_map)Filters)NoSuchChunkErrorNotChunkAlignedErrorNotChunkedErrorPerformanceWarning)Groupc                     	 t        t        j                         dz        5 } t        j                  |       cddd       S # 1 sw Y   yxY w# t
        $ r i cY S w xY w)z+Load the CPU information from a cache file..pytables-cpuinfo.jsonN)openr	   homejsonloadFileNotFoundError)fs    +lib/python3.12/site-packages/tables/leaf.pyread_cached_cpu_infor#   )   sG    $))+ 889Q99Q< :99 	s-    A A	A A
A 
A AAc                    t        t        j                         dz  d      5 }t        j                  | |d       ddd       y# 1 sw Y   yxY w)z&Write CPU information to a cache file.r   w   )indentN)r   r	   r   r   dump)cpu_info_dictr!   s     r"   write_cached_cpu_infor*   2   s6    	diik44c	:a		-1- 
;	:	:s   AA)maxsizec                     t               } | r| S 	 ddl}|j                         }	 t	        |       |S # t        $ r i cY S w xY w# t
        $ r Y |S w xY w)z/Return a dictionary containing CPU information.r   N)r#   cpuinfoImportErrorget_cpu_infor*   OSError)cached_infor-   r)   s      r"   r/   r/   8   ss     '(K ((*Mm,
   	
   		s   2 A A A 	AAc                N    d}|t        dt        j                  |       z        z  S )z,Return the fitted chunksize for expected_mb.i       )intmathlog10)expected_mbbasesizes     r"   	csformular9   M   s'    
 Hc!tzz+66777    c                &    | dk  rd} | S | dkD  rd} | S )z:Protection against creating too small or too large chunks.r   i  )r7   s    r"   limit_esr=   V   s+    Q  
u	r:   c                ~    t        |       } t        t        j                  |             }d|z  } t	        |       }|dz  S )a  Compute the optimum HDF5 chunksize for I/O purposes.

    Rational: HDF5 takes the data in bunches of chunksize length to
    write the on disk. A BTree in memory is used to map structures on
    disk. The more chunks that are allocated for a dataset the larger
    the B-tree. Large B-trees take memory and causes file storage
    overhead as well as more disk I/O and higher contention for the meta
    data cache.  You have to balance between memory and I/O overhead
    (small B-trees) and time to access to data (big B-trees).

    The tuning of the chunksize parameter affects the performance and
    the memory consumed. This is based on my own experiments and, as
    always, your mileage may vary.

    
      )r=   r4   r5   r6   r9   )r7   zone	chunksizes      r"   calc_chunksizerC   _   s>      ;'Ktzz+&'Dd(K+&Iq=r:   c                  :    e Zd ZU dZded<   ded<   ded<   ded<   y)		ChunkInfoa  Information about storage for a given chunk.

    It may also refer to a chunk which is within the dataset's shape but that
    does not exist in storage, i.e. a missing chunk.

    An instance of this named tuple class contains the following information,
    in field order:

    .. attribute:: start

        The coordinates in dataset items where the chunk starts, a tuple of
        integers with the same rank as the dataset.  These coordinates are
        always aligned with chunk boundaries.  Also present for missing
        chunks.

    .. attribute:: filter_mask

        An integer where each active bit signals that the filter in its
        position in the pipeline was disabled when storing the chunk.  For
        instance, ``0b10`` disables shuffling, ``0b100`` disables szip, and so
        on.  ``None`` for missing chunks.

    .. attribute:: offset

        An integer which indicates the offset in bytes of chunk data as it
        exists in storage.  ``None`` for missing chunks.

    .. attribute:: size

        An integer which indicates the size in bytes of chunk data as it
        exists in storage.  ``None`` for missing chunks.

    ztuple[int, ...] | Nonestart
int | Nonefilter_maskoffsetsizeN)__name__
__module____qualname____doc____annotations__r<   r:   r"   rE   rE   w   s"     D "!
r:   rE   c                      e Zd ZdZej
                  Z	 ej                  Z	 e	d*d       Z
e	d+d       Ze	d,d       Ze	d,d       Zed-d       Ze	d.d       Ze	d,d       Ze	d/d	       Zej&                  d0d
       Zej(                  d1d       Ze	d,d       Z	 	 	 	 	 d2	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d3 fdZd,dZd*dZd1 fdZ	 	 	 	 	 	 	 	 d4dZd,dZ	 	 d5	 	 	 	 	 	 	 	 	 	 	 d6dZ	 d7	 	 	 	 	 	 	 	 	 d8dZ	 d7	 	 	 	 	 	 	 	 	 d9dZ	 	 	 	 	 	 d:dZd;dZ d1dZ!d<dZ"d<dZ#d1dZ$d=dZ%	 	 	 	 d>	 	 	 	 	 	 	 	 	 d?dZ&	 	 	 	 d>	 	 	 	 	 	 	 	 	 d@dZ'dAdZ(d.d Z)dBd!Z*dCd"Z+dDd#Z,d1d$Z-dEd%Z.	 dF	 	 	 	 	 dGd&Z/	 dH	 	 	 	 	 	 	 dId'Z0d7dJ fd(Z1d7dJd)Z2 xZ3S )KLeafa  Abstract base class for all PyTables leaves.

    A leaf is a node (see the Node class in :class:`Node`) which hangs from a
    group (see the Group class in :class:`Group`) but, unlike a group, it can
    not have any further children below it (i.e. it is an end node).

    This definition includes all nodes which contain actual data (datasets
    handled by the Table - see :ref:`TableClassDescr`, Array -
    see :ref:`ArrayClassDescr`, CArray - see :ref:`CArrayClassDescr`, EArray -
    see :ref:`EArrayClassDescr`, and VLArray - see :ref:`VLArrayClassDescr`
    classes) and unsupported nodes (the UnImplemented
    class - :ref:`UnImplementedClassDescr`) these classes do in fact inherit
    from Leaf.


    .. rubric:: Leaf attributes

    These instance variables are provided in addition to those in Node
    (see :ref:`NodeClassDescr`):

    .. attribute:: byteorder

        The byte ordering of the leaf data *on disk*.  It will be either
        ``little`` or ``big``.

    .. attribute:: dtype

        The NumPy dtype that most closely matches this leaf type.

    .. attribute:: extdim

        The index of the enlargeable dimension (-1 if none).

    .. attribute:: nrows

        The length of the main dimension of the leaf data.

    .. attribute:: nrowsinbuf

        The number of rows that fit in internal input buffers.

        You can change this to fine-tune the speed or memory
        requirements of your application.

    .. attribute:: shape

        The shape of data in the leaf.

    c                    | j                   S )zName of the node.

        The name of this node in its parent group (This is an
        easier-to-write alias of :attr:`Node._v_name`).
        )_v_nameselfs    r"   namez	Leaf.name   s     ||r:   c                    t        | dd      S )zHDF5 chunk size for chunked leaves (a tuple).

        This is read-only because you cannot change the chunk size of a
        leaf once it has been created.
        _v_chunkshapeN)getattrrT   s    r"   
chunkshapezLeaf.chunkshape   s     t_d33r:   c                    | j                   S )zNode identifier, which may change from run to run.

        (This is an easier-to-write alias of :attr:`Node._v_objectid`).

        .. versionchanged:: 3.0
           The *objectID* property has been renamed into *object_id*.

        )_v_objectidrT   s    r"   	object_idzLeaf.object_id   s     r:   c                ,    t        | j                        S )zXReturn the number of dimensions of the leaf data.

        .. versionadded: 2.4
        )lenshaperT   s    r"   ndimz	Leaf.ndim   s     4::r:   c                ,    t        j                  |       S )z]Filter properties for this leaf.

        See Also
        --------
        Filters

        )r   
_from_leafrT   s    r"   filterszLeaf.filters  s     !!$''r:   c                "    | j                         S )a  Return True if the timestamps for the leaf are recorded.

        If the leaf is not a dataset, this will fail with HDF5ExtError.

        The track times dataset creation property does not seem to
        survive closing and reopening as of HDF5 1.8.17.  Currently,
        it may be more accurate to test whether the ctime for the
        dataset is 0:
        track_times = (leaf._get_obj_timestamps().ctime == 0)
        )_get_obj_track_timesrT   s    r"   track_timeszLeaf.track_times  s     ((**r:   c                :    | j                   dk  ry| j                   S )zDimension along which iterators work.

        Its value is 0 (i.e. the first dimension) when the dataset is not
        extendable, and self.extdim (where available) for extendable ones.
        r   )extdimrT   s    r"   maindimzLeaf.maindim  s     ;;?{{r:   c                    | j                   S )a.  Type of the data object read from this leaf.

        It can be any of 'numpy' or 'python'.

        You can (and are encouraged to) use this property to get, set
        and delete the FLAVOR HDF5 attribute of the leaf. When the leaf
        has no such attribute, the default flavor is used.
        )_flavorrT   s    r"   flavorzLeaf.flavor%  s     ||r:   c                ~    | j                   j                          t        |       |x| j                  _        | _        y N)_v_file_check_writabler   _v_attrsFLAVORrl   )rU   rm   s     r"   rm   zLeaf.flavor1  s-    $$&V.44t|r:   c                2    | j                   `t        | _        y ro   )rr   rs   r   rl   rT   s    r"   rm   zLeaf.flavor7  s    MM &r:   c                "    | j                         S )aA  Size on disk of the object.

        The size of this leaf's data in bytes as it is stored on disk.  If the
        data is compressed, this shows the compressed size.  In the case of
        uncompressed, chunked data, this may be slightly larger than the amount
        of data, due to partially filled chunks.
        )_get_storage_sizerT   s    r"   size_on_diskzLeaf.size_on_disk<  s     %%''r:   c                    || _         	 d | _        	 d | _        	 |r7||j                  }|| j                  d<   |dvrt        d|z        || _        	 || _        t        | %  |||       y )Nrd   )NlittlebigzGthe byteorder can only take 'little' or 'big' values and you passed: %s)
_v_new
nrowsinbufrl   
_v_filters__dict__
ValueError	byteorder_want_track_timessuper__init__)	rU   
parentnoderV   newrd   r   _logrg   	__class__s	           r"   r   zLeaf.__init__G  s     ?&*	 :>8$//'.DMM)$ 77 )+45  'DN?!,
 	T40r:   c                    | j                   S )a.  Return the length of the main dimension of the leaf data.

        Please note that this may raise an OverflowError on 32-bit platforms
        for datasets having more than 2**31-1 rows.  This is a limitation of
        Python that you can work around by using the nrows or shape attributes.

        )nrowsrT   s    r"   __len__zLeaf.__len__r  s     zzr:   c                8   g }| j                   j                  r|j                  d       | j                   j                  r| j                   j                  r|j                  d       | j                   j
                  r|j                  d       |j                  | j                   j                   d| j                   j                   d       | j                   d| j                  j                   | j                   dj                  |       d| j                  S )	zReturn the string representation of the object.

        The string representation for this object is its pathname in the
        HDF5 object tree plus some additional metainfo.
        
fletcher32shuffle
bitshuffle()z (z, z) )rd   r   append	complevelr   r   complib_v_pathnamer   rK   r`   join_v_title)rU   rd   s     r"   __str__zLeaf.__str__|  s     <<""NN<(<<!!||##y)||&&|,NNdll2231T\\5K5K4LANO 4>>#:#:";zzl499W-.b0AC	
r:   c                   t         |           | j                  rY| j                  t        | _        y| j
                  j                  d   r'| j                  j                  d| j                         yy| j
                  j                  d   r7t        | j                  dt              }t        j                  ||      | _        yt        | _        y)zCode to be run after node creation and before creation logging.

        This method gets or sets the flavor of the leaf.

        NPYTABLES_SYS_ATTRSrs   )r   _g_post_init_hookr{   rl   r   rp   paramsrr   _g__setattrrY   flavor_alias_mapget)rU   rm   r   s     r"   r   zLeaf._g_post_init_hook  s     	!#;;||#.<<&&';<MM--hE = ||""#78 /J/33FFC.r:   c                   | j                   dk(  rt        d      fS d}||z  |z  }t        |      }| j                  j                  }|y|j                  d      rh| j                  dv rZ|dz  }t               }d|v r@|d   }	|j                  dd	      }
t        |	      t        u rt        |
      t        u r|	|
kD  r|	}|d
kD  rd
}| j                  }||z  }|dk(  rd}t        | j                         }d||<   t        j                  |t              }||k  r	||z  ||<   nMt        t!        |            D ]1  }d||<   t        j                  |t              }||k  s)||z  ||<    n ||d<   t#        d |D              S )z'Calculate the shape for the HDF5 chunk.r<   r   i   blosc2)TABLECARRAYEARRAY   l3_cache_sizel2_cache_sizez	Not foundir   dtypec              3  2   K   | ]  }t        |        y wro   )r   ).0ss     r"   	<genexpr>z(Leaf._calc_chunkshape.<locals>.<genexpr>  s     5*QXa[*s   )r`   r   rC   rd   r   
startswith
_c_classidr/   r   typer4   rj   listnpprodranger_   tuple)rU   expectedrowsrowsizeitemsizeMBr7   rB   r   cpu_infor   r   rj   chunknitemsrZ   newchunknitemsjs                   r"   _calc_chunkshapezLeaf._calc_chunkshape  s   
 ::QK>! #g-"4";/	,,&&""8,#@@ OI#~H(* ( 9 !)_k J'3.]+s2%5 -I :%&	,,8+!K$**%

78<[("-"?Jw 3z?+ !
1!#8!D![0$/>$AJqM , "-
25*555r:   c                    | j                   j                  }| j                  }|d   }|dk7  r||z  }nd}|dk(  r:d}|d   |z  }||kD  r+t        j                  d| j
                   d| dt               |S )z<Calculate the number of rows that fits on a PyTables buffer.IO_BUFFER_SIZEr   r   BUFFER_TIMESzThe Leaf ``z1`` is exceeding the maximum recommended rowsize (a]   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.)rp   r   r   warningswarnr   r   )rU   r   r   
buffersizer|   
maxrowsizes         r"   _calc_nrowsinbufzLeaf._calc_nrowsinbuf  s    $$,,,-
a<#w.JJ ?J/*<J#!$"2"2!3 444>< @,	- ' r:   c                    || j                   }n| j                  |   }|r|r|dk  rt        d      t        |||      j	                  t        |            S )Nr   zslice step cannot be negative)r   r`   r   sliceindicesr4   )rU   rF   stopstepdimwarn_negstepr   s          r"   _process_rangezLeaf._process_range  sV     ;JJEJJsOEDTAX<== UD$'//E
;;r:   c                    | j                   }|3|1|/d|cxk  r|k  rn nt        d|d|d      d}|dk(  r|}n|dz   }| j                  ||||      \  }}}|||fS )Nr   zstart of range (z") is greater than number of rows (r   r   r   )r   )r   
IndexErrorr   )rU   rF   r   r   r   r   s         r"   _process_range_readzLeaf._process_range_read'  s     

$, 5!E! -2E;  D{qy //4L 0 
tT tT""r:   c                P   |j                  dd       }|j                  dd       }|j                  dd       }|j                  d| j                        }	|j                  d| j                        }
|j                  d| j                        }|j                  dd      }|j                  d	d       }|d
k(  r| j                  }n|dk(  rd }|	| j                  }	|
| j                  }
 | j                  ||||||	|
||f	i |\  }}|r(| j
                  j                  |j
                  d       nMd| j
                  v r?| j                  j                  d   r&|j
                  j                  d| j                         | j                  |_
        ||dxx   dz  cc<   |dxx   |z  cc<   |S )NrF   r   r   titlerd   rZ   copyuserattrsTstatskeepauto)	copyclassrs   r   leavesr   bytes)popr   rd   rZ   _g_copy_with_statsrr   _g_copyrp   r   r   rl   )rU   	newparentnewname	recursiver   kwargsrF   r   r   r   rd   rZ   r   r   new_nodebytes_s                   r"   r   zLeaf._g_copy>  s    

7D)zz&$'zz&$'

7DMM2**Y5ZZdoo>


?D9

7D)J6!J =MME?llG 5T44
 
6 MM!!("3"3t!D&||""#78!!--hE<< (Oq O'Nf$Nr:   c                    t         |   }| j                  || _        |dv rH|| j                  k7  r7|j                  j                  s|j	                         }|j                  d       |S d| _        |S )z1Fix the byteorder of data passed in constructors.)ry   rz   T
irrelevant)r   r   flags	writeablecopybyteswap)rU   data
dbyteorders      r"   _g_fix_byteorder_datazLeaf._g_fix_byteorder_dataw  sq      
+
 >>!'DN **T^^+zz++99;Dd#
  *DNr:   c                   |}t        |      t        t        fv rLt        |t              r/t	        |      t	        | j
                        kD  rt        d|      	 t        |      }n(t        |t        j                        st        d|      t	        |      dk(  rt        j                  g d      S |j                  j                  dk(  r`|j
                  | j
                  k(  st        d      t        j                  |j!                         d      }t        j"                  |      }nz|j                  j                  dk(  s|j                  j                  dk(  r<t	        |j
                        d	kD  rt        d
      t	        |j
                        d	k(  r]|j
                  d   t	        | j
                        k7  rt        d
      t        j                  |d      }t        j"                  |      }nt        j                  |d      }|j$                  |n|j$                  }||u r|j'                         }|dk  }|| j
                  z   |   ||<   t        j(                  |dk        s"t        j(                  || j
                  k\        rt        d      t        d      |j*                  j,                  s|j'                         }|S # t        $ r t        d|      w xY w)a  Perform a point-wise selection.

        `key` can be any of the following items:

        * A boolean array with the same shape as self. Those positions
          with True values will signal the coordinates to be returned.

        * A numpy array (or list or tuple) with the point coordinates.
          This has to be a two-dimensional array of size len(self.shape)
          by num_elements containing a list of zero-based values
          specifying the coordinates in the dataset of the selected
          elements. The order of the element coordinates in the array
          specifies the order in which the array elements are iterated
          through when I/O is performed. Duplicate coordinate locations
          are not checked for.

        Return the coordinates array.  If this is not possible, raise a
        `TypeError` so that the next selection method can be tried out.

        This is useful for whatever `Leaf` instance implementing a
        point-wise selection.

        zInvalid index or slice: r   i8r   bz-Boolean indexing array has incompatible shapeiur3   z0Coordinate indexing array has incompatible shapezIndex out of boundsz!Only integer coordinates allowed.)r   r   r   
isinstancer_   r`   r   r   r   	TypeErrorr   ndarrayarrayr   kindasarraynonzero	transposebaser   anyr   
contiguous)rU   key	input_keycoordsr   idxs         r"   _point_selectionzLeaf._point_selection  se   0 	9u%#u%#c(S_*D #;C7!CDDDcl C,6sg>?? s8q=88Bd++99>>S 99

* C  ZZT:F\\&)FYY^^s"ciinn&;399~! F  SYY1$99Q<3tzz?2$J  Ct4f- Ct4 $[[06fkkDy 1*C!DJJ.4F3K vvfqj!RVVFdjj,@%A !677?@@||&&[[]Fe  D":3' BCCDs   K K&c                2    | j                   t        d      y )NzThe dataset is not chunked)rZ   r   rT   s    r"   _check_chunkedzLeaf._check_chunked  s    ??"!">?? #r:   c                    t        |      | j                  k7  rt        d| d| j                         t	        d t        || j                        D              rt        d| d| j                         y )Nz.Chunk coordinates do not match dataset shape: z !~ c              3  :   K   | ]  \  }}|d k  xs ||k\    yw)r   Nr<   )r   cr   s      r"   r   z+Leaf._check_chunk_within.<locals>.<genexpr>  s%     E-D6Aqq1uQ-Ds   z,Chunk coordinates not within dataset shape: z <> )r_   ra   r   r`   r   zipr   rU   r   s     r"   _check_chunk_withinzLeaf._check_chunk_within  s{    v;$))#@($tzzl,  ES-DEE>($tzzl,  Fr:   c                    t        d t        || j                        D              r$t        dt	        |       d| j                         y )Nc              3  ,   K   | ]  \  }}||z    y wro   r<   )r   r  css      r"   r   z+Leaf._check_chunk_coords.<locals>.<genexpr>  s     B%A'1bq2v%As   z.Coordinates are not multiples of chunk shape: z !* )r   r  rZ   r   r   r  s     r"   _check_chunk_coordszLeaf._check_chunk_coords  sJ    BS%ABB&@=/doo%68  Cr:   c                &    | j                  d       y)zRemove this node from the hierarchy.

        This method has the behavior described
        in :meth:`Node._f_remove`. Please note that there is no recursive flag
        since leaves do not have child nodes.

        FN)	_f_removerT   s    r"   removezLeaf.remove  s     	ur:   c                &    | j                  |       y)zqRename this node in place.

        This method has the behavior described in :meth:`Node._f_rename()`.

        N)	_f_rename)rU   r   s     r"   renamezLeaf.rename  s     	wr:   c                ,    | j                  ||||       y)zkMove or rename this node.

        This method has the behavior described in :meth:`Node._f_move`

        N)_f_move)rU   r   r   	overwritecreateparentss        r"   movez	Leaf.move  s     	YMBr:   c                0     | j                   |||fd|i|S )a}  Copy this node and return the new one.

        This method has the behavior described in :meth:`Node._f_copy`. Please
        note that there is no recursive flag since leaves do not have child
        nodes.

        .. warning::

            Note that unknown parameters passed to this method will be
            ignored, so may want to double check the spelling of these
            (i.e. if you write them incorrectly, they will most probably
            be ignored).

        Parameters
        ----------
        title
            The new title for the destination. If omitted or None, the original
            title is used.
        filters : Filters
            Specifying this parameter overrides the original filter properties
            in the source node. If specified, it must be an instance of the
            Filters class (see :ref:`FiltersClassDescr`). The default is to
            copy the filter properties from the source node.
        copyuserattrs
            You can prevent the user attributes from being copied by setting
            this parameter to False. The default is to copy them.
        start, stop, step : int
            Specify the range of rows to be copied; the default is to copy all
            the rows.
        stats
            This argument may be used to collect statistics on the copy
            process. When used, it should be a dictionary with keys 'groups',
            'leaves' and 'bytes' having a numeric value. Their values will be
            incremented to reflect the number of groups, leaves and bytes,
            respectively, that have been copied during the operation.
        chunkshape
            The chunkshape of the new leaf.  It supports a couple of special
            values.  A value of keep means that the chunkshape will be the same
            as original leaf (this is the default).  A value of auto means
            that a new shape will be computed automatically in order to ensure
            the best performance when accessing the dataset through the main
            dimension.  Any other value should be an integer or a tuple
            matching the dimensions of the leaf.

        r  )_f_copy)rU   r   r   r  r  r   s         r"   r   z	Leaf.copy  s5    j t||
 (	

 
 	
r:   c                Z    | j                   dk  rt        d      | j                  |       y)a  Truncate the main dimension to be size rows.

        If the main dimension previously was larger than this size, the extra
        data is lost.  If the main dimension previously was shorter, it is
        extended, and the extended part is filled with the default values.

        The truncation operation can only be applied to *enlargeable* datasets,
        else a TypeError will be raised.

        r   z,non-enlargeable datasets cannot be truncatedN)ri   r   _g_truncate)rU   rJ   s     r"   truncatezLeaf.truncateZ  s)     ;;?JKKr:   c                "    | j                         S )z~Return True if this node is visible.

        This method has the behavior described in :meth:`Node._f_isvisible()`.

        )_f_isvisiblerT   s    r"   	isvisiblezLeaf.isvisiblej  s       ""r:   c                $    | j                  |      S )z~Get a PyTables attribute from this node.

        This method has the behavior described in :meth:`Node._f_getattr`.

        )
_f_getattrrU   rV   s     r"   get_attrzLeaf.get_attrs  s     t$$r:   c                (    | j                  ||       y)zSet a PyTables attribute for this node.

        This method has the behavior described in :meth:`Node._f_setattr()`.

        N)
_f_setattr)rU   rV   values      r"   set_attrzLeaf.set_attr{  s     	e$r:   c                &    | j                  |       y)zDelete a PyTables attribute from this node.

        This method has the behavior described in :meth:`Node_f_delAttr`.

        N)
_f_delattrr#  s     r"   del_attrzLeaf.del_attr  s     	r:   c                $    | j                          y)a.  Flush pending data to disk.

        Saves whatever remaining buffered data to disk. It also releases
        I/O buffers, so if you are filling many datasets in the same
        PyTables session, please call flush() extensively so as to help
        PyTables to keep memory requirements low.

        N)_g_flushrT   s    r"   flushz
Leaf.flush  s     	r:   c                   | j                          | j                  |       t        j                  |t              }| j                  |      \  }}}| j                  }||z  }||z  }t        t        |j                               |||      S )a  Get storage information about the chunk containing the `coords`.

        The coordinates `coords` are a tuple of integers with the same rank as
        the dataset.

        Return a :class:`ChunkInfo` instance with the information.

        The coordinates need not be aligined with chunk boundaries.  This
        means that this method may be used to get the start coordinates of the
        chunk that contains the item at the given coordinates, for use with
        other direct chunking operations (see :attr:`ChunkInfo.start`).

        If the coordinates are within the dataset's shape but there is no such
        chunk in storage (missing chunk), a :class:`ChunkInfo` with a valid
        ``start`` and ``filter_mask = offset = size = None`` is returned.  If
        the coordinates are beyond the shape, :exc:`IndexError` is raised
        (even if the start of the chunk would fall within the shape).

        Calling this method on a non-chunked dataset raises a
        :exc:`NotChunkedError`.

        r   )
r  r	  r   r   r   _g_chunk_inforZ   rE   r   tolist)rU   r   rH   rI   rJ   rZ   s         r"   
chunk_infozLeaf.chunk_info  s    . 	  (&1$($6$6v$>!VT __
:*v}}/fdKKr:   c                t   | j                          | j                  |       | j                  |       |"t        j                  t        |      fd|      }t        j                  |t              }| j                  ||      }|t        dt        |             ||j                         S t        |      S )ai  Get the raw chunk that starts at the given `coords` from storage.

        The coordinates `coords` are a tuple of integers with the same rank as
        the dataset.  If they are not multiples of its chunkshape,
        :exc:`NotChunkAlignedError` is raised.

        If a buffer-like `out` argument is given, it receives chunk data.  If
        it has insufficient storage for the chunk, :exc:`ValueError` is raised
        (use :meth:`chunk_info()` to get the required capacity).

        The obtained data is supposed to have gone at storage time through
        dataset filters, minus those in the chunk's filter mask (use
        :meth:`chunk_info()` to get it).

        Return the chunk's raw content, either as a `bytes` instance (if `out`
        is ``None``) or as a `memoryview` over the object given as `out`.

        Reading a chunk within the dataset's shape, but not in storage
        (missing chunk) raises a :exc:`NoSuchChunkError`.  If the chunk is
        beyond the shape, :exc:`IndexError` is raised.

        Calling this method on a non-chunked dataset raises a
        :exc:`NotChunkedError`.

        u1r   bufferr   z(Can't read missing chunk at coordinates )r  r	  r  r   r   r_   r   r   _g_read_chunkr   r   tobytes
memoryview)rU   r   outchunks       r"   
read_chunkzLeaf.read_chunk  s    < 	  (  (?**c#h[SAC&1""63/=":uV}oN  #&+u}}B:c?Br:   c                   | j                          | j                  |       | j                  |       t        j                  |t
              }t        j                  t        |      fd|      }| j                  |||       y)a  Write `data` to storage for the chunk starting at the given `coords`.

        The coordinates `coords` are a tuple of integers with the same rank as
        the dataset.  If they are not multiples of its chunkshape,
        :exc:`NotChunkAlignedError` is raised.

        The content of the buffer-like `data` must already have gone through
        dataset filters, minus those in the given `filter_mask` (which is to
        be saved along data; see :attr:`ChunkInfo.filter_mask`).

        Writing a chunk which is already in storage replaces it, otherwise it
        is added to storage as long as it is within the dataset's shape
        (missing chunk).  This means that you may use :meth:`truncate()` to
        grow an enlargeable dataset cheaply (as no chunk data is written),
        then sparsely write selected chunks in arbitrary order.

        If the chunk is beyond the dataset's shape, :exc:`IndexError` is
        raised.

        Calling this method on a non-chunked dataset raises a
        :exc:`NotChunkedError`.

        r   r4  r5  N)	r  r	  r  r   r   r   r   r_   _g_write_chunk)rU   r   r   rH   s       r"   write_chunkzLeaf.write_chunk  sf    4 	  (  (&1zz3t9,d4@FD+6r:   c                    | j                   sy|rt        | d      r| j                          | j                          t        |           y)zClose this node in the tree.

        This method has the behavior described in :meth:`Node._f_close`.
        Besides that, the optional argument flush tells whether to flush
        pending data to disk or not before closing.

        N_v_iobuf)	_v_isopenhasattrr.  _g_closer   _f_close)rU   r.  r   s     r"   rE  zLeaf._f_close	  s>     ~~ WT:.JJL 	 	r:   c                &    | j                  |       y)znClose this node in the tree.

        This method is completely equivalent to :meth:`Leaf._f_close`.

        N)rE  )rU   r.  s     r"   closez
Leaf.close!  s     	er:   )returnstr)rH  tuple[int, ...])rH  r4   )rH  r   )rH  bool)rH  Literal['numpy', 'python'])rm   rL  rH  None)rH  rM  )FNNTT)r   r   rV   rI  r   rK  rd   zFilters | Noner   zLiteral['little', 'big', None]r   rK  rg   rK  rH  rM  )r   r4   r   r4   r   r4   rH  rJ  )NT)rF   r4   r   r4   r   r4   r   rG   r   rK  rH  tuple[int, int, int])T)
rF   r4   r   r4   r   r4   r   rK  rH  rN  )
r   r   r   rI  r   rK  r   rK  rH  rQ   )r   
np.ndarrayr   rI  rH  rO  )r   zlist | tuple | np.ndarrayrH  rO  )r   rJ  rH  rM  )r   rI  rH  rM  )NNFF)
r   Group | Noner   
str | Noner  rK  r  rK  rH  rM  )
r   rP  r   rQ  r  rK  r  rK  rH  rQ   )rJ   r4   rH  rM  )rV   rI  rH  r   )rV   rI  r'  r   rH  rM  )rV   rI  rH  rM  )r   rJ  rH  rE   ro   )r   rJ  r:  zbytearray | NPByteArray | NonerH  zbytes | memoryview)r   )r   rJ  r   
BufferLikerH   r4   rH  rM  )r.  rK  rH  rM  )4rK   rL   rM   rN   r   rr   attrsr   r   propertyrV   rZ   r]   ra   r   rd   rg   rj   rm   setterdeleterrw   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  r   r  r   r$  r(  r+  r.  r2  r<  r?  rE  rG  __classcell__)r   s   @r"   rQ   rQ      s   0f MMECMMED   4 4 	  	    ( ( + +   	 	 ]]5 5
 ^^' ' ( ( "&48 )1)1 )1 	)1
  )1 2)1 )1 )1 
)1V
(/(I6I6*-I69<I6	I6VL !<< < 	<
 < < 
<0 FJ## ##+.#>B#	#8 77 7 	7
 7 
7r,/	4Rh@
  #'"#CC C 	C
 C 
C  #'"#;
;
 ;
 	;

 ;
 
;
z #%%	!LL /3+C+C ,+C 
	+C\ MN 7% 7-7 7FI 7	 7D0 r:   rQ   )rH  dict[str, Any])r)   rX  rH  rM  )r7   r4   rH  r4   )9rN   
__future__r   r   r5   r   typingr   r   r   r   r   pathlibr	   	functoolsr
   numpyr   noder   utilsr   r   r   rm   r   r   r   r   r   rd   r   
exceptionsr   r   r   r   groupr   r   r   r4   r   uint8NPByteArrayr   	bytearrayr9  rR  r#   r*   r/   r9   r=   rC   rE   rQ   r<   r:   r"   <module>re     s    % "    A A     1 1 : : 1    jjsRXXbhh%778 5)Z<=
. 1 (80&
 &RG4 Gr:   