a
    OfW                    @  sR  U d Z ddlmZ ddlmZ ddlZddlmZmZ ddl	Z	ddl
Z
ddlZddlmZ ddlmZmZmZmZmZmZmZ ddlZddlZddlmZmZmZmZ dd	lmZm Z! dd
l"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: ddl;m<Z<m=Z=m>Z>m?Z? ddl@mAZA ddlBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZL ddlMmNZNmOZOmPZP ddlQmR  mSZT ddlUmVZVmWZW ddlXmYZY ddlZm[Z[ ddl\m]Z]m^Z^ ddl_m`Z` ddlambZbmcZc ervddldmeZemfZfmgZg ddlhmiZi ddljmkZkmlZlmmZm ddlnmoZompZpmqZqmrZrmsZsmtZtmuZumvZv dd l\mwZw d!Zxd"Zyd#d$ Zzd%d&d'd(d)Z{d*d+ Z|eVZ}d,d-d.d/Z~d0Zd1ed2< d3Zd1ed4< d5Zd1ed6< d7d7d8d8d9ZeCdgiZd:Zd1ed;< d<Zd1ed=< ed>@ ejd?d@eejdA ejdBdeeg dCdA W d   n1 sV0    Y  dad@adDdE ZddId&dJd&dKd%dLd%dLdMdNdOd&d&dPdQdRdSZddId&d&dUdKdKdVdLdKdW	dXdYZdZdZdLd[d\d]ZG d^d_ d_ZG d`da daZG dbdc dcZG ddde deeZG dfdg dgeZG dhdi dieZG djdk dkeZG dldm dmZG dndo doeZG dpdq dqeZG drds dseZG dtdu dueZG dvdw dweZG dxdy dyeZG dzd{ d{eZG d|d} d}eZG d~d deZG dd deZG dd deZG dd deZddddddddZdddddZeddddLddddZedddPdLddddZddddLddddZd&dd&d&dcdddZd&d&d&ddddZd&dddddZdd&d&ddddZdd&d&ddddZdd&d&d&dddZd&d&d&dddZd&dLdddZd&dd&dddZd&d&dddZddddZG dd dZdS )zY
High level interface to PyTables for reading and writing pandas data structures
to disk
    )annotations)suppressN)datetzinfo)dedent)TYPE_CHECKINGAnyCallableFinalLiteralcastoverload)config
get_optionusing_copy_on_writeusing_pyarrow_string_dtype)libwriters)is_string_array)	timezones)import_optional_dependency)patch_pickle)AttributeConflictWarningClosedFileErrorIncompatibilityWarningPerformanceWarningPossibleDataLossError)cache_readonly)find_stack_level)ensure_objectis_bool_dtypeis_complex_dtypeis_list_likeis_string_dtypeneeds_i8_conversion)CategoricalDtypeDatetimeTZDtypeExtensionDtypePeriodDtype)array_equivalent)
	DataFrameDatetimeIndexIndex
MultiIndexPeriodIndex
RangeIndexSeriesTimedeltaIndexconcatisna)CategoricalDatetimeArrayPeriodArray)PyTablesExprmaybe_expression)extract_array)ensure_index)ArrayManagerBlockManager)stringify_path)adjoinpprint_thing)HashableIteratorSequence)TracebackType)ColFileNode)AnyArrayLike	ArrayLikeAxisIntDtypeArgFilePathSelfShapenpt)Blockz0.15.2UTF-8c                 C  s   t | tjr| d} | S )z(if we have bytes, decode them to unicoderP   )
isinstancenpbytes_decode)s rV   K/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/io/pytables.py_ensure_decoded   s    
rX   
str | Nonestr)encodingreturnc                 C  s   | d u rt } | S N)_default_encodingr[   rV   rV   rW   _ensure_encoding   s    r`   c                 C  s   t | trt| } | S )z
    Ensure that an index / column name is a str (python 3); otherwise they
    may be np.string dtype. Non-string dtypes are passed through unchanged.

    https://github.com/pandas-dev/pandas/issues/13492
    )rQ   rZ   namerV   rV   rW   _ensure_str   s    
rc   intscope_levelc                   sV   |d  t | ttfr* fdd| D } nt| r>t|  d} | du sNt| rR| S dS )z
    Ensure that the where is a Term or a list of Term.

    This makes sure that we are capturing the scope of variables that are
    passed create the terms here with a frame_level=2 (we are 2 levels down)
       c                   s0   g | ](}|d urt |r(t| d dn|qS )Nrg   re   )r8   Term).0termlevelrV   rW   
<listcomp>   s   z _ensure_term.<locals>.<listcomp>re   N)rQ   listtupler8   rh   len)whererf   rV   rk   rW   _ensure_term   s    	
rr   z
where criteria is being ignored as this version [%s] is too old (or
not-defined), read the file in and write it out to a new file to upgrade (with
the copy_to method)
r
   incompatibility_doczu
the [%s] attribute of the existing index is [%s] which conflicts with the new
[%s], resetting the attribute to None
attribute_conflict_docz
your performance may suffer as PyTables will pickle object types that it cannot
map directly to c-types [inferred_type->%s,key->%s] [items->%s]
performance_docfixedtable)frv   trw   z;
: boolean
    drop ALL nan rows when appending to a table

dropna_docz~
: format
    default format writing format, if None, then
    put will default to 'fixed' and append will default to 'table'

format_doczio.hdfZdropna_tableF)	validatordefault_format)rv   rw   Nc                  C  sL   t d u rHdd l} | a tt | jjdkaW d    n1 s>0    Y  t S )Nr   strict)
_table_modtablesr   AttributeErrorfileZ_FILE_OPEN_POLICY!_table_file_open_policy_is_strict)r   rV   rV   rW   _tables   s    

 r   aTr~   zFilePath | HDFStoreDataFrame | Series
int | Noneboolint | dict[str, int] | Nonebool | None Literal[True] | list[str] | NoneNone)path_or_bufkeyvaluemode	complevelcomplibappendformatindexmin_itemsizedropnadata_columnserrorsr[   r\   c              
     s   |r$ 	f
dd}n 	f
dd}t | } t| trt| |||d}|| W d   q1 s0    Y  n||  dS )z+store this object, close it if we opened itc                   s   | j 	 d
S )N)r   r   r   nan_repr   r   r   r[   )r   store
r   r   r[   r   r   r   r   r   r   r   rV   rW   <lambda>  s   zto_hdf.<locals>.<lambda>c                   s   | j 	 d
S )N)r   r   r   r   r   r   r[   r   putr   r   rV   rW   r   %  s   )r   r   r   N)r=   rQ   rZ   HDFStore)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r[   rx   r   rV   r   rW   to_hdf  s     
(r   rzstr | list | Nonezlist[str] | None)	r   r   r   rq   startstopcolumnsiterator	chunksizec
                 K  s  |dvrt d| d|dur,t|dd}t| trN| jsDtd| }d}ntt| } t| tshtd	zt	j
| }W n tt fy   d}Y n0 |std
|  dt| f||d|
}d}zt|du r| }t|dkrt d|d }|dd D ]}t||st dq|j}|j|||||||	|dW S  t ttfy   t| tstt |  W d   n1 s0    Y   Y n0 dS )a"	  
    Read from the store, close it if we opened it.

    Retrieve pandas object stored in file, optionally based on where
    criteria.

    .. warning::

       Pandas uses PyTables for reading and writing HDF5 files, which allows
       serializing object-dtype data with pickle when using the "fixed" format.
       Loading pickled data received from untrusted sources can be unsafe.

       See: https://docs.python.org/3/library/pickle.html for more.

    Parameters
    ----------
    path_or_buf : str, path object, pandas.HDFStore
        Any valid string path is acceptable. Only supports the local file system,
        remote URLs and file-like objects are not supported.

        If you want to pass in a path object, pandas accepts any
        ``os.PathLike``.

        Alternatively, pandas accepts an open :class:`pandas.HDFStore` object.

    key : object, optional
        The group identifier in the store. Can be omitted if the HDF file
        contains a single pandas object.
    mode : {'r', 'r+', 'a'}, default 'r'
        Mode to use when opening the file. Ignored if path_or_buf is a
        :class:`pandas.HDFStore`. Default is 'r'.
    errors : str, default 'strict'
        Specifies how encoding and decoding errors are to be handled.
        See the errors argument for :func:`open` for a full list
        of options.
    where : list, optional
        A list of Term (or convertible) objects.
    start : int, optional
        Row number to start selection.
    stop  : int, optional
        Row number to stop selection.
    columns : list, optional
        A list of columns names to return.
    iterator : bool, optional
        Return an iterator object.
    chunksize : int, optional
        Number of rows to include in an iteration when using an iterator.
    **kwargs
        Additional keyword arguments passed to HDFStore.

    Returns
    -------
    object
        The selected object. Return type depends on the object stored.

    See Also
    --------
    DataFrame.to_hdf : Write a HDF file from a DataFrame.
    HDFStore : Low-level access to HDF files.

    Examples
    --------
    >>> df = pd.DataFrame([[1, 1.0, 'a']], columns=['x', 'y', 'z'])  # doctest: +SKIP
    >>> df.to_hdf('./store.h5', 'data')  # doctest: +SKIP
    >>> reread = pd.read_hdf('./store.h5')  # doctest: +SKIP
    )r   r+r   zmode zG is not allowed while performing a read. Allowed modes are r, r+ and a.Nrg   re   z&The HDFStore must be open for reading.Fz5Support for generic buffers has not been implemented.zFile z does not exist)r   r   Tr   z]Dataset(s) incompatible with Pandas data types, not table, or no datasets found in HDF5 file.z?key must be provided when HDF5 file contains multiple datasets.)rq   r   r   r   r   r   
auto_close)
ValueErrorrr   rQ   r   is_openOSErrorr=   rZ   NotImplementedErrorospathexists	TypeErrorFileNotFoundErrorgroupsrp   _is_metadata_of_v_pathnameselectLookupErrorr   r   close)r   r   r   r   rq   r   r   r   r   r   kwargsr   r   r   r   Zcandidate_only_groupZgroup_to_checkrV   rV   rW   read_hdf<  sj    O







(r   rF   )groupparent_groupr\   c                 C  sF   | j |j krdS | }|j dkrB|j}||kr:|jdkr:dS |j}qdS )zDCheck if a given group is a metadata group for a given parent_group.Frg   metaT)Z_v_depthZ	_v_parent_v_name)r   r   currentparentrV   rV   rW   r     s    
r   c                   @  s6  e Zd ZU dZded< ded< ddd	d
ddddZddddZedd ZeddddZ	ddddZ
dddddZdddddZdddd Zdd
dd!d"Zd#dd$d%Zddd&d'Zd(dd)d*Zd+d,d-dd.d/d0Zddd2d3d4d5Zd6dd7d8Zd9dd:d;Zdddd<d=d>Zddd?d@Zed
ddAdBZdd
ddCdDdEZdddFdGZddd
d	d
dHdIdJZddd	d	dKdLdMZdddd	d	dNdOdPZdd
d	d
dQdRdSZdddVd
d
d	dWdXdd
d
ddYdZd[Zddddd\d]Z dddVd^d
d	dWd	d_dXddd`dadbZ!ddcd
ddddedfZ"ddd	dgddhdidjZ#dkddldmZ$dddodpdqdrZ%ddsddtduZ&ddvddwdxZ'ddd
d	d
d
d dzd{d|Z(ddd}d~Z)ddddZ*dddddZ+dddddvdddZ,dddVd^d
d	dWd	d
dd
ddddZ-ddddZ.dd
ddddZ/dddddZ0dS )r   aS	  
    Dict-like IO interface for storing pandas objects in PyTables.

    Either Fixed or Table format.

    .. warning::

       Pandas uses PyTables for reading and writing HDF5 files, which allows
       serializing object-dtype data with pickle when using the "fixed" format.
       Loading pickled data received from untrusted sources can be unsafe.

       See: https://docs.python.org/3/library/pickle.html for more.

    Parameters
    ----------
    path : str
        File path to HDF5 file.
    mode : {'a', 'w', 'r', 'r+'}, default 'a'

        ``'r'``
            Read-only; no data can be modified.
        ``'w'``
            Write; a new file is created (an existing file with the same
            name would be deleted).
        ``'a'``
            Append; an existing file is opened for reading and writing,
            and if the file does not exist it is created.
        ``'r+'``
            It is similar to ``'a'``, but the file must already exist.
    complevel : int, 0-9, default None
        Specifies a compression level for data.
        A value of 0 or None disables compression.
    complib : {'zlib', 'lzo', 'bzip2', 'blosc'}, default 'zlib'
        Specifies the compression library to be used.
        These additional compressors for Blosc are supported
        (default if no compressor specified: 'blosc:blosclz'):
        {'blosc:blosclz', 'blosc:lz4', 'blosc:lz4hc', 'blosc:snappy',
         'blosc:zlib', 'blosc:zstd'}.
        Specifying a compression library which is not available issues
        a ValueError.
    fletcher32 : bool, default False
        If applying compression use the fletcher32 checksum.
    **kwargs
        These parameters will be passed to the PyTables open_file method.

    Examples
    --------
    >>> bar = pd.DataFrame(np.random.randn(10, 4))
    >>> store = pd.HDFStore('test.h5')
    >>> store['foo'] = bar   # write to HDF5
    >>> bar = store['foo']   # retrieve
    >>> store.close()

    **Create or load HDF5 file in-memory**

    When passing the `driver` option to the PyTables open_file method through
    **kwargs, the HDF5 file is loaded or created in-memory and will only be
    written when closed:

    >>> bar = pd.DataFrame(np.random.randn(10, 4))
    >>> store = pd.HDFStore('test.h5', driver='H5FD_CORE')
    >>> store['foo'] = bar
    >>> store.close()   # only now, data is written to disk
    zFile | None_handlerZ   _moder   NFr   r   r   )r   r   
fletcher32r\   c                 K  s   d|v rt dtd}|d ur@||jjvr@t d|jj d|d u rX|d urX|jj}t|| _|d u rnd}|| _d | _|r|nd| _	|| _
|| _d | _| jf d|i| d S )	Nr   z-format is not a defined argument for HDFStorer   zcomplib only supports z compression.r   r   r   )r   r   filtersZall_complibsZdefault_complibr=   _pathr   r   
_complevel_complib_fletcher32_filtersopen)selfr   r   r   r   r   r   r   rV   rV   rW   __init__*  s&    	
zHDFStore.__init__r\   c                 C  s   | j S r]   r   r   rV   rV   rW   
__fspath__K  s    zHDFStore.__fspath__c                 C  s   |    | jdusJ | jjS )zreturn the root nodeN)_check_if_openr   rootr   rV   rV   rW   r   N  s    zHDFStore.rootc                 C  s   | j S r]   r   r   rV   rV   rW   filenameU  s    zHDFStore.filenamer   c                 C  s
   |  |S r]   )getr   r   rV   rV   rW   __getitem__Y  s    zHDFStore.__getitem__r   r\   c                 C  s   |  || d S r]   r   )r   r   r   rV   rV   rW   __setitem__\  s    zHDFStore.__setitem__c                 C  s
   |  |S r]   )remover   rV   rV   rW   __delitem___  s    zHDFStore.__delitem__ra   c              	   C  sD   z|  |W S  ttfy"   Y n0 tdt| j d| ddS )z$allow attribute access to get stores'z' object has no attribute 'N)r   KeyErrorr   r   type__name__)r   rb   rV   rV   rW   __getattr__b  s    zHDFStore.__getattr__c                 C  s4   |  |}|dur0|j}|||dd fv r0dS dS )zx
        check for existence of this key
        can match the exact pathname or the pathnm w/o the leading '/'
        Nrg   TF)get_noder   )r   r   noderb   rV   rV   rW   __contains__l  s    
zHDFStore.__contains__rd   c                 C  s   t |  S r]   )rp   r   r   rV   rV   rW   __len__x  s    zHDFStore.__len__c                 C  s   t | j}t|  d| dS )N
File path: 
)r?   r   r   )r   ZpstrrV   rV   rW   __repr__{  s    
zHDFStore.__repr__rL   c                 C  s   | S r]   rV   r   rV   rV   rW   	__enter__  s    zHDFStore.__enter__ztype[BaseException] | NonezBaseException | NonezTracebackType | None)exc_type	exc_value	tracebackr\   c                 C  s   |    d S r]   )r   )r   r   r   r   rV   rV   rW   __exit__  s    zHDFStore.__exit__pandas	list[str])includer\   c                 C  s^   |dkrdd |   D S |dkrJ| jdus0J dd | jjddd	D S td
| ddS )a  
        Return a list of keys corresponding to objects stored in HDFStore.

        Parameters
        ----------

        include : str, default 'pandas'
                When kind equals 'pandas' return pandas objects.
                When kind equals 'native' return native HDF5 Table objects.

        Returns
        -------
        list
            List of ABSOLUTE path-names (e.g. have the leading '/').

        Raises
        ------
        raises ValueError if kind has an illegal value

        Examples
        --------
        >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df)  # doctest: +SKIP
        >>> store.get('data')  # doctest: +SKIP
        >>> print(store.keys())  # doctest: +SKIP
        ['/data1', '/data2']
        >>> store.close()  # doctest: +SKIP
        r   c                 S  s   g | ]
}|j qS rV   r   ri   nrV   rV   rW   rm         z!HDFStore.keys.<locals>.<listcomp>nativeNc                 S  s   g | ]
}|j qS rV   r   r   rV   rV   rW   rm     s   /Table)	classnamez8`include` should be either 'pandas' or 'native' but is 'r   )r   r   Z
walk_nodesr   )r   r   rV   rV   rW   keys  s    
zHDFStore.keyszIterator[str]c                 C  s   t |  S r]   )iterr   r   rV   rV   rW   __iter__  s    zHDFStore.__iter__zIterator[tuple[str, list]]c                 c  s   |   D ]}|j|fV  qdS )z'
        iterate on key->group
        N)r   r   )r   grV   rV   rW   items  s    zHDFStore.items)r   r\   c                 K  s   t  }| j|krR| jdv r$|dv r$n(|dv rL| jrLtd| j d| j d|| _| jr`|   | jr| jdkrt  j| j| j| j	d| _
tr| jrd	}t||j| j| jfi || _d
S )a9  
        Open the file in the specified mode

        Parameters
        ----------
        mode : {'a', 'w', 'r', 'r+'}, default 'a'
            See HDFStore docstring or tables.open_file for info about modes
        **kwargs
            These parameters will be passed to the PyTables open_file method.
        )r   w)r   r   )r   zRe-opening the file [z] with mode [z] will delete the current file!r   )r   zGCannot open HDF5 file, which is already opened, even in read-only mode.N)r   r   r   r   r   r   r   Filtersr   r   r   r   r   	open_filer   )r   r   r   r   msgrV   rV   rW   r     s*    

zHDFStore.openc                 C  s   | j dur| j   d| _ dS )z0
        Close the PyTables file handle
        N)r   r   r   rV   rV   rW   r     s    

zHDFStore.closec                 C  s   | j du rdS t| j jS )zF
        return a boolean indicating whether the file is open
        NF)r   r   Zisopenr   rV   rV   rW   r     s    
zHDFStore.is_open)fsyncr\   c                 C  sT   | j durP| j   |rPtt  t| j   W d   n1 sF0    Y  dS )a  
        Force all buffered modifications to be written to disk.

        Parameters
        ----------
        fsync : bool (default False)
          call ``os.fsync()`` on the file handle to force writing to disk.

        Notes
        -----
        Without ``fsync=True``, flushing may not guarantee that the OS writes
        to disk. With fsync, the operation will block until the OS claims the
        file has been written; however, other caching layers may still
        interfere.
        N)r   flushr   r   r   r  fileno)r   r  rV   rV   rW   r    s
    


zHDFStore.flushc                 C  sV   t  < | |}|du r*td| d| |W  d   S 1 sH0    Y  dS )a  
        Retrieve pandas object stored in file.

        Parameters
        ----------
        key : str

        Returns
        -------
        object
            Same type as object stored in file.

        Examples
        --------
        >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df)  # doctest: +SKIP
        >>> store.get('data')  # doctest: +SKIP
        >>> store.close()  # doctest: +SKIP
        NNo object named  in the file)r   r   r   _read_groupr   r   r   rV   rV   rW   r     s
    
zHDFStore.get)r   r   r   r   c	                   st   |  |}	|	du r"td| dt|dd}| |	   fdd}
t| |
|j|||||d
}| S )	a6  
        Retrieve pandas object stored in file, optionally based on where criteria.

        .. warning::

           Pandas uses PyTables for reading and writing HDF5 files, which allows
           serializing object-dtype data with pickle when using the "fixed" format.
           Loading pickled data received from untrusted sources can be unsafe.

           See: https://docs.python.org/3/library/pickle.html for more.

        Parameters
        ----------
        key : str
            Object being retrieved from file.
        where : list or None
            List of Term (or convertible) objects, optional.
        start : int or None
            Row number to start selection.
        stop : int, default None
            Row number to stop selection.
        columns : list or None
            A list of columns that if not None, will limit the return columns.
        iterator : bool or False
            Returns an iterator.
        chunksize : int or None
            Number or rows to include in iteration, return an iterator.
        auto_close : bool or False
            Should automatically close the store when finished.

        Returns
        -------
        object
            Retrieved object from file.

        Examples
        --------
        >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df)  # doctest: +SKIP
        >>> store.get('data')  # doctest: +SKIP
        >>> print(store.keys())  # doctest: +SKIP
        ['/data1', '/data2']
        >>> store.select('/data1')  # doctest: +SKIP
           A  B
        0  1  2
        1  3  4
        >>> store.select('/data1', where='columns == A')  # doctest: +SKIP
           A
        0  1
        1  3
        >>> store.close()  # doctest: +SKIP
        Nr  r  rg   re   c                   s   j | || dS )N)r   r   rq   r   read_start_stop_wherer   rU   rV   rW   funcy  s    zHDFStore.select.<locals>.funcrq   nrowsr   r   r   r   r   )r   r   rr   _create_storer
infer_axesTableIteratorr  
get_result)r   r   rq   r   r   r   r   r   r   r   r  itrV   r  rW   r   /  s(    @

zHDFStore.selectr   r   r   c                 C  s8   t |dd}| |}t|ts(td|j|||dS )a  
        return the selection as an Index

        .. warning::

           Pandas uses PyTables for reading and writing HDF5 files, which allows
           serializing object-dtype data with pickle when using the "fixed" format.
           Loading pickled data received from untrusted sources can be unsafe.

           See: https://docs.python.org/3/library/pickle.html for more.


        Parameters
        ----------
        key : str
        where : list of Term (or convertible) objects, optional
        start : integer (defaults to None), row number to start selection
        stop  : integer (defaults to None), row number to stop selection
        rg   re   z&can only read_coordinates with a tablerq   r   r   )rr   
get_storerrQ   r   r   read_coordinates)r   r   rq   r   r   tblrV   rV   rW   select_as_coordinates  s
    

zHDFStore.select_as_coordinates)r   columnr   r   c                 C  s,   |  |}t|tstd|j|||dS )a~  
        return a single column from the table. This is generally only useful to
        select an indexable

        .. warning::

           Pandas uses PyTables for reading and writing HDF5 files, which allows
           serializing object-dtype data with pickle when using the "fixed" format.
           Loading pickled data received from untrusted sources can be unsafe.

           See: https://docs.python.org/3/library/pickle.html for more.

        Parameters
        ----------
        key : str
        column : str
            The column of interest.
        start : int or None, default None
        stop : int or None, default None

        Raises
        ------
        raises KeyError if the column is not found (or key is not a valid
            store)
        raises ValueError if the column can not be extracted individually (it
            is part of a data block)

        z!can only read_column with a tabler  r   r   )r  rQ   r   r   read_column)r   r   r  r   r   r  rV   rV   rW   select_column  s    #

zHDFStore.select_column)r   r   r   c
                   sv  t |dd}t|ttfr.t|dkr.|d }t|trRj|||||||	dS t|ttfshtdt|sxtd|du r|d }fdd	|D 	|}
d}t
|
|fgt|D ]\\}}|du rtd
| d|jstd|j d|du r
|j}q|j|krtdqdd	 D }dd |D    fdd}t|
||||||||	d
}|jddS )a  
        Retrieve pandas objects from multiple tables.

        .. warning::

           Pandas uses PyTables for reading and writing HDF5 files, which allows
           serializing object-dtype data with pickle when using the "fixed" format.
           Loading pickled data received from untrusted sources can be unsafe.

           See: https://docs.python.org/3/library/pickle.html for more.

        Parameters
        ----------
        keys : a list of the tables
        selector : the table to apply the where criteria (defaults to keys[0]
            if not supplied)
        columns : the columns I want back
        start : integer (defaults to None), row number to start selection
        stop  : integer (defaults to None), row number to stop selection
        iterator : bool, return an iterator, default False
        chunksize : nrows to include in iteration, return an iterator
        auto_close : bool, default False
            Should automatically close the store when finished.

        Raises
        ------
        raises KeyError if keys or selector is not found or keys is empty
        raises TypeError if keys is not a list or tuple
        raises ValueError if the tables are not ALL THE SAME DIMENSIONS
        rg   re   r   )r   rq   r   r   r   r   r   r   zkeys must be a list/tuplez keys must have a non-zero lengthNc                   s   g | ]}  |qS rV   )r  ri   kr   rV   rW   rm     r   z/HDFStore.select_as_multiple.<locals>.<listcomp>zInvalid table []zobject [z>] is not a table, and cannot be used in all select as multiplez,all tables must have exactly the same nrows!c                 S  s   g | ]}t |tr|qS rV   )rQ   r   ri   xrV   rV   rW   rm   -  r   c                 S  s   h | ]}|j d  d  qS r   )non_index_axesri   ry   rV   rV   rW   	<setcomp>0  r   z.HDFStore.select_as_multiple.<locals>.<setcomp>c                   s*    fddD }t |dd S )Nc                   s   g | ]}|j  d qS )rq   r   r   r   r	  r)  )r  r  r  r   rV   rW   rm   5  s   z=HDFStore.select_as_multiple.<locals>.func.<locals>.<listcomp>F)axisverify_integrity)r2   _consolidate)r  r  r  Zobjs)r,  r   tblsr  rW   r  2  s    z)HDFStore.select_as_multiple.<locals>.funcr  Tcoordinates)rr   rQ   rn   ro   rp   rZ   r   r   r   r  	itertoolschainzipr   is_tablepathnamer  popr  r  )r   r   rq   selectorr   r   r   r   r   r   rU   r  ry   r#  Z_tblsr  r  rV   )r,  r   r   r/  rW   select_as_multiple  sd    +

 


zHDFStore.select_as_multipleTr~   r   r   r   )r   r   r   r   r   r   r   r   track_timesr   r\   c                 C  sH   |du rt dpd}| |}| j|||||||||	|
||||d dS )a  
        Store object in HDFStore.

        Parameters
        ----------
        key : str
        value : {Series, DataFrame}
        format : 'fixed(f)|table(t)', default is 'fixed'
            Format to use when storing object in HDFStore. Value can be one of:

            ``'fixed'``
                Fixed format.  Fast writing/reading. Not-appendable, nor searchable.
            ``'table'``
                Table format.  Write as a PyTables Table structure which may perform
                worse but allow more flexible operations like searching / selecting
                subsets of the data.
        index : bool, default True
            Write DataFrame index as a column.
        append : bool, default False
            This will force Table format, append the input data to the existing.
        data_columns : list of columns or True, default None
            List of columns to create as data columns, or True to use all columns.
            See `here
            <https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#query-via-data-columns>`__.
        encoding : str, default None
            Provide an encoding for strings.
        track_times : bool, default True
            Parameter is propagated to 'create_table' method of 'PyTables'.
            If set to False it enables to have the same h5 files (same hashes)
            independent on creation time.
        dropna : bool, default False, optional
            Remove missing values.

        Examples
        --------
        >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df)  # doctest: +SKIP
        Nio.hdf.default_formatrv   )r   r   r   r   r   r   r   r   r[   r   r:  r   )r   _validate_format_write_to_group)r   r   r   r   r   r   r   r   r   r   r   r[   r   r:  r   rV   rV   rW   r   M  s&    8
zHDFStore.putc              
   C  s   t |dd}z| |}W n ty.    Y nt ty@    Y nb ty } zJ|dur`td|| |}|dur|jdd W Y d}~dS W Y d}~n
d}~0 0 t	|||r|j
jdd n|jstd|j|||dS dS )	a:  
        Remove pandas object partially by specifying the where condition

        Parameters
        ----------
        key : str
            Node to remove or delete rows from
        where : list of Term (or convertible) objects, optional
        start : integer (defaults to None), row number to start selection
        stop  : integer (defaults to None), row number to stop selection

        Returns
        -------
        number of rows removed (or None if not a Table)

        Raises
        ------
        raises KeyError if key is not a valid store

        rg   re   Nz5trying to remove a node with a non-None where clause!T	recursivez7can only remove with where on objects written as tablesr  )rr   r  r   AssertionError	Exceptionr   r   Z	_f_removecomall_noner   r5  delete)r   r   rq   r   r   rU   errr   rV   rV   rW   r     s2    
$zHDFStore.removezbool | list[str]r   )r   r   r   r   r   r   r   r   r   r   r\   c                 C  sl   |	durt d|du r td}|du r4tdp2d}| |}| j|||||||||
|||||||d dS )a|  
        Append to Table in file.

        Node must already exist and be Table format.

        Parameters
        ----------
        key : str
        value : {Series, DataFrame}
        format : 'table' is the default
            Format to use when storing object in HDFStore.  Value can be one of:

            ``'table'``
                Table format. Write as a PyTables Table structure which may perform
                worse but allow more flexible operations like searching / selecting
                subsets of the data.
        index : bool, default True
            Write DataFrame index as a column.
        append       : bool, default True
            Append the input data to the existing.
        data_columns : list of columns, or True, default None
            List of columns to create as indexed data columns for on-disk
            queries, or True to use all columns. By default only the axes
            of the object are indexed. See `here
            <https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#query-via-data-columns>`__.
        min_itemsize : dict of columns that specify minimum str sizes
        nan_rep      : str to use as str nan representation
        chunksize    : size to chunk the writing
        expectedrows : expected TOTAL row size of this table
        encoding     : default None, provide an encoding for str
        dropna : bool, default False, optional
            Do not write an ALL nan row to the store settable
            by the option 'io.hdf.dropna_table'.

        Notes
        -----
        Does *not* check if data being appended overlaps with existing
        data in the table, so be careful

        Examples
        --------
        >>> df1 = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df1, format='table')  # doctest: +SKIP
        >>> df2 = pd.DataFrame([[5, 6], [7, 8]], columns=['A', 'B'])
        >>> store.append('data', df2)  # doctest: +SKIP
        >>> store.close()  # doctest: +SKIP
           A  B
        0  1  2
        1  3  4
        0  5  6
        1  7  8
        Nz>columns is not a supported keyword in append, try data_columnszio.hdf.dropna_tabler;  rw   )r   axesr   r   r   r   r   r   r   expectedrowsr   r   r[   r   )r   r   r<  r=  )r   r   r   r   rF  r   r   r   r   r   r   r   r   rG  r   r   r[   r   rV   rV   rW   r     s6    I
zHDFStore.appenddict)dr   r\   c                   s  |durt dt|ts"td||vr2tdttttjtt	t
  }d}	g }
| D ]0\}  du r|	durtd|}	qh|
  qh|	durֈj| }|t|
}t||}||||	< |du r|| }|r*fdd| D }t|}|D ]}||}qj| |dd}| D ]h\} ||krT|nd}j |d	}|dur fd
d| D nd}| j||f||d| q>dS )a  
        Append to multiple tables

        Parameters
        ----------
        d : a dict of table_name to table_columns, None is acceptable as the
            values of one node (this will get all the remaining columns)
        value : a pandas object
        selector : a string that designates the indexable table; all of its
            columns will be designed as data_columns, unless data_columns is
            passed, in which case these are used
        data_columns : list of columns to create as data columns, or True to
            use all columns
        dropna : if evaluates to True, drop rows from all tables if any single
                 row in each table has all NaN. Default False.

        Notes
        -----
        axes parameter is currently not accepted

        Nztaxes is currently not accepted as a parameter to append_to_multiple; you can create the tables independently insteadzQappend_to_multiple must have a dictionary specified as the way to split the valuez=append_to_multiple requires a selector that is in passed dictz<append_to_multiple can only have one value in d that is Nonec                 3  s    | ]} | j d djV  qdS )all)howN)r   r   )ri   cols)r   rV   rW   	<genexpr>  r   z.HDFStore.append_to_multiple.<locals>.<genexpr>r   r,  c                   s   i | ]\}}| v r||qS rV   rV   ri   r   r   )vrV   rW   
<dictcomp>  r   z/HDFStore.append_to_multiple.<locals>.<dictcomp>)r   r   )r   rQ   rH  r   nextr   setrangendim	_AXES_MAPr   r   extendrF  
differencer,   sortedget_indexertakevaluesintersectionlocr7  reindexr   )r   rI  r   r8  r   rF  r   r   r,  Z
remain_keyZremain_valuesr#  orderedZorddZidxsZvalid_indexr   r   dcvalfilteredrV   )rP  r   rW   append_to_multiple8  sZ    
&

zHDFStore.append_to_multiplerY   )r   optlevelkindr\   c                 C  sB   t   | |}|du rdS t|ts.td|j|||d dS )a  
        Create a pytables index on the table.

        Parameters
        ----------
        key : str
        columns : None, bool, or listlike[str]
            Indicate which columns to create an index on.

            * False : Do not create any indexes.
            * True : Create indexes on all columns.
            * None : Create indexes on all columns.
            * listlike : Create indexes on the given columns.

        optlevel : int or None, default None
            Optimization level, if None, pytables defaults to 6.
        kind : str or None, default None
            Kind of index, if None, pytables defaults to "medium".

        Raises
        ------
        TypeError: raises if the node is not a table
        Nz1cannot create table index on a Fixed format store)r   re  rf  )r   r  rQ   r   r   create_index)r   r   r   re  rf  rU   rV   rV   rW   create_table_index  s    

zHDFStore.create_table_indexrn   c                 C  s<   t   |   | jdusJ tdus(J dd | j D S )a  
        Return a list of all the top-level nodes.

        Each node returned is not a pandas storage object.

        Returns
        -------
        list
            List of objects.

        Examples
        --------
        >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df)  # doctest: +SKIP
        >>> print(store.groups())  # doctest: +SKIP
        >>> store.close()  # doctest: +SKIP
        [/data (Group) ''
          children := ['axis0' (Array), 'axis1' (Array), 'block0_values' (Array),
          'block0_items' (Array)]]
        Nc                 S  sP   g | ]H}t |tjjst|jd dsHt|ddsHt |tjjr|jdkr|qS )pandas_typeNrw   )	rQ   r   linkLinkgetattr_v_attrsrw   r   r   )ri   r   rV   rV   rW   rm     s   z#HDFStore.groups.<locals>.<listcomp>)r   r   r   r   walk_groupsr   rV   rV   rW   r     s    zHDFStore.groupsr   z*Iterator[tuple[str, list[str], list[str]]])rq   r\   c                 c  s   t   |   | jdusJ tdus(J | j|D ]}t|jdddurLq4g }g }|j D ]B}t|jdd}|du rt	|tj
jr||j q^||j q^|jd||fV  q4dS )a  
        Walk the pytables group hierarchy for pandas objects.

        This generator will yield the group path, subgroups and pandas object
        names for each group.

        Any non-pandas PyTables objects that are not a group will be ignored.

        The `where` group itself is listed first (preorder), then each of its
        child groups (following an alphanumerical order) is also traversed,
        following the same procedure.

        Parameters
        ----------
        where : str, default "/"
            Group where to start walking.

        Yields
        ------
        path : str
            Full path to a group (without trailing '/').
        groups : list
            Names (strings) of the groups contained in `path`.
        leaves : list
            Names (strings) of the pandas objects contained in `path`.

        Examples
        --------
        >>> df1 = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df1, format='table')  # doctest: +SKIP
        >>> df2 = pd.DataFrame([[5, 6], [7, 8]], columns=['A', 'B'])
        >>> store.append('data', df2)  # doctest: +SKIP
        >>> store.close()  # doctest: +SKIP
        >>> for group in store.walk():  # doctest: +SKIP
        ...     print(group)  # doctest: +SKIP
        >>> store.close()  # doctest: +SKIP
        Nri  r   )r   r   r   r   rn  rl  rm  Z_v_childrenr\  rQ   r   Groupr   r   r   rstrip)r   rq   r   r   leaveschildri  rV   rV   rW   walk  s     'zHDFStore.walkzNode | Nonec                 C  s~   |    |dsd| }| jdus(J tdus4J z| j| j|}W n tjjy`   Y dS 0 t|tj	szJ t
||S )z9return the node with the key or None if it does not existr   N)r   
startswithr   r   r   r   
exceptionsZNoSuchNodeErrorrQ   rF   r   )r   r   r   rV   rV   rW   r   $  s    
zHDFStore.get_nodeGenericFixed | Tablec                 C  s8   |  |}|du r"td| d| |}|  |S )z<return the storer object for a key, raise if not in the fileNr  r  )r   r   r  r  )r   r   r   rU   rV   rV   rW   r  4  s    

zHDFStore.get_storerr   )r   propindexesr   r   	overwriter\   c	              	   C  s   t |||||d}	|du r&t|  }t|ttfs:|g}|D ]}
| |
}|dur>|
|	v rj|rj|	|
 | |
}t|trd}|rdd |j	D }|	j
|
||t|dd|jd q>|	j|
||jd q>|	S )	a;  
        Copy the existing store to a new file, updating in place.

        Parameters
        ----------
        propindexes : bool, default True
            Restore indexes in copied file.
        keys : list, optional
            List of keys to include in the copy (defaults to all).
        overwrite : bool, default True
            Whether to overwrite (remove and replace) existing nodes in the new store.
        mode, complib, complevel, fletcher32 same as in HDFStore.__init__

        Returns
        -------
        open file handle of the new store
        )r   r   r   r   NFc                 S  s   g | ]}|j r|jqS rV   )
is_indexedrb   ri   r   rV   rV   rW   rm   l  r   z!HDFStore.copy.<locals>.<listcomp>r   )r   r   r[   r_   )r   rn   r   rQ   ro   r  r   r   r   rF  r   rl  r[   r   )r   r   r   rw  r   r   r   r   rx  Z	new_storer#  rU   datar   rV   rV   rW   copy>  s6    





zHDFStore.copyc           
      C  s
  t | j}t|  d| d}| jrt|  }t|rg }g }|D ]}z<| |}|dur|t |j	pj| |t |p|d W qD t
y    Y qD ty } z0|| t |}	|d|	 d W Y d}~qDd}~0 0 qD|td||7 }n|d7 }n|d	7 }|S )
a  
        Print detailed information on the store.

        Returns
        -------
        str

        Examples
        --------
        >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df)  # doctest: +SKIP
        >>> print(store.info())  # doctest: +SKIP
        >>> store.close()  # doctest: +SKIP
        <class 'pandas.io.pytables.HDFStore'>
        File path: store.h5
        /data    frame    (shape->[2,2])
        r   r   Nzinvalid_HDFStore nodez[invalid_HDFStore node: r$     EmptyzFile is CLOSED)r?   r   r   r   rY  r   rp   r  r   r6  r@  rA  r>   )
r   r   outputZlkeysr   r\  r#  rU   detailZdstrrV   rV   rW   infoy  s.    


*
zHDFStore.infoc                 C  s   | j st| j dd S )Nz file is not open!)r   r   r   r   rV   rV   rW   r     s    zHDFStore._check_if_open)r   r\   c              
   C  sL   zt |  }W n6 tyF } ztd| d|W Y d}~n
d}~0 0 |S )zvalidate / deprecate formatsz#invalid HDFStore format specified [r$  N)_FORMAT_MAPlowerr   r   )r   r   rE  rV   rV   rW   r<    s
    (zHDFStore._validate_formatrP   zDataFrame | Series | None)r   r[   r   r\   c              
   C  s>  |durt |ttfstdtt|jdd}tt|jdd}|du r|du rt  tdusdJ t|dds~t |tj	j
rd}d}qtdn$t |trd	}nd
}|dkr|d7 }d|vr.ttd}z|| }	W nF ty }
 z,td| dt| d| |
W Y d}
~
n
d}
~
0 0 |	| |||dS |du r|dur|dkrt|dd}|dur|jdkrtd}n|jdkrd}nB|dkrt|dd}|dur|jdkrd}n|jdkrd}ttttttd}z|| }	W nF ty, }
 z,td| dt| d| |
W Y d}
~
n
d}
~
0 0 |	| |||dS )z"return a suitable class to operateNz(value must be None, Series, or DataFrameri  
table_typerw   frame_tablegeneric_tablezKcannot create a storer if the object is not existing nor a value are passedseriesframe_table)r  r  z=cannot properly create the storer for: [_STORER_MAP] [group->,value->z	,format->r[   r   series_tabler   rg   appendable_seriesappendable_multiseriesappendable_frameappendable_multiframe)r  r  r  r  r  wormz<cannot properly create the storer for: [_TABLE_MAP] [group->)rQ   r0   r*   r   rX   rl  rm  r   r   rw   r   SeriesFixed
FrameFixedr   r   nlevelsGenericTableAppendableSeriesTableAppendableMultiSeriesTableAppendableFrameTableAppendableMultiFrameTable	WORMTable)r   r   r   r   r[   r   ptttZ_STORER_MAPclsrE  r   Z
_TABLE_MAPrV   rV   rW   r    s    








zHDFStore._create_storer)r   r   r   r   r   r   r   r   r   r:  r\   c                 C  s   t |dd r|dks|rd S | ||}| j|||||d}|rr|jrZ|jrb|dkrb|jrbtd|jsz|  n|  |js|rtd|j||||||	|
||||||d t|t	r|r|j
|d d S )	Nemptyrw   r  rv   zCan only append to Tablesz0Compression not supported on Fixed format stores)objrF  r   r   r   r   r   r   rG  r   r   r   r:  )r   )rl  _identify_groupr  r5  	is_existsr   set_object_infowriterQ   r   rg  )r   r   r   r   rF  r   r   r   r   r   r   r   rG  r   r   r   r[   r   r:  r   rU   rV   rV   rW   r=    s:    

zHDFStore._write_to_grouprF   r   c                 C  s   |  |}|  | S r]   )r  r  r
  )r   r   rU   rV   rV   rW   r  U  s    
zHDFStore._read_group)r   r   r\   c                 C  sN   |  |}| jdusJ |dur8|s8| jj|dd d}|du rJ| |}|S )z@Identify HDF5 group based on key, delete/create group if needed.NTr>  )r   r   remove_node_create_nodes_and_group)r   r   r   r   rV   rV   rW   r  Z  s    

zHDFStore._identify_groupc                 C  sv   | j dusJ |d}d}|D ]P}t|s.q |}|dsD|d7 }||7 }| |}|du rl| j ||}|}q |S )z,Create nodes from key and return group name.Nr   )r   splitrp   endswithr   Zcreate_group)r   r   pathsr   pnew_pathr   rV   rV   rW   r  l  s    


z HDFStore._create_nodes_and_group)r   NNF)r   )r   )F)NNNNFNF)NNN)NN)NNNNNFNF)NTFNNNNNNr~   TF)NNN)NNTTNNNNNNNNNNr~   )NNF)NNN)r   )r   TNNNFT)NNrP   r~   )NTFNNNNNNFNNNr~   T)1r   
__module____qualname____doc____annotations__r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r  r!  r9  r   r   r   rd  rh  r   rs  r   r  r|  r  r   r<  r  r=  r  r  r  rV   rV   rV   rW   r     s  
A    !

*-        `   $  +        }            $L=               $k   d   ('<       ;5    `               $>r   c                   @  sp   e Zd ZU dZded< ded< ded< dddd
dd
ddddZddddZddddZdd
dddZdS )r  aa  
    Define the iteration interface on a table

    Parameters
    ----------
    store : HDFStore
    s     : the referred storer
    func  : the function to execute the query
    where : the where of the query
    nrows : the rows to iterate on
    start : the passed start value (default is None)
    stop  : the passed stop value (default is None)
    iterator : bool, default False
        Whether to use the default iterator.
    chunksize : the passed chunking value (default is 100000)
    auto_close : bool, default False
        Whether to automatically close the store at the end of iteration.
    r   r   r   r   rv  rU   NFr   r   )r   rU   r   r   r   r\   c                 C  s   || _ || _|| _|| _| jjrN|d u r,d}|d u r8d}|d u rD|}t||}|| _|| _|| _d | _	|sr|	d ur|	d u r~d}	t
|	| _nd | _|
| _d S )Nr   順 )r   rU   r  rq   r5  minr  r   r   r1  rd   r   r   )r   r   rU   r  rq   r  r   r   r   r   r   rV   rV   rW   r     s,    
zTableIterator.__init__rA   r   c                 c  sv   | j }| jd u rtd|| jk rjt|| j | j}| d d | j|| }|}|d u st|sbq|V  q|   d S )Nz*Cannot iterate until get_result is called.)	r   r1  r   r   r  r   r  rp   r   )r   r   r   r   rV   rV   rW   r     s    

zTableIterator.__iter__c                 C  s   | j r| j  d S r]   )r   r   r   r   rV   rV   rW   r     s    zTableIterator.closer0  c                 C  s   | j d ur4t| jtstd| jj| jd| _| S |rft| jtsLtd| jj| j| j| j	d}n| j}| 
| j| j	|}|   |S )Nz0can only use an iterator or chunksize on a table)rq   z$can only read_coordinates on a tabler  )r   rQ   rU   r   r   r  rq   r1  r   r   r  r   )r   r1  rq   resultsrV   rV   rW   r    s    
zTableIterator.get_result)NNFNF)F)	r   r  r  r  r  r   r   r   r  rV   rV   rV   rW   r    s   
	     *r  c                   @  s  e Zd ZU dZdZded< dZded< g dZdKdd	d
dddZe	ddddZ
e	ddddZdd
dddZddddZdddddZddddZe	dddd Zd!ddd"d#d$d%Zd&d' Ze	d(d) Ze	d*d+ Ze	d,d- Ze	d.d/ Zd0dd1d2ZdLd
dd3d4Zd
dd5d6Zd7dd
d8d9d:ZdMd;d<Zdd
d=d>d?Zd
dd@dAZd
ddBdCZd
ddDdEZd7d
dFdGdHZ d7d
dFdIdJZ!dS )NIndexCola  
    an index column description class

    Parameters
    ----------
    axis   : axis which I reference
    values : the ndarray like converted values
    kind   : a string description of this type
    typ    : the pytables type
    pos    : the position in the pytables

    Tr   is_an_indexableis_data_indexable)freqtz
index_nameNrZ   rY   r   )rb   cnamer\   c                 C  s   t |tstd|| _|| _|| _|| _|p0|| _|| _|| _	|| _
|	| _|
| _|| _|| _|| _|| _|d ur|| | t | jtsJ t | jtsJ d S )Nz`name` must be a str.)rQ   rZ   r   r\  rf  typrb   r  r,  posr  r  r  r`  rw   r   metadataset_pos)r   rb   r\  rf  r  r  r,  r  r  r  r  r`  rw   r   r  rV   rV   rW   r     s(    


zIndexCol.__init__rd   r   c                 C  s   | j jS r]   )r  itemsizer   rV   rV   rW   r  /  s    zIndexCol.itemsizec                 C  s   | j  dS )N_kindra   r   rV   rV   rW   	kind_attr4  s    zIndexCol.kind_attr)r  r\   c                 C  s$   || _ |dur | jdur || j_dS )z,set the position of this column in the TableN)r  r  Z_v_pos)r   r  rV   rV   rW   r  8  s    zIndexCol.set_posc                 C  s@   t tt| j| j| j| j| jf}ddd t	g d|D S )N,c                 S  s   g | ]\}}| d | qS z->rV   rO  rV   rV   rW   rm   C  s   z%IndexCol.__repr__.<locals>.<listcomp>)rb   r  r,  r  rf  )
ro   mapr?   rb   r  r,  r  rf  joinr4  r   temprV   rV   rW   r   >  s    zIndexCol.__repr__objectotherr\   c                   s   t  fdddD S )compare 2 col itemsc                 3  s&   | ]}t |d t  |d kV  qd S r]   rl  rz  r  r   rV   rW   rM  K  s   z"IndexCol.__eq__.<locals>.<genexpr>)rb   r  r,  r  rJ  r   r  rV   r  rW   __eq__I  s    zIndexCol.__eq__c                 C  s   |  | S r]   )r  r  rV   rV   rW   __ne__P  s    zIndexCol.__ne__c                 C  s"   t | jdsdS t| jj| jjS )z%return whether I am an indexed columnrL  F)hasattrrw   rl  rL  r  ry  r   rV   rV   rW   ry  S  s    zIndexCol.is_indexed
np.ndarrayz3tuple[np.ndarray, np.ndarray] | tuple[Index, Index]r\  r[   r   r\   c           
      C  s  t |tjsJ t||jjdur2|| j  }t| j	}t
||||}i }t| j|d< | jdurtt| j|d< t}t|jdst |jtrt}n|jdkrd|v rdd }z||fi |}W n2 ty   d|v rd|d< ||fi |}Y n0 t|| j}	|	|	fS )zV
        Convert the data from this selection to the appropriate pandas type.
        Nrb   r  Mi8c                 [  s    t j| |dd d|d S )Nr  )r  rb   )r.   Zfrom_ordinalsr   Z_rename)r&  kwdsrV   rV   rW   r   {  s   z"IndexCol.convert.<locals>.<lambda>)rQ   rR   ndarrayr   dtypefieldsr  r|  rX   rf  _maybe_convertr  r  r,   r   is_np_dtyper&   r+   r   _set_tzr  )
r   r\  r   r[   r   val_kindr   factoryZnew_pd_indexZfinal_pd_indexrV   rV   rW   convert[  s0    

zIndexCol.convertc                 C  s   | j S )zreturn the valuesr\  r   rV   rV   rW   	take_data  s    zIndexCol.take_datac                 C  s   | j jS r]   )rw   rm  r   rV   rV   rW   attrs  s    zIndexCol.attrsc                 C  s   | j jS r]   rw   descriptionr   rV   rV   rW   r    s    zIndexCol.descriptionc                 C  s   t | j| jdS )z!return my current col descriptionN)rl  r  r  r   rV   rV   rW   col  s    zIndexCol.colc                 C  s   | j S zreturn my cython valuesr  r   rV   rV   rW   cvalues  s    zIndexCol.cvaluesrA   c                 C  s
   t | jS r]   )r   r\  r   rV   rV   rW   r     s    zIndexCol.__iter__c                 C  sP   t | jdkrLt|tr$|| j}|durL| jj|k rLt j	|| j
d| _dS )z
        maybe set a string col itemsize:
            min_itemsize can be an integer or a dict with this columns name
            with an integer size
        stringN)r  r  )rX   rf  rQ   rH  r   rb   r  r  r   	StringColr  )r   r   rV   rV   rW   maybe_set_size  s
    
zIndexCol.maybe_set_sizec                 C  s   d S r]   rV   r   rV   rV   rW   validate_names  s    zIndexCol.validate_namesAppendableTable)handlerr   r\   c                 C  s:   |j | _ |   | | | | | | |   d S r]   )rw   validate_colvalidate_attrvalidate_metadatawrite_metadataset_attr)r   r  r   rV   rV   rW   validate_and_set  s    


zIndexCol.validate_and_setc                 C  s^   t | jdkrZ| j}|durZ|du r*| j}|j|k rTtd| d| j d|j d|jS dS )z:validate this column: return the compared against itemsizer  Nz#Trying to store a string with len [z] in [z)] column but
this column has a limit of [zC]!
Consider using min_itemsize to preset the sizes on these columns)rX   rf  r  r  r   r  )r   r  crV   rV   rW   r    s    
zIndexCol.validate_col)r   r\   c                 C  sB   |r>t | j| jd }|d ur>|| jkr>td| d| j dd S )Nzincompatible kind in col [ - r$  )rl  r  r  rf  r   )r   r   Zexisting_kindrV   rV   rW   r    s    zIndexCol.validate_attrc                 C  s   | j D ]}t| |d}|| ji }||}||v r|dur||kr|dv rt|||f }tj|tt	 d d||< t
| |d qtd| j d| d| d| d	q|dus|dur|||< qdS )	z
        set/update the info for this indexable with the key/value
        if there is a conflict raise/warn as needed
        N)r  r  
stacklevelzinvalid info for [z] for [z], existing_value [z] conflicts with new value [r$  )_info_fieldsrl  
setdefaultrb   r   rt   warningswarnr   r   setattrr   )r   r  r   r   idxZexisting_valuewsrV   rV   rW   update_info  s*    

zIndexCol.update_infoc                 C  s$   | | j}|dur | j| dS )z!set my state from the passed infoN)r   rb   __dict__update)r   r  r  rV   rV   rW   set_info  s    zIndexCol.set_infoc                 C  s   t | j| j| j dS )zset the kind for this columnN)r  r  r  rf  r   rV   rV   rW   r    s    zIndexCol.set_attr)r  r\   c                 C  sH   | j dkrD| j}|| j}|durD|durDt||dddsDtddS )z:validate that kind=category does not change the categoriescategoryNTZ
strict_nanZdtype_equalzEcannot append a categorical with different categories to the existing)r   r  read_metadatar  r)   r   )r   r  Znew_metadataZcur_metadatarV   rV   rW   r  	  s    
zIndexCol.validate_metadatac                 C  s   | j dur|| j| j  dS )zset the meta dataN)r  r  r  )r   r  rV   rV   rW   r  	  s    
zIndexCol.write_metadata)NNNNNNNNNNNNN)N)N)"r   r  r  r  r  r  r  r  r   r  r  r  r  r   r  r  ry  r  r  r  r  r  r  r   r  r  r  r  r  r   r  r  r  r  rV   rV   rV   rW   r    sb   
             +2




	r  c                   @  sD   e Zd ZdZeddddZddddd	d
dZddddZdS )GenericIndexColz:an index which is not represented in the data of the tabler   r   c                 C  s   dS NFrV   r   rV   rV   rW   ry  	  s    zGenericIndexCol.is_indexedr  rZ   ztuple[Index, Index]r  c                 C  s,   t |tjsJ t|tt|}||fS )z
        Convert the data from this selection to the appropriate pandas type.

        Parameters
        ----------
        values : np.ndarray
        nan_rep : str
        encoding : str
        errors : str
        )rQ   rR   r  r   r/   rp   )r   r\  r   r[   r   r   rV   rV   rW   r  !	  s    zGenericIndexCol.convertr   c                 C  s   d S r]   rV   r   rV   rV   rW   r  3	  s    zGenericIndexCol.set_attrN)r   r  r  r  r  ry  r  r  rV   rV   rV   rW   r  	  s
   r  c                      s>  e Zd ZdZdZdZddgZd;dddd	d
 fddZeddddZ	eddddZ
ddddZdddddZdd	dddZdd Zeddd d!d"Zed#d$ Zedd%d&d'd(Zeddd&d)d*Zed+d, Zed-d. Zed/d0 Zed1d2 Zd	dd3d4Zd5ddd6d7d8Zd	dd9d:Z  ZS )<DataCola3  
    a data holding column, by definition this is not indexable

    Parameters
    ----------
    data   : the actual data
    cname  : the column name in the table to hold the data (typically
                values)
    meta   : a string description of the metadata
    metadata : the actual metadata
    Fr  r`  NrZ   rY   zDtypeArg | Noner   )rb   r  r  r\   c                   s2   t  j|||||||||	|
|d || _|| _d S )N)rb   r\  rf  r  r  r  r  r`  rw   r   r  )superr   r  r{  )r   rb   r\  rf  r  r  r  r  r`  rw   r   r  r  r{  	__class__rV   rW   r   H	  s    zDataCol.__init__r   c                 C  s   | j  dS )N_dtypera   r   rV   rV   rW   
dtype_attrh	  s    zDataCol.dtype_attrc                 C  s   | j  dS )N_metara   r   rV   rV   rW   	meta_attrl	  s    zDataCol.meta_attrc                 C  s@   t tt| j| j| j| j| jf}ddd t	g d|D S )Nr  c                 S  s   g | ]\}}| d | qS r  rV   rO  rV   rV   rW   rm   w	  s   z$DataCol.__repr__.<locals>.<listcomp>)rb   r  r  rf  shape)
ro   r  r?   rb   r  r  rf  r  r  r4  r  rV   rV   rW   r   p	  s    zDataCol.__repr__r  r   r  c                   s   t  fdddD S )r  c                 3  s&   | ]}t |d t  |d kV  qd S r]   r  rz  r  rV   rW   rM  	  s   z!DataCol.__eq__.<locals>.<genexpr>)rb   r  r  r  r  r  rV   r  rW   r  }	  s    zDataCol.__eq__rH   )r{  r\   c                 C  s@   |d usJ | j d u sJ t|\}}|| _|| _ t|| _d S r]   )r  _get_data_and_dtype_namer{  _dtype_to_kindrf  )r   r{  
dtype_namerV   rV   rW   set_data	  s    zDataCol.set_datac                 C  s   | j S )zreturn the datar{  r   rV   rV   rW   r  	  s    zDataCol.take_datarD   )r\  r\   c                 C  s   |j }|j}|j}|jdkr&d|jf}t|trJ|j}| j||j j	d}n~t
|ds`t|trl| |}n\t
|dr| |}nDt|rt j||d d}n&t|r| ||}n| j||j	d}|S )zW
        Get an appropriately typed and shaped pytables.Col object for values.
        rg   rf  r  mr   r  r  )r  r  r  rU  sizerQ   r4   codesget_atom_datarb   r   r  r&   get_atom_datetime64get_atom_timedelta64r!   r   Z
ComplexColr#   get_atom_string)r  r\  r  r  r  r  atomrV   rV   rW   	_get_atom	  s$    


zDataCol._get_atomc                 C  s   t  j||d dS )Nr   r  r   r  r  r  r  rV   rV   rW   r  	  s    zDataCol.get_atom_stringz	type[Col]rf  r\   c                 C  sR   | dr$|dd }d| d}n"| dr4d}n| }| d}tt |S )z0return the PyTables column class for this columnuint   NZUIntrD   periodInt64Col)rt  
capitalizerl  r   )r  rf  Zk4Zcol_nameZkcaprV   rV   rW   get_atom_coltype	  s    


zDataCol.get_atom_coltypec                 C  s   | j |d|d dS )Nr  r   r  r*  r  r  rf  rV   rV   rW   r  	  s    zDataCol.get_atom_datac                 C  s   t  j|d dS Nr   r+  r   r(  r  r  rV   rV   rW   r  	  s    zDataCol.get_atom_datetime64c                 C  s   t  j|d dS r.  r/  r0  rV   rV   rW   r  	  s    zDataCol.get_atom_timedelta64c                 C  s   t | jdd S )Nr  )rl  r{  r   rV   rV   rW   r  	  s    zDataCol.shapec                 C  s   | j S r  r  r   rV   rV   rW   r  	  s    zDataCol.cvaluesc                 C  s`   |r\t | j| jd}|dur2|t| jkr2tdt | j| jd}|dur\|| jkr\tddS )zAvalidate that we have the same order as the existing & same dtypeNz4appended items do not match existing items in table!z@appended items dtype do not match existing items dtype in table!)rl  r  r  rn   r\  r   r  r  )r   r   Zexisting_fieldsZexisting_dtyperV   rV   rW   r  	  s    zDataCol.validate_attrr  )r\  r[   r   c                 C  s  t |tjsJ t||jjdur.|| j }| jdus<J | jdu r\t|\}}t	|}n|}| j}| j
}t |tjs|J t| j}| j}	| j}
| j}|dusJ t|}|drt||dd}n&|dkrtj|dd}n|dkr8ztjd	d
 |D td}W n, ty4   tjdd
 |D td}Y n0 n|dkr|	}| }|du rhtg tjd}n<t|}| r||  }||dk  |t j8  < tj|||
dd}n6z|j|dd}W n" t y   |jddd}Y n0 t|dkrt!||||d}| j"|fS )aR  
        Convert the data from this selection to the appropriate pandas type.

        Parameters
        ----------
        values : np.ndarray
        nan_rep :
        encoding : str
        errors : str

        Returns
        -------
        index : listlike to become an Index
        data : ndarraylike to become a column
        N
datetime64Tcoercetimedelta64m8[ns]r  r   c                 S  s   g | ]}t |qS rV   r   fromordinalri   rP  rV   rV   rW   rm   
  r   z#DataCol.convert.<locals>.<listcomp>c                 S  s   g | ]}t |qS rV   r   fromtimestampr9  rV   rV   rW   rm   "
  r   r  F)
categoriesr`  validater|  Or  r   r[   r   )#rQ   rR   r  r   r  r  r  r  r  r  rf  rX   r   r  r`  r  rt  r  asarrayr  r   ravelr,   Zfloat64r3   anyastyperd   Zcumsum_valuesr4   Z
from_codesr   _unconvert_string_arrayr\  )r   r\  r   r[   r   	convertedr  rf  r   r  r`  r  r  r=  r  maskrV   rV   rW   r  	  sf    










 zDataCol.convertc                 C  sH   t | j| j| j t | j| j| j | jdus2J t | j| j| j dS )zset the data for this columnN)r  r  r  r\  r  r   r  r  r   rV   rV   rW   r  K
  s    zDataCol.set_attr)NNNNNNNNNNNN)r   r  r  r  r  r  r  r   r  r  r  r   r  r  r  classmethodr!  r  r*  r  r  r  r  r  r  r  r  __classcell__rV   rV   r  rW   r	  7	  sX                





dr	  c                   @  sZ   e Zd ZdZdZddddZedd Zed	d
dddZedd Z	edd Z
dS )DataIndexableColz+represent a data column that can be indexedTr   r   c                 C  s   t t| jjstdd S )N-cannot have non-object label DataIndexableCol)r#   r,   r\  r  r   r   rV   rV   rW   r  X
  s    zDataIndexableCol.validate_namesc                 C  s   t  j|dS )N)r  r"  r#  rV   rV   rW   r  ]
  s    z DataIndexableCol.get_atom_stringrZ   rD   r$  c                 C  s   | j |d S )Nr  r,  r-  rV   rV   rW   r  a
  s    zDataIndexableCol.get_atom_datac                 C  s
   t   S r]   r/  r0  rV   rV   rW   r  e
  s    z$DataIndexableCol.get_atom_datetime64c                 C  s
   t   S r]   r/  r0  rV   rV   rW   r  i
  s    z%DataIndexableCol.get_atom_timedelta64N)r   r  r  r  r  r  rJ  r  r  r  r  rV   rV   rV   rW   rL  S
  s   

rL  c                   @  s   e Zd ZdZdS )GenericDataIndexableColz(represent a generic pytables data columnN)r   r  r  r  rV   rV   rV   rW   rN  n
  s   rN  c                   @  s  e Zd ZU dZded< dZded< ded< ded	< d
ed< dZded< dNd
dddddddZeddddZ	eddddZ
edd Zdddd Zddd!d"Zd dd#d$Zed%d& Zed'd( Zed)d* Zed+d, Zeddd-d.Zeddd/d0Zed1d2 Zddd3d4Zddd5d6Zed7d8 Zeddd9d:Zed;d< Zd=dd>d?ZdOdddAdBZdddCdDZdPdEdEdFdGdHZdddIdJZdQdEdEddKdLdMZ d@S )RFixedz
    represent an object in my store
    facilitate read/write of various types of objects
    this is an abstract base class

    Parameters
    ----------
    parent : HDFStore
    group : Node
        The group node where the table resides.
    rZ   pandas_kindrv   format_typetype[DataFrame | Series]obj_typerd   rU  r   r   Fr   r5  rP   r~   rF   rY   r   )r   r   r[   r   r\   c                 C  sZ   t |tsJ t|td us"J t |tjs:J t||| _|| _t|| _|| _	d S r]   )
rQ   r   r   r   rF   r   r   r`   r[   r   )r   r   r   r[   r   rV   rV   rW   r   
  s    
zFixed.__init__r   c                 C  s*   | j d dko(| j d dko(| j d dk S )Nr   rg   
      )versionr   rV   rV   rW   is_old_version
  s    zFixed.is_old_versionztuple[int, int, int]c                 C  s`   t t| jjdd}z0tdd |dD }t|dkrB|d }W n tyZ   d}Y n0 |S )	zcompute and set our versionpandas_versionNc                 s  s   | ]}t |V  qd S r]   rd   r%  rV   rV   rW   rM  
  r   z Fixed.version.<locals>.<genexpr>.rU  r'  )r   r   r   )rX   rl  r   rm  ro   r  rp   r   )r   rV  rV   rV   rW   rV  
  s    
zFixed.versionc                 C  s   t t| jjdd S )Nri  )rX   rl  r   rm  r   rV   rV   rW   ri  
  s    zFixed.pandas_typec                 C  s^   |    | j}|durXt|ttfrDddd |D }d| d}| jdd| d	S | jS )
(return a pretty representation of myselfNr  c                 S  s   g | ]}t |qS rV   r?   r%  rV   rV   rW   rm   
  r   z"Fixed.__repr__.<locals>.<listcomp>[r$  12.12z	 (shape->))r  r  rQ   rn   ro   r  ri  )r   rU   ZjshaperV   rV   rW   r   
  s    zFixed.__repr__c                 C  s   t | j| j_t t| j_dS )zset my pandas type & versionN)rZ   rP  r  ri  _versionrX  r   rV   rV   rW   r  
  s    zFixed.set_object_infoc                 C  s   t  | }|S r]   r?  )r   Znew_selfrV   rV   rW   r|  
  s    
z
Fixed.copyc                 C  s   | j S r]   )r  r   rV   rV   rW   r  
  s    zFixed.shapec                 C  s   | j jS r]   r   r   r   rV   rV   rW   r6  
  s    zFixed.pathnamec                 C  s   | j jS r]   )r   r   r   rV   rV   rW   r   
  s    zFixed._handlec                 C  s   | j jS r]   )r   r   r   rV   rV   rW   r   
  s    zFixed._filtersc                 C  s   | j jS r]   )r   r   r   rV   rV   rW   r   
  s    zFixed._complevelc                 C  s   | j jS r]   )r   r   r   rV   rV   rW   r   
  s    zFixed._fletcher32c                 C  s   | j jS r]   )r   rm  r   rV   rV   rW   r  
  s    zFixed.attrsc                 C  s   dS zset our object attributesNrV   r   rV   rV   rW   	set_attrs
  s    zFixed.set_attrsc                 C  s   dS )zget our object attributesNrV   r   rV   rV   rW   	get_attrs
  s    zFixed.get_attrsc                 C  s   | j S )zreturn my storabler  r   rV   rV   rW   storable
  s    zFixed.storablec                 C  s   dS r  rV   r   rV   rV   rW   r  
  s    zFixed.is_existsc                 C  s   t | jdd S )Nr  )rl  re  r   rV   rV   rW   r  
  s    zFixed.nrowszLiteral[True] | Nonec                 C  s   |du rdS dS )z%validate against an existing storableNTrV   r  rV   rV   rW   r>  
  s    zFixed.validateNc                 C  s   dS )+are we trying to operate on an old version?NrV   )r   rq   rV   rV   rW   validate_version
  s    zFixed.validate_versionc                 C  s   | j }|du rdS |   dS )zr
        infer the axes of my storer
        return a boolean indicating if we have a valid storer or not
        NFT)re  rd  )r   rU   rV   rV   rW   r  
  s
    zFixed.infer_axesr   r   r   c                 C  s   t dd S )Nz>cannot read on an abstract storer: subclasses should implementr   r   rq   r   r   r   rV   rV   rW   r
     s    z
Fixed.readc                 K  s   t dd S )Nz?cannot write on an abstract storer: subclasses should implementri  r   r  r   rV   rV   rW   r    s    zFixed.writer   r   r\   c                 C  s0   t |||r$| jj| jdd dS tddS )zs
        support fully deleting the node in its entirety (only) - where
        specification must be None
        Tr>  Nz#cannot delete on an abstract storer)rB  rC  r   r  r   r   )r   rq   r   r   rV   rV   rW   rD    s    zFixed.delete)rP   r~   )N)NNNN)NNN)!r   r  r  r  r  rQ  r5  r   r  rW  rV  ri  r   r  r|  r  r6  r   r   r   r   r  rc  rd  re  r  r  r>  rg  r  r
  r  rD  rV   rV   rV   rW   rO  r
  sh   
  







     rO  c                   @  sF  e Zd ZU dZedediZdd e D Zg Z	de
d< dd	d
dZdd Zdd Zdd	ddZedd	ddZdd	ddZdd	ddZdd	ddZd:dddddd Zd;dddd!d"d#d$Zdd!dd%d&d'Zdd(dd%d)d*Zd<dddd(d"d+d,Zd=d-ddd!d.d/d0Zdd1dd2d3d4Zd>dd5d6dd7d8d9ZdS )?GenericFixedza generified fixed versiondatetimer'  c                 C  s   i | ]\}}||qS rV   rV   )ri   r#  rP  rV   rV   rW   rQ  "  r   zGenericFixed.<dictcomp>r   
attributesrZ   r   c                 C  s   | j |dS )N )_index_type_mapr   )r   r  rV   rV   rW   _class_to_alias&  s    zGenericFixed._class_to_aliasc                 C  s   t |tr|S | j|tS r]   )rQ   r   _reverse_index_mapr   r,   )r   aliasrV   rV   rW   _alias_to_class)  s    
zGenericFixed._alias_to_classc                 C  s   |  tt|dd}|tkr.d	dd}|}n|tkrFd
dd}|}n|}i }d|v rn|d |d< |tu rnt}d|v rt|d tr|d 	d|d< n|d |d< |tu sJ ||fS )Nindex_classrp  c                 S  s>   t j| j| j|d}tj|d d}|d ur:|d|}|S )N)r  r  ra   UTC)r5   _simple_newr\  r  r+   tz_localize
tz_convert)r\  r  r  ZdtaresultrV   rV   rW   rx   8  s    
z*GenericFixed._get_index_factory.<locals>.fc                 S  s$   t |}tj| |d}tj|d dS )Nr6  ra   )r(   r6   rx  r.   )r\  r  r  r  ZparrrV   rV   rW   rx   E  s    r  r  zutf-8)NN)NN)
ru  rX   rl  r+   r.   r,   r1   rQ   bytesrT   )r   r  rv  rx   r  r   rV   rV   rW   _get_index_factory/  s*    


zGenericFixed._get_index_factoryr   c                 C  s$   |durt d|dur t ddS )zE
        raise if any keywords are passed which are not-None
        Nzqcannot pass a column specification when reading a Fixed format store. this store must be selected in its entiretyzucannot pass a where specification when reading from a Fixed format store. this store must be selected in its entirety)r   )r   r   rq   rV   rV   rW   validate_read`  s    zGenericFixed.validate_readr   c                 C  s   dS )NTrV   r   rV   rV   rW   r  o  s    zGenericFixed.is_existsc                 C  s   | j | j_ | j| j_dS rb  )r[   r  r   r   rV   rV   rW   rc  s  s    
zGenericFixed.set_attrsc              	   C  sR   t t| jdd| _tt| jdd| _| jD ]}t| |tt| j|d q.dS )retrieve our attributesr[   Nr   r~   )r`   rl  r  r[   rX   r   ro  r  )r   r   rV   rV   rW   rd  x  s    
zGenericFixed.get_attrsc                 K  s   |    d S r]   )rc  rk  rV   rV   rW   r    s    zGenericFixed.writeNr   r  c                 C  s   ddl }t| j|}|j}t|dd}t||jrD|d || }ntt|dd}	t|dd}
|
durxtj|
|	d}n||| }|	r|		drt|d	d}t
||d
d}n|	dkrtj|dd}|r|jS |S dS )z2read an array for the specified node (off of groupr   N
transposedF
value_typer  r6  r1  r  Tr2  r4  r5  )r   rl  r   rm  rQ   ZVLArrayrX   rR   r  rt  r  rB  T)r   r   r   r   r   r   r  r  retr  r  r  rV   rV   rW   
read_array  s&    zGenericFixed.read_arrayr,   )r   r   r   r\   c                 C  sh   t t| j| d}|dkr.| j|||dS |dkrVt| j|}| j|||d}|S td| d S )N_varietymultirh  regularzunrecognized index variety: )rX   rl  r  read_multi_indexr   read_index_noder   )r   r   r   r   Zvarietyr   r   rV   rV   rW   
read_index  s    zGenericFixed.read_index)r   r   r\   c                 C  s   t |tr,t| j| dd | || nt| j| dd td|| j| j}| ||j	 t
| j|}|j|j_|j|j_t |ttfr| t||j_t |tttfr|j|j_t |tr|jd urt|j|j_d S )Nr  r  r  r   )rQ   r-   r  r  write_multi_index_convert_indexr[   r   write_arrayr\  rl  r   rf  rm  rb   r+   r.   rr  r   rv  r1   r  r  _get_tz)r   r   r   rH  r   rV   rV   rW   write_index  s    



zGenericFixed.write_indexr-   c                 C  s   t | j| d|j tt|j|j|jD ]\}\}}}t|j	t
rNtd| d| }t||| j| j}| ||j t| j|}	|j|	j_||	j_t |	j| d| | | d| }
| |
| q,d S )N_nlevelsz=Saving a MultiIndex with an extension dtype is not supported._level_name_label)r  r  r  	enumerater4  levelsr  namesrQ   r  r'   r   r  r[   r   r  r\  rl  r   rf  rm  rb   )r   r   r   ilevlevel_codesrb   	level_keyZ
conv_levelr   	label_keyrV   rV   rW   r    s"    
zGenericFixed.write_multi_indexc                 C  s   t | j| d}g }g }g }t|D ]l}| d| }	t | j|	}
| j|
||d}|| ||j | d| }| j|||d}|| q&t|||ddS )Nr  r  rh  r  T)r  r  r  r-  )	rl  r  rT  r   r  r   rb   r  r-   )r   r   r   r   r  r  r  r  r  r  r   r  r  r  rV   rV   rW   r    s     
zGenericFixed.read_multi_indexrF   )r   r   r   r\   c                 C  s   ||| }d|j v r>t|j jdkr>tj|j j|j jd}t|j j}d }d|j v rlt|j j	}t|}|j }| 
|\}}	|dv r|t||| j| jdfdti|	}
n |t||| j| jdfi |	}
||
_	|
S )Nr  r   r6  rb   )r   r  r  r  )rm  rR   prodr  r  r  rX   rf  rc   rb   r}  _unconvert_indexr[   r   r  )r   r   r   r   r{  rf  rb   r  r  r   r   rV   rV   rW   r    s:    
zGenericFixed.read_index_noderH   )r   r   r\   c                 C  sJ   t d|j }| j| j|| t| j|}t|j|j	_
|j|j	_dS )zwrite a 0-len arrayrg   N)rR   r  rU  r   create_arrayr   rl  rZ   r  rm  r  r  )r   r   r   Zarrr   rV   rV   rW   write_array_empty  s
    zGenericFixed.write_array_emptyrG   zIndex | None)r   r  r   r\   c                 C  sh  t |dd}|| jv r&| j| j| |jdk}d}t|jtrHtd|s`t	|dr`|j
}d}d }| jd urtt  t j|j}W d    n1 s0    Y  |d ur|s| jj| j|||j| jd}||d d < n| || nh|jjtjkrbtj|dd}	|rn,|	d	krn t|	||f }
tj|
tt d
 | j| j|t  }| | nt!|jdr| j"| j||#d t$|jt%| j|j&_'nt|jt(r| j"| j||j) t%| j|}t*|j+|j&_+d|jj, d|j&_'n`t!|jdr.| j"| j||#d dt%| j|j&_'n&|rB| || n| j"| j|| |t%| j|j&_-d S )NT)Zextract_numpyr   Fz]Cannot store a category dtype in a HDF5 dataset that uses format="fixed". Use format="table".r  )r   Zskipnar  r  r  r  datetime64[r$  r  r4  ).r9   r   r   r  r  rQ   r  r%   r   r  r  r   r   r   r   ZAtomZ
from_dtypeZcreate_carrayr  r  r   rR   Zobject_r   infer_dtyperu   r  r  r   r   Zcreate_vlarray
ObjectAtomr   r  r  viewrZ   rl  rm  r  r&   asi8r  r  unitr  )r   r   r  r   r   Zempty_arrayr  r   cainferred_typer  Zvlarrr   rV   rV   rW   r  (  sf    




.

zGenericFixed.write_array)NN)NN)NN)NN)N)r   r  r  r  r+   r.   rq  r   rs  ro  r  rr  ru  r}  r~  r  r  rc  rd  r  r  r  r  r  r  r  r  r  rV   rV   rV   rW   rm    s2   
1#   &
 rm  c                      sV   e Zd ZU dZdgZded< edd Zddddd	d
dZdd fddZ	  Z
S )r  r  rb   r@   c              	   C  s.   zt | jjfW S  ttfy(   Y d S 0 d S r]   )rp   r   r\  r   r   r   rV   rV   rW   r    s    zSeriesFixed.shapeNr   r0   rl  c                 C  s^   |  || | jd||d}| jd||d}t||| jdd}t rZt|ddrZ|d}|S )	Nr   rh  r\  F)r   rb   r|  Tr  string[pyarrow_numpy])r~  r  r  r0   rb   r   r   rE  )r   rq   r   r   r   r   r\  r{  rV   rV   rW   r
    s    
zSeriesFixed.readr   r   c                   s<   t  j|fi | | d|j | d| |j| j_d S )Nr   r\  )r
  r  r  r   r  rb   r  rk  r  rV   rW   r    s    zSeriesFixed.write)NNNN)r   r  r  rP  ro  r  r  r  r
  r  rK  rV   rV   r  rW   r    s   

    r  c                      sZ   e Zd ZU ddgZded< eddddZdd	d	d
dddZdd fddZ  Z	S )BlockManagerFixedrU  nblocksrd   zShape | Noner   c                 C  s   z| j }d}t| jD ]8}t| jd| d}t|dd }|d ur||d 7 }q| jj}t|dd }|d urt|d|d  }ng }|| |W S  ty   Y d S 0 d S )Nr   block_itemsr  rg   )	rU  rT  r  rl  r   Zblock0_valuesrn   r   r   )r   rU  r   r  r   r  rV   rV   rW   r    s"    
zBlockManagerFixed.shapeNr   r*   rl  c                 C  sH  |  || |  d}g }t| jD ]<}||kr<||fnd\}}	| jd| ||	d}
||
 q(|d }g }t| jD ]x}| d| d}| jd| d||	d}||	| }t
|j||d d	d
}t rt|ddr|d}|| q|t|dkr4t|ddd}t r"| }|j|d	d}|S t
|d |d dS )Nr   )NNr,  rh  r  r  rF  rg   Fr   r   r|  Tr  r  )r,  r|  )r   r|  r   r   )r~  rS  Z_get_block_manager_axisrT  rU  r  r   r  r  rZ  r*   r  r   r   rE  rp   r2   r   r|  r_  )r   rq   r   r   r   Zselect_axisrF  r  r  r  axr   dfs	blk_itemsr\  dfoutrV   rV   rW   r
    s0    
zBlockManagerFixed.readr   c                   s   t  j|fi | t|jtr*|d}|j}| s@| }|j| j	_t
|jD ]0\}}|dkrr|jsrtd| d| | qTt|j| j	_t
|jD ]D\}}|j|j}| jd| d|j|d | d| d| qd S )Nr  r   z/Columns index has to be unique for fixed formatr,  rF  )r   r  )r
  r  rQ   _mgrr;   _as_managerZis_consolidatedZconsolidaterU  r  r  rF  Z	is_uniquer   r  rp   blocksr  r   r[  mgr_locsr  r\  )r   r  r   r{  r  r  blkr  r  rV   rW   r    s     

zBlockManagerFixed.write)NNNN)
r   r  r  ro  r  r  r  r
  r  rK  rV   rV   r  rW   r    s   
    )r  c                   @  s   e Zd ZdZeZdS )r  r  N)r   r  r  rP  r*   rS  rV   rV   rV   rW   r  	  s   r  c                      s  e Zd ZU dZdZdZded< ded< dZded	< d
Zded< dddddddddddd
 fddZ	e
ddddZddddZdd d!d"Zddd#d$Ze
d%dd&d'Zd(d)d*d+d,Ze
d-dd.d/Ze
d%dd0d1Ze
d2d3 Ze
d4d5 Ze
d6d7 Ze
d8d9 Ze
d:dd;d<Ze
d-dd=d>Ze
d%dd?d@Ze
dAddBdCZdDddEdFZdGdH ZdIddJdKZdddLdMdNZddOddPdQdRZddSdTdUZ dddVdWZ!dddXdYZ"ddddZd[Z#ddd\d]Z$e%d^d_ Z&dddd`dadbZ'ddcdcdddedfdgZ(e)d%dhdidjZ*dkdl Z+ddmd%dndodpZ,e-dmd%dqdrdsZ.ddtdmdudvdwZ/dcd%dcdDdxdydzZ0ddcdcd{d|d}Z1dddcdcd~ddZ2  Z3S )r   aa  
    represent a table:
        facilitate read/write of various types of tables

    Attrs in Table Node
    -------------------
    These are attributes that are store in the main table node, they are
    necessary to recreate these tables when read back in.

    index_axes    : a list of tuples of the (original indexing axis and
        index column)
    non_index_axes: a list of tuples of the (original index axis and
        columns on a non-indexing axis)
    values_axes   : a list of the columns which comprise the data of this
        table
    data_columns  : a list of the columns that we are allowing indexing
        (these become single columns in values_axes)
    nan_rep       : the string to use for nan representations for string
        objects
    levels        : the names of levels
    metadata      : the names of the metadata columns
    Z
wide_tablerw   rZ   rQ  r  rg   zint | list[Hashable]r  Trn   r  Nr~   r   rF   rY   zlist[IndexCol] | Nonez list[tuple[AxisInt, Any]] | Nonezlist[DataCol] | Nonezlist | Nonezdict | Noner   )
r   r   r[   r   
index_axesr(  values_axesr   r  r\   c                   sP   t  j||||d |pg | _|p$g | _|p.g | _|p8g | _|	pBi | _|
| _d S )Nr  )r
  r   r  r(  r  r   r  r   )r   r   r   r[   r   r  r(  r  r   r  r   r  rV   rW   r   .  s    




zTable.__init__r   c                 C  s   | j dd S )N_r   )r  r  r   rV   rV   rW   table_type_shortC  s    zTable.table_type_shortc                 C  s   |    t| jrd| jnd}d| d}d}| jrZddd | jD }d| d}dd	d | jD }| jd
| d| j d| j	 d| j
 d| d| dS )r[  r  rp  z,dc->[r$  rZ  c                 S  s   g | ]}t |qS rV   rZ   r%  rV   rV   rW   rm   O  r   z"Table.__repr__.<locals>.<listcomp>r]  c                 S  s   g | ]
}|j qS rV   ra   rz  rV   rV   rW   rm   R  r   r^  z (typ->z,nrows->z,ncols->z,indexers->[r_  )r  rp   r   r  rW  rV  r  ri  r  r  ncols)r   Zjdcra  verZjverZjindex_axesrV   rV   rW   r   G  s(    zTable.__repr__)r  c                 C  s"   | j D ]}||jkr|  S qdS )zreturn the axis for cN)rF  rb   )r   r  r   rV   rV   rW   r   Y  s    


zTable.__getitem__c              
   C  s   |du rdS |j | j kr2td|j  d| j  ddD ]~}t| |d}t||d}||kr6t|D ]4\}}|| }||krbtd| d| d| dqbtd| d| d| dq6dS )	z"validate against an existing tableNz'incompatible table_type with existing [r  r$  )r  r(  r  zinvalid combination of [z] on appending data [z] vs current table [)r  r   rl  r  r   rA  )r   r  r  svovr  saxZoaxrV   rV   rW   r>  `  s:    zTable.validater   c                 C  s   t | jtS )z@the levels attribute is 1 or a list in the case of a multi-index)rQ   r  rn   r   rV   rV   rW   is_multi_index  s    zTable.is_multi_indexr   z tuple[DataFrame, list[Hashable]])r  r\   c              
   C  s`   t |jj}z| }W n. tyH } ztd|W Y d}~n
d}~0 0 t|tsXJ ||fS )ze
        validate that we can store the multi-index; reset and return the
        new object
        zBduplicate names/columns in the multi-index when storing as a tableN)rB  Zfill_missing_namesr   r  Zreset_indexr   rQ   r*   )r   r  r  Z	reset_objrE  rV   rV   rW   validate_multiindex  s    zTable.validate_multiindexrd   c                 C  s   t dd | jD S )z-based on our axes, compute the expected nrowsc                 S  s   g | ]}|j jd  qS r'  )r  r  ri   r  rV   rV   rW   rm     r   z(Table.nrows_expected.<locals>.<listcomp>)rR   r  r  r   rV   rV   rW   nrows_expected  s    zTable.nrows_expectedc                 C  s
   d| j v S )zhas this table been createdrw   r  r   rV   rV   rW   r    s    zTable.is_existsc                 C  s   t | jdd S Nrw   rl  r   r   rV   rV   rW   re    s    zTable.storablec                 C  s   | j S )z,return the table group (this is my storable))re  r   rV   rV   rW   rw     s    zTable.tablec                 C  s   | j jS r]   )rw   r  r   rV   rV   rW   r    s    zTable.dtypec                 C  s   | j jS r]   r  r   rV   rV   rW   r    s    zTable.descriptionzitertools.chain[IndexCol]c                 C  s   t | j| jS r]   )r2  r3  r  r  r   rV   rV   rW   rF    s    z
Table.axesc                 C  s   t dd | jD S )z.the number of total columns in the values axesc                 s  s   | ]}t |jV  qd S r]   )rp   r\  rz  rV   rV   rW   rM    r   zTable.ncols.<locals>.<genexpr>)sumr  r   rV   rV   rW   r    s    zTable.ncolsc                 C  s   dS r  rV   r   rV   rV   rW   is_transposed  s    zTable.is_transposedztuple[int, ...]c                 C  s(   t tdd | jD dd | jD S )z@return a tuple of my permutated axes, non_indexable at the frontc                 S  s   g | ]}t |d  qS r'  rY  rz  rV   rV   rW   rm     r   z*Table.data_orientation.<locals>.<listcomp>c                 S  s   g | ]}t |jqS rV   )rd   r,  rz  rV   rV   rW   rm     r   )ro   r2  r3  r(  r  r   rV   rV   rW   data_orientation  s    zTable.data_orientationzdict[str, Any]c                   sR   ddd dd j D } fddjD }fddjD }t|| | S )z<return a dict of the kinds allowable columns for this objectr   r   r   rg   c                 S  s   g | ]}|j |fqS rV   r  rz  rV   rV   rW   rm     r   z$Table.queryables.<locals>.<listcomp>c                   s   g | ]\}} | d fqS r]   rV   )ri   r,  r\  )
axis_namesrV   rW   rm     r   c                   s&   g | ]}|j t jv r|j|fqS rV   )rb   rS  r   r  r9  r   rV   rW   rm     s   )r  r(  r  rH  )r   Zd1Zd2Zd3rV   )r  r   rW   
queryables  s    

zTable.queryablesc                 C  s   dd | j D S )zreturn a list of my index colsc                 S  s   g | ]}|j |jfqS rV   )r,  r  r  rV   rV   rW   rm     r   z$Table.index_cols.<locals>.<listcomp>r  r   rV   rV   rW   
index_cols  s    zTable.index_colsr   c                 C  s   dd | j D S )zreturn a list of my values colsc                 S  s   g | ]
}|j qS rV   r  r  rV   rV   rW   rm     r   z%Table.values_cols.<locals>.<listcomp>)r  r   rV   rV   rW   values_cols  s    zTable.values_colsr   c                 C  s   | j j}| d| dS )z)return the metadata pathname for this keyz/meta/z/metara  r  rV   rV   rW   _get_metadata_path  s    zTable._get_metadata_pathr  )r   r\  r\   c                 C  s0   | j j| |t|ddd| j| j| jd dS )z
        Write out a metadata array to the key as a fixed-format Series.

        Parameters
        ----------
        key : str
        values : ndarray
        Fr?  rw   )r   r[   r   r   N)r   r   r  r0   r[   r   r   )r   r   r\  rV   rV   rW   r    s    	
zTable.write_metadatar   c                 C  s0   t t | jdd|ddur,| j| |S dS )z'return the meta data array for this keyr   N)rl  r   r   r   r  r   rV   rV   rW   r    s    zTable.read_metadatac                 C  sp   t | j| j_|  | j_|  | j_| j| j_| j| j_| j| j_| j| j_| j	| j_	| j
| j_
| j| j_dS )zset our table type & indexablesN)rZ   r  r  r  r  r(  r   r   r[   r   r  r  r   rV   rV   rW   rc    s    





zTable.set_attrsc                 C  s   t | jddpg | _t | jddp$g | _t | jddp8i | _t | jdd| _tt | jdd| _tt | jdd| _	t | jd	dpg | _
d
d | jD | _dd | jD | _dS )r  r(  Nr   r  r   r[   r   r~   r  c                 S  s   g | ]}|j r|qS rV   r  rz  rV   rV   rW   rm     r   z#Table.get_attrs.<locals>.<listcomp>c                 S  s   g | ]}|j s|qS rV   r  rz  rV   rV   rW   rm     r   )rl  r  r(  r   r  r   r`   r[   rX   r   r  
indexablesr  r  r   rV   rV   rW   rd  
  s    zTable.get_attrsc                 C  s>   |dur:| j r:tddd | jD  }tj|tt d dS )rf  NrZ  c                 S  s   g | ]}t |qS rV   r  r%  rV   rV   rW   rm     r   z*Table.validate_version.<locals>.<listcomp>r  )rW  rs   r  rV  r  r  r   r   )r   rq   r  rV   rV   rW   rg    s    zTable.validate_versionc                 C  sR   |du rdS t |tsdS |  }|D ]&}|dkr4q&||vr&td| dq&dS )z
        validate the min_itemsize doesn't contain items that are not in the
        axes this needs data_columns to be defined
        Nr\  zmin_itemsize has the key [z%] which is not an axis or data_column)rQ   rH  r  r   )r   r   qr#  rV   rV   rW   validate_min_itemsize!  s    

zTable.validate_min_itemsizec                   s   g }j jjtjjD ]j\}\}}t|}|}|durJdnd}| d}t|d}	t||||	|j||d}
||
 qt	j
t|  fdd|fddtjjD  |S )	z/create/cache the indexables if they don't existNr  r  )rb   r,  r  rf  r  rw   r   r  c                   s   t |tsJ t}|v rt}t|}t|j}t| dd }t| dd }t|}|}t| dd }	||||| |  |j	|	||d
}
|
S )Nr  r  r  )
rb   r  r\  rf  r  r  rw   r   r  r  )
rQ   rZ   r	  rL  rl  _maybe_adjust_namerV  r  r  rw   )r  r  klassr   adj_namer\  r  rf  mdr   r  )base_posra  descr   table_attrsrV   rW   rx   Y  s0    

zTable.indexables.<locals>.fc                   s   g | ]\}} ||qS rV   rV   )ri   r  r  )rx   rV   rW   rm   ~  r   z$Table.indexables.<locals>.<listcomp>)r  rw   r  r  r  rl  r  r  r   rS  r   rp   rW  r  )r   _indexablesr  r,  rb   r   r  r   r  rf  	index_colrV   )r  ra  r  rx   r   r  rW   r  6  s2    




% zTable.indexablesr$  c              	   C  sV  |   sdS |du rdS |du s(|du r8dd | jD }t|ttfsL|g}i }|dur`||d< |durp||d< | j}|D ]}t|j|d}|dur"|jr|j	}|j
}	|j}
|dur|
|kr|  n|
|d< |dur|	|kr|  n|	|d< |jsP|jdrtd	|jf i | qz|| jd
 d v rztd| d| d| dqzdS )aZ  
        Create a pytables index on the specified columns.

        Parameters
        ----------
        columns : None, bool, or listlike[str]
            Indicate which columns to create an index on.

            * False : Do not create any indexes.
            * True : Create indexes on all columns.
            * None : Create indexes on all columns.
            * listlike : Create indexes on the given columns.

        optlevel : int or None, default None
            Optimization level, if None, pytables defaults to 6.
        kind : str or None, default None
            Kind of index, if None, pytables defaults to "medium".

        Raises
        ------
        TypeError if trying to create an index on a complex-type column.

        Notes
        -----
        Cannot index Time64Col or ComplexCol.
        Pytables must be >= 3.0.
        NFTc                 S  s   g | ]}|j r|jqS rV   )r  r  rz  rV   rV   rW   rm     r   z&Table.create_index.<locals>.<listcomp>re  rf  complexzColumns containing complex values can be stored but cannot be indexed when using table format. Either use fixed format, set index=False, or do not include the columns containing complex values to data_columns when initializing the table.r   rg   zcolumn z/ is not a data_column.
In order to read column z: you must reload the dataframe 
into HDFStore and include z  with the data_columns argument.)r  rF  rQ   ro   rn   rw   rl  rL  ry  r   re  rf  Zremove_indexr   rt  r   rg  r(  r   )r   r   re  rf  kwrw   r  rP  r   Zcur_optlevelZcur_kindrV   rV   rW   rg    sR    


zTable.create_indexr   z9list[tuple[np.ndarray, np.ndarray] | tuple[Index, Index]]rl  c           	      C  sZ   t | |||d}| }g }| jD ]2}|| j |j|| j| j| jd}|	| q"|S )a  
        Create the axes sniffed from the table.

        Parameters
        ----------
        where : ???
        start : int or None, default None
        stop : int or None, default None

        Returns
        -------
        List[Tuple[index_values, column_values]]
        r  rA  )
	Selectionr   rF  r  r  r  r   r[   r   r   )	r   rq   r   r   	selectionr\  r  r   resrV   rV   rW   
_read_axes  s    
zTable._read_axesr  c                 C  s   |S )zreturn the data for this objrV   r  r  r  rV   rV   rW   
get_object  s    zTable.get_objectc                   s   t |sg S |d \} | j|i }|ddkrL|rLtd| d| |du r^t }n|du rjg }t|trt|t|}|fdd	|	 D   fd
d	|D S )zd
        take the input data_columns and min_itemize and create a data
        columns spec
        r   r   r-   z"cannot use a multi-index on axis [z] with data_columns TNc                   s    g | ]}|d kr| vr|qS r  rV   r"  )existing_data_columnsrV   rW   rm     s   z/Table.validate_data_columns.<locals>.<listcomp>c                   s   g | ]}| v r|qS rV   rV   )ri   r  )axis_labelsrV   rW   rm   #  r   )
rp   r  r   r   rn   rQ   rH  rS  rW  r   )r   r   r   r(  r,  r  rV   )r  r  rW   validate_data_columns  s.    


	zTable.validate_data_columnsr*   )r  r>  c           /        s  t ts,| jj}td| dt d du r:dg fdd D  |  rzd}d	d | jD  t| j	}| j
}nd
}| j}	| jdksJ t | jd krtdg }
|du rd}t fdddD }j| }t|}|rHt|
}| j| d }tt|t|dddsHttt|tt|dddrH|}|	|i }t|j|d< t|j|d< |
||f  d }j| }|}t||| j| j}||_|d | |	 |!| |g}t|}|dksJ t|
dksJ |
D ]}t"|d |d q|jdk}| #|||
}| $|% }| &|||
| j'|\}}g }t(t)||D ]\}\}}t*}d}|rt|dkr|d |v rt+}|d }|du st |t,std|r4|r4z| j'| }W nD t-t.fy0 }  z&td| d| j' d| W Y d} ~ n
d} ~ 0 0 nd}|pFd| }!t/|!|j0|||| j| j|d}"t1|!| j2}#|3|"}$t4|"j5j6}%d}&t7|"dddurt8|"j9}&d }' }(})t |"j5t:r|"j;})d}'t<|"j=> }(t?|"\}*}+||#|!t||$||%|&|)|'|(|+|*d},|, |	 ||, |d7 }qpdd |D }-t| | j@| j| j| j||
||-|	|d
}.tA| drv| jB|._B|.C| |r|r|.D|  |.S ) a0  
        Create and return the axes.

        Parameters
        ----------
        axes: list or None
            The names or numbers of the axes to create.
        obj : DataFrame
            The object to create axes on.
        validate: bool, default True
            Whether to validate the obj against an existing object already written.
        nan_rep :
            A value to use for string column nan_rep.
        data_columns : List[str], True, or None, default None
            Specify the columns that we want to create to allow indexing on.

            * True : Use all available columns.
            * None : Use no columns.
            * List[str] : Use the specified columns.

        min_itemsize: Dict[str, int] or None, default None
            The min itemsize for a column in bytes.
        z/cannot properly create the storer for: [group->r  r$  Nr   c                   s   g | ]}  |qS rV   )_get_axis_numberrz  )r  rV   rW   rm   Q  r   z&Table._create_axes.<locals>.<listcomp>Tc                 S  s   g | ]
}|j qS rV   rN  rz  rV   rV   rW   rm   V  r   FrU  rg   z<currently only support ndim-1 indexers in an AppendableTablenanc                 3  s   | ]}| vr|V  qd S r]   rV   r%  )rF  rV   rW   rM  n  r   z%Table._create_axes.<locals>.<genexpr>r  r  r  r   rM  zIncompatible appended table [z]with existing table [Zvalues_block_)existing_colr   r   r[   r   r   r  r  )rb   r  r\  r  r  rf  r  r`  r   r  r  r{  c                 S  s   g | ]}|j r|jqS rV   )r  rb   )ri   r  rV   rV   rW   rm     r   )
r   r   r[   r   r  r(  r  r   r  r   r  )ErQ   r*   r   r   r   r   r  r  rn   r   r   r  rU  rp   r   rR  rF  r(  r)   rR   arrayrY  r  r  r   r   Z_get_axis_namer  r[   r   r,  r  r   r  _reindex_axisr  r  r.  _get_blocks_and_itemsr  r  r4  r	  rL  rZ   
IndexErrorr   _maybe_convert_for_string_atomr\  r  rV  r!  r  r  rb   rl  r  r  r%   r`  rB  r=  rC  r  r   r  r  r  r>  )/r   rF  r  r>  r   r   r   r   table_existsZnew_infonew_non_index_axesr  r   Zappend_axisZindexerZ
exist_axisr  	axis_nameZ	new_indexZnew_index_axesjr  r  r  r  Zvaxesr  r  b_itemsr  rb   r  rE  new_namedata_convertedr  r  rf  r  r   r  r`  r{  r  r  ZdcsZ	new_tablerV   )rF  r  rW   _create_axes%  s,    








"






zTable._create_axes)r  r  c                 C  s  t | jtr| d} dd }| j}tt|}t|j}||}t|r|d \}	}
t	|

t	|}| j||	dj}tt|}t|j}||}|D ]:}| j|g|	dj}tt|}||j ||| q|rdd t||D }g }g }|D ]}t|j}z&||\}}|| || W q ttfy| } z2dd	d
 |D }td| d|W Y d }~qd }~0 0 q|}|}||fS )Nr  c                   s    fdd j D S )Nc                   s   g | ]} j |jqS rV   )r   r[  r  )ri   r  mgrrV   rW   rm   $  r   zFTable._get_blocks_and_items.<locals>.get_blk_items.<locals>.<listcomp>)r  r  rV   r  rW   get_blk_items#  s    z2Table._get_blocks_and_items.<locals>.get_blk_itemsr   rN  c                 S  s"   i | ]\}}t | ||fqS rV   )ro   tolist)ri   br  rV   rV   rW   rQ  B  s   z/Table._get_blocks_and_items.<locals>.<dictcomp>r  c                 S  s   g | ]}t |qS rV   r\  )ri   itemrV   rV   rW   rm   O  r   z/Table._get_blocks_and_items.<locals>.<listcomp>z+cannot match existing table structure for [z] on appending data)rQ   r  r;   r  r   r<   rn   r  rp   r,   rX  r_  rW  r4  ro   r\  r7  r   r  r   r  r   )r  r  r  r  r   r  r   r  r  r,  r  Z
new_labelsr  Zby_itemsZ
new_blocksZnew_blk_itemsZear   r  r  rE  ZjitemsrV   rV   rW   r    sR    








zTable._get_blocks_and_itemsr  )r  r\   c                   s   |durt |}|durNjrNtjt s.J jD ]}||vr4|d| q4jD ]$\}}t |||  fdd}qT|jdur|j D ]\}}	}
|||
|	 q S )zprocess axes filtersNr   c                   s    j D ]} |} |}|d us*J | |krfjrH|tj}|||} j|d|   S | |v rtt	 | j
}t|}t trd| }|||} j|d|   S qtd|  dd S )NrN  rg   zcannot find the field [z] for filtering!)Z_AXIS_ORDERSr  	_get_axisr  unionr,   r  r^  r:   rl  r\  rQ   r*   r   )fieldfiltopr  Zaxis_numberZaxis_valuesZtakersr\  r  r   rV   rW   process_filterj  s"    





z*Table.process_axes.<locals>.process_filter)	rn   r  rQ   r  insertr(  r  filterr   )r   r  r  r   r   r,  labelsr  r  r	  r  rV   r
  rW   process_axesY  s    
 
zTable.process_axes)r   r   rG  r\   c                 C  s   |du rt | jd}d|d}dd | jD |d< |rj|du rH| jpFd}t j|||pZ| jd	}||d
< n| jdur~| j|d
< |S )z:create the description of the table from the axes & valuesNi'  rw   )rb   rG  c                 S  s   i | ]}|j |jqS rV   )r  r  rz  rV   rV   rW   rQ    r   z,Table.create_description.<locals>.<dictcomp>r  	   )r   r   r   r   )maxr  rF  r   r   r   r   r   )r   r   r   r   rG  rI  r   rV   rV   rW   create_description  s     	




zTable.create_descriptionrh  c           
      C  s   |  | |  sdS t| |||d}| }|jdur|j D ]D\}}}| j|| | d d}	|||	j	||   |j
 }qBt|S )zf
        select coordinates (row numbers) from a table; return the
        coordinates object
        Fr  Nrg   rh  )rg  r  r  select_coordsr  r   r   r  r  ilocr\  r,   )
r   rq   r   r   r  Zcoordsr  r	  r  r{  rV   rV   rW   r    s    

 zTable.read_coordinatesr  c                 C  s   |    |  sdS |dur$td| jD ]|}||jkr*|jsNtd| dt| jj	|}|
| j |j||| | j| j| jd}tt|d |j|dd  S q*td| d	dS )
zj
        return a single column from the table, generally only indexables
        are interesting
        FNz4read_column does not currently accept a where clausezcolumn [z=] can not be extracted individually; it is not data indexablerA  rg   )rb   r|  z] not found in the table)rg  r  r   rF  rb   r  r   rl  rw   rL  r  r  r  r   r[   r   r0   r  r  r   )r   r  rq   r   r   r   r  Z
col_valuesrV   rV   rW   r     s*    



 zTable.read_column)Nr~   NNNNNN)N)NNN)NN)TNNN)N)NNN)NNN)4r   r  r  r  rP  rQ  r  r  r5  r   r  r  r   r   r>  r  r  r  r  re  rw   r  r  rF  r  r  r  r  r  r  r  r  r  rc  rd  rg  r  r   r  rg  r  rJ  r  r  r  staticmethodr  r  r  r  r   rK  rV   rV   r  rW   r     s   
        &!



	
L W "*     qC7     r   c                   @  s4   e Zd ZdZdZddddddZdd	d
dZdS )r  z
    a write-once read-many table: this format DOES NOT ALLOW appending to a
    table. writing is a one-time operation the data are stored in a format
    that allows for searching the data on disk
    r  Nr   rh  c                 C  s   t ddS )z[
        read the indices and the indexing array, calculate offset rows and return
        z!WORMTable needs to implement readNri  rj  rV   rV   rW   r
    s    
zWORMTable.readr   r   c                 K  s   t ddS )z
        write in a format that we can search later on (but cannot append
        to): write out the indices and the values using _write_array
        (e.g. a CArray) create an indexing table so that we can search
        z"WORMTable needs to implement writeNri  rk  rV   rV   rW   r  
  s    zWORMTable.write)NNNN)r   r  r  r  r  r
  r  rV   rV   rV   rW   r    s       r  c                   @  sh   e Zd ZdZdZddddddd	d
dZdddddddZddddddddZddddddZdS )r  (support the new appendable table formatsZ
appendableNFTr   r   r   )r   r   r   r:  r\   c                 C  s   |s| j r| j| jd | j||||||d}|jD ]}|  q6|j s|j||||	d}|  ||d< |jj	|jfi | |j
|j_
|jD ]}||| q|j||
d d S )Nrw   )rF  r  r>  r   r   r   )r   r   r   rG  r:  )r   )r  r   r  r   r  rF  r  r  rc  Zcreate_tabler  r  r  
write_data)r   r  rF  r   r   r   r   r   r   rG  r   r   r   r:  rw   r   optionsrV   rV   rW   r    s4    
	



zAppendableTable.write)r   r   r\   c                   s  | j j}| j}g }|rT| jD ]6}t|jjdd}t|tj	r|
|jddd qt|r|d }|dd D ]}||@ }qp| }nd}dd	 | jD }	t|	}
|
dksJ |
d
d	 | jD }dd	 |D }g }t|D ]2\}}|f| j ||
|   j }|
|| q|du r d}tjt||| j d}|| d }t|D ]x}|| t|d | |  krx q| j| fdd	|	D |dur|  nd fdd	|D d qJdS )z`
        we form the data into a 2-d including indexes,values,mask write chunk-by-chunk
        r   rN  u1Fr?  rg   Nc                 S  s   g | ]
}|j qS rV   )r  rz  rV   rV   rW   rm   o  r   z.AppendableTable.write_data.<locals>.<listcomp>c                 S  s   g | ]}|  qS rV   )r  rz  rV   rV   rW   rm   u  r   c              	   S  s,   g | ]$}| tt|j|jd  qS r  )Z	transposerR   ZrollarangerU  r9  rV   rV   rW   rm   v  r   r  r6  c                   s   g | ]}|  qS rV   rV   rz  Zend_iZstart_irV   rW   rm     r   c                   s   g | ]}|  qS rV   rV   r9  r  rV   rW   rm     r   )indexesrI  r\  )r  r  r  r  r3   r{  rJ  rQ   rR   r  r   rE  rp   rC  r  r  r  reshaper  r  rT  write_data_chunk)r   r   r   r  r  Zmasksr   rI  r  r  nindexesr\  bvaluesr  rP  Z	new_shaperowschunksrV   r  rW   r  T  sL    




zAppendableTable.write_datar  zlist[np.ndarray]znpt.NDArray[np.bool_] | None)r!  r  rI  r\  r\   c                 C  s   |D ]}t |js dS q|d jd }|t|krFt j|| jd}| jj}t|}t|D ]\}	}
|
|||	 < q^t|D ]\}	}||||	|  < q||dur| j	t
dd }| s|| }t|r| j| | j  dS )z
        Parameters
        ----------
        rows : an empty memory space where we are putting the chunk
        indexes : an array of the indexes
        mask : an array of the masks
        values : an array of the values
        Nr   r6  Fr?  )rR   r  r  rp   r  r  r  r  rC  rE  r   rJ  rw   r   r  )r   r!  r  rI  r\  rP  r  r  r  r  r  r  rV   rV   rW   r    s&    z AppendableTable.write_data_chunkrh  c                 C  sf  |d u st |sf|d u r:|d u r:| j}| jj| jdd n(|d u rH| j}| jj||d}| j  |S |  srd S | j}t	| |||d}|
 }t|dd }t |}	|	rb| }
t|
|
dk j}t |sdg}|d |	kr||	 |d dkr|dd | }t|D ]@}|t||}|j||jd  ||jd  d d |}q| j  |	S )	NTr>  rh  Fr?  rg   r   r<  )rp   r  r   r  r   rw   Zremove_rowsr  r  r  r  r0   Zsort_valuesdiffrn   r   r   r  r7  reversedr[  rT  )r   rq   r   r   r  rw   r  r\  Zsorted_serieslnr#  r   Zpgr   r!  rV   rV   rW   rD    sD    


zAppendableTable.delete)NFNNNNNNFNNT)F)NNN)	r   r  r  r  r  r  r  r  rD  rV   rV   rV   rW   r    s$               ;;,r  c                   @  s`   e Zd ZU dZdZdZdZeZde	d< e
ddd	d
ZeddddZddddddZdS )r  r  r  r  rU  rR  rS  r   r   c                 C  s   | j d jdkS )Nr   rg   )r  r,  r   rV   rV   rW   r    s    z"AppendableFrameTable.is_transposedr  c                 C  s   |r
|j }|S )zthese are written transposed)r  r  rV   rV   rW   r    s    zAppendableFrameTable.get_objectNr   rh  c                   sh    |   sd S  j|||d}t jrH j jd d i ni } fddt jD }t|dkstJ |d }|| d }	g }
t jD ]\}}| j	vrq|| \}}|ddkrt
|}n
t|}|d}|d ur|j|d	d
  jr |}|}t
|	t|	dd d}n|j}t
|	t|	dd d}|}|jdkrlt|tjrl|d|jd f}t|tjrt|j||dd}n.t|t
rt|||d}ntj|g||d}t r|jjdks|j|jk sJ |j|jft rt|d	dr|d}|
 | qt|
dkr8|
d }nt!|
dd}t" |||d} j#|||d}|S )Nr  r   c                   s"   g | ]\}}| j d  u r|qS r'  r  )ri   r  r  r   rV   rW   rm     r   z-AppendableFrameTable.read.<locals>.<listcomp>rg   r   r-   r  TZinplacerb   ra   Fr  r  r@  r  r  rN  )r  r   )$rg  r  r  rp   r(  r  r   r  rF  r  r,   r-   from_tuples	set_namesr  rl  r  rU  rQ   rR   r  r  r  r*   Z_from_arraysr   r  rf  ZdtypesrJ  r   rE  r   r2   r  r  )r   rq   r   r   r   r{  r  Zindsindr   framesr  r   Z
index_valsr  rL  r  r\  Zindex_Zcols_r  r  rV   r   rW   r
  	  sf    




"


zAppendableFrameTable.read)NNNN)r   r  r  r  rP  r  rU  r*   rS  r  r  r  rJ  r  r
  rV   rV   rV   rW   r    s   
    r  c                      st   e Zd ZdZdZdZdZeZe	ddddZ
edd	d
dZddd fddZddddd fddZ  ZS )r  r  r  r  rU  r   r   c                 C  s   dS r  rV   r   rV   rV   rW   r  f  s    z#AppendableSeriesTable.is_transposedr  c                 C  s   |S r]   rV   r  rV   rV   rW   r  j  s    z AppendableSeriesTable.get_objectNr   c                   s@   t |ts|jpd}||}t jf ||j d| dS )+we are going to write this as a frame tabler\  r  r   N)rQ   r*   rb   Zto_framer
  r  r   r  )r   r  r   r   rb   r  rV   rW   r  o  s    


zAppendableSeriesTable.writer   r0   rl  c                   s   | j }|d urB|rBt| jts"J | jD ]}||vr(|d| q(t j||||d}|rj|j| jdd |jd d df }|j	dkrd |_	|S )Nr   r+  Tr&  r\  )
r  rQ   r  rn   r  r
  r
  	set_indexr  rb   )r   rq   r   r   r   r  r   rU   r  rV   rW   r
  v  s    

zAppendableSeriesTable.read)N)NNNN)r   r  r  r  rP  r  rU  r0   rS  r  r  rJ  r  r  r
  rK  rV   rV   r  rW   r  ^  s   	    r  c                      s.   e Zd ZdZdZdZdd fddZ  ZS )r  r  r  r  r   r   c                   sb   |j pd}| |\}| _t| jts*J t| j}|| t||_t j	f d|i| dS )r+  r\  r  N)
rb   r  r  rQ   rn   r   r,   r   r
  r  )r   r  r   rb   ZnewobjrL  r  rV   rW   r    s    



z AppendableMultiSeriesTable.write)r   r  r  r  rP  r  r  rK  rV   rV   r  rW   r    s   r  c                   @  sp   e Zd ZU dZdZdZdZeZde	d< e
ddd	d
Ze
dd ZddddZedd ZddddZdS )r  z:a table that read/writes the generic pytables table formatr  r  rU  zlist[Hashable]r  rZ   r   c                 C  s   | j S r]   )rP  r   rV   rV   rW   ri    s    zGenericTable.pandas_typec                 C  s   t | jdd p| jS r  r  r   rV   rV   rW   re    s    zGenericTable.storabler   c                 C  sL   g | _ d| _g | _dd | jD | _dd | jD | _dd | jD | _dS )r  Nc                 S  s   g | ]}|j r|qS rV   r  rz  rV   rV   rW   rm     r   z*GenericTable.get_attrs.<locals>.<listcomp>c                 S  s   g | ]}|j s|qS rV   r  rz  rV   rV   rW   rm     r   c                 S  s   g | ]
}|j qS rV   ra   rz  rV   rV   rW   rm     r   )r(  r   r  r  r  r  r   r   rV   rV   rW   rd    s    zGenericTable.get_attrsc           
   
   C  s   | j }| d}|durdnd}tdd| j||d}|g}t|jD ]^\}}t|tsZJ t||}| |}|durzdnd}t	|||g|| j||d}	|
|	 qD|S )z0create the indexables from the table descriptionr   Nr  r   )rb   r,  rw   r   r  )rb   r  r\  r  rw   r   r  )r  r  r  rw   r  Z_v_namesrQ   rZ   rl  rN  r   )
r   rI  r  r   r  r  r  r   r   ra  rV   rV   rW   r    s.    


	zGenericTable.indexablesc                 K  s   t dd S )Nz cannot write on an generic tableri  )r   r   rV   rV   rW   r    s    zGenericTable.writeN)r   r  r  r  rP  r  rU  r*   rS  r  r  ri  re  rd  r   r  r  rV   rV   rV   rW   r    s   



#r  c                      sf   e Zd ZdZdZeZdZe	dZ
eddddZdd
d fddZdddd fddZ  ZS )r  za frame with a multi-indexr  rU  z^level_\d+$rZ   r   c                 C  s   dS )NZappendable_multirV   r   rV   rV   rW   r    s    z*AppendableMultiFrameTable.table_type_shortNr   c                   s|   |d u rg }n|du r |j  }| |\}| _t| jts@J | jD ]}||vrF|d| qFt jf ||d| d S )NTr   r,  )	r   r  r  r  rQ   rn   r  r
  r  )r   r  r   r   r   r  rV   rW   r    s    

zAppendableMultiFrameTable.writer   rh  c                   sD   t  j||||d}| j}|j fdd|jjD |_|S )Nr+  c                   s    g | ]} j |rd n|qS r]   )
_re_levelssearch)ri   rb   r   rV   rW   rm   	  r   z2AppendableMultiFrameTable.read.<locals>.<listcomp>)r
  r
  r-  r  r   r(  r  )r   rq   r   r   r   r  r  r   rW   r
    s    zAppendableMultiFrameTable.read)N)NNNN)r   r  r  r  r  r*   rS  rU  recompiler.  r  r  r  r
  rK  rV   rV   r  rW   r    s   
    r  r*   rI   r,   )r  r,  r  r\   c                 C  s   |  |}t|}|d ur"t|}|d u s4||rB||rB| S t| }|d urlt| j|dd}||std d g| j }|||< | jt| } | S )NF)sort)	r  r:   equalsuniquer]  slicerU  r^  ro   )r  r,  r  r  r  ZslicerrV   rV   rW   r    s    

r  r   zstr | tzinfo)r  r\   c                 C  s   t | }|S )z+for a tz-aware type, return an encoded zone)r   Zget_timezone)r  zonerV   rV   rW   r  )  s    
r  znp.ndarray | Indexr+   )r\  r  r3  r\   c                 C  s   d S r]   rV   r\  r  r3  rV   rV   rW   r  /  s    r  r  c                 C  s   d S r]   rV   r7  rV   rV   rW   r  6  s    zstr | tzinfo | Noneznp.ndarray | DatetimeIndexc                 C  s   t | tr0| jdu s"| j|ks"J | jdur0| S |dur|t | trJ| j}nd}|  } t|}t| |d} | d|} n|rtj	| dd} | S )a  
    coerce the values to a DatetimeIndex if tz is set
    preserve the input shape if possible

    Parameters
    ----------
    values : ndarray or Index
    tz : str or tzinfo
    coerce : if we do not have a passed timezone, coerce to M8[ns] ndarray
    Nra   rw  M8[ns]r6  )
rQ   r+   r  rb   rC  rX   ry  rz  rR   rB  )r\  r  r3  rb   rV   rV   rW   r  ;  s    


)rb   r   r[   r   r\   c              
   C  s  t | tsJ |j}t|\}}t|}t|}t|j	dsTt
|j	sTt|j	rzt| |||t|dd t|dd |dS t |trtdtj|dd}	t|}
|	dkrtjd	d
 |
D tjd}t| |dt  |dS |	dkrt|
||}|j	j}t| |dt ||dS |	dv r2t| ||||dS t |tjrL|j	tksPJ |dksbJ |t  }t| ||||dS d S )Niur  r  )r\  rf  r  r  r  r  zMultiIndex not supported here!Fr  r   c                 S  s   g | ]}|  qS rV   )	toordinalr9  rV   rV   rW   rm     r   z"_convert_index.<locals>.<listcomp>r6  )r  r  )integerZfloating)r\  rf  r  r  r  )rQ   rZ   rb   r  r  rL  r!  r   r  r  r$   r    r  rl  r-   r   r  rR   rB  Zint32r   Z	Time32Col_convert_string_arrayr  r  r  r  r  )rb   r   r[   r   r  rH  r  rf  r   r  r\  r  rV   rV   rW   r  b  s^    










r  )rf  r[   r   r\   c                 C  s   | dr,|dkrt| }qt| |}n|dkr>t| }n|dkrztjdd | D td}W q ty   tjdd | D td}Y q0 nT|dv rt| }n@|d	v rt| d ||d
}n&|dkrt| d }ntd| |S )Nr1  r4  r   c                 S  s   g | ]}t |qS rV   r7  r9  rV   rV   rW   rm     r   z$_unconvert_index.<locals>.<listcomp>r6  c                 S  s   g | ]}t |qS rV   r:  r9  rV   rV   rW   rm     r   )r;  floatr   r  rA  r  r   zunrecognized index type )	rt  r+   r  r1   rR   rB  r  r   rG  )r{  rf  r[   r   r   rV   rV   rW   r    s*    


 r  rH   r   )rb   r   r   c                 C  s  |j tkr|S ttj|}|j j}tj|dd}	|	dkr@td|	dkrPtd|	dksd|dksd|S t	|}
|
 }|||
< tj|dd}	|	dkrt|jd	 D ]V}|| }tj|dd}	|	dkrt||kr|| nd
| }td| d|	 dqt||||j}|j}t|tr>t|| p:|dp:d	}t|pHd	|}|d urz||}|d urz||krz|}|jd| dd}|S )NFr  r   z+[date] is not implemented as a table columnrn  z>too many timezones in this block, create separate data columnsr  r  r   zNo.zCannot serialize the column [z2]
because its data contents are not [string] but [z] object dtyper\  z|Sr?  )r  r  r   rR   r  rb   r   r  r   r3   r|  rT  r  rp   r<  r  r  rQ   rH  rd   r   r  r  rE  )rb   r   r  r   r   r[   r   r   r  r  rI  r{  r  r  Zerror_column_labelr  r  ZecirV   rV   rW   r    sN    

 

r  )r{  r[   r   r\   c                 C  s`   t | r,t|  ddj||j| j} t|  }t	dt
|}tj| d| d} | S )a  
    Take a string-like that is object dtype and coerce to a fixed size string type.

    Parameters
    ----------
    data : np.ndarray[object]
    encoding : str
    errors : str
        Handler for encoding errors.

    Returns
    -------
    np.ndarray[fixed-length-string]
    Fr?  rg   Sr6  )rp   r0   rC  rZ   encoderF  r  r  r   r  
libwritersmax_len_string_arrayrR   rB  )r{  r[   r   ensuredr  rV   rV   rW   r<    s    r<  c                 C  s   | j }tj|  td} t| rztt| }d| }t	| d t
rbt| ddjj||dj} n| j|ddjtdd} |du rd}t| | | |S )	a*  
    Inverse of _convert_string_array.

    Parameters
    ----------
    data : np.ndarray[fixed-length-string]
    nan_rep : the storage repr of NaN
    encoding : str
    errors : str
        Handler for encoding errors.

    Returns
    -------
    np.ndarray[object]
        Decoded data.
    r6  Ur   Fr?  )r   Nr  )r  rR   rB  rC  r  rp   r@  rA  r   rQ   r|  r0   rZ   rT   rF  rE  Z!string_array_replace_from_nan_repr  )r{  r   r[   r   r  r  r  rV   rV   rW   rG  '  s    
rG  )r\  r  r[   r   c                 C  s6   t |tsJ t|t|r2t|||}|| } | S r]   )rQ   rZ   r   _need_convert_get_converter)r\  r  r[   r   convrV   rV   rW   r  M  s
    r  rf  r[   r   c                   sL   dkrdd S dv r$fddS dkr: fddS t d d S )Nr1  c                 S  s   t j| ddS )Nr8  r6  rR   rB  r&  rV   rV   rW   r   W  r   z _get_converter.<locals>.<lambda>c                   s   t j|  dS )Nr6  rH  rI  r  rV   rW   r   Y  r   r  c                   s   t | d  dS )NrA  )rG  rI  r  rV   rW   r   [  s   zinvalid kind )r   rG  rV   )r[   r   rf  rW   rE  U  s    rE  r$  c                 C  s   | dv sd| v rdS dS )N)r1  r  r1  TFrV   r  rV   rV   rW   rD  b  s    rD  zSequence[int])rb   rV  r\   c                 C  sl   t |tst|dk rtd|d dkrh|d dkrh|d dkrhtd| }|rh| d }d| } | S )	z
    Prior to 0.10.1, we named values blocks like: values_block_0 an the
    name values_0, adjust the given name if necessary.

    Parameters
    ----------
    name : str
    version : Tuple[int, int, int]

    Returns
    -------
    str
       z6Version is incorrect, expected sequence of 3 integers.r   rg   rT  rU  zvalues_block_(\d+)Zvalues_)rQ   rZ   rp   r   r0  r/  r   )rb   rV  r  grprV   rV   rW   r  h  s    $
r  )	dtype_strr\   c                 C  s   t | } | drd}n| dr(d}n| dr8d}n~| drHd}nn| drX| }n^| drhd	}nN| d
rxd
}n>| drd}n.| drd}n| dkrd}ntd|  d|S )zA
    Find the "kind" string describing the given dtype name.
    )r  r|  r  r=  r  )rd   r%  r;  r1  	timedeltar4  r   r  r'  r  zcannot interpret dtype of [r$  )rX   rt  r   )rL  rf  rV   rV   rW   r    s.    








r  r  c                 C  sv   t | tr| j} t | jtr.d| jj d}n| jj}| jjdv rTt	| 
d} nt | trd| j} t	| } | |fS )zJ
    Convert the passed data into a storable form and a dtype string.
    r  r$  ZmMr  )rQ   r4   r  r  r&   r  rb   rf  rR   rB  r  r.   r  )r{  r  rV   rV   rW   r    s    


r  c                   @  s>   e Zd ZdZddddddddZd	d
 Zdd Zdd ZdS )r  z
    Carries out a selection operation on a tables.Table object.

    Parameters
    ----------
    table : a Table object
    where : list of Terms (or convertible to)
    start, stop: indices to start and/or stop selection

    Nr   r   r   )rw   r   r   r\   c                 C  sV  || _ || _|| _|| _d | _d | _d | _d | _t|rt	t
 tj|dd}|dv rt|}|jtjkr| j| j }}|d u rd}|d u r| j j}t||| | _nNt|jjtjr| jd ur|| jk  s| jd ur|| jk rt
d|| _W d    n1 s0    Y  | jd u rR| || _| jd urR| j \| _| _d S )NFr  )r;  booleanr   z3where must have index locations >= start and < stop)rw   rq   r   r   	conditionr  Ztermsr1  r"   r   r   r   r  rR   rB  r  Zbool_r  r  
issubclassr   r;  rD  generateevaluate)r   rw   rq   r   r   inferredrV   rV   rW   r     sD    


&zSelection.__init__c              
   C  s   |du rdS | j  }zt||| j jdW S  ty| } z:d| }td| d| d}t||W Y d}~n
d}~0 0 dS )z'where can be a : dict,list,tuple,stringN)r  r[   r  z-                The passed where expression: a*  
                            contains an invalid variable reference
                            all of the variable references must be a reference to
                            an axis (e.g. 'index' or 'columns'), or a data_column
                            The currently defined references are: z
                )	rw   r  r7   r[   	NameErrorr  r   r   r   )r   rq   r  rE  Zqkeysr  rV   rV   rW   rQ    s    
	zSelection.generatec                 C  sX   | j dur(| jjj| j  | j| jdS | jdurB| jj| jS | jjj| j| jdS )(
        generate the selection
        Nrh  )	rO  rw   Z
read_wherer   r   r   r1  r  r
  r   rV   rV   rW   r     s    

zSelection.selectc                 C  s   | j | j }}| jj}|du r$d}n|dk r4||7 }|du rB|}n|dk rR||7 }| jdurx| jjj| j ||ddS | jdur| jS t	||S )rU  Nr   T)r   r   r2  )
r   r   rw   r  rO  Zget_where_listr   r1  rR   r  )r   r   r   r  rV   rV   rW   r    s"    

zSelection.select_coords)NNN)r   r  r  r  r   rQ  r   r  rV   rV   rV   rW   r    s      -r  )r   NNFNTNNNNr~   rP   )	Nr   r~   NNNNFN)N)F)F)F)r  
__future__r   
contextlibr   r|  rn  r   r   r2  r   r0  textwrapr   typingr   r   r	   r
   r   r   r   r  numpyrR   Zpandas._configr   r   r   r   Zpandas._libsr   r   r@  Zpandas._libs.libr   Zpandas._libs.tslibsr   Zpandas.compat._optionalr   Zpandas.compat.pickle_compatr   Zpandas.errorsr   r   r   r   r   Zpandas.util._decoratorsr   Zpandas.util._exceptionsr   Zpandas.core.dtypes.commonr   r    r!   r"   r#   r$   Zpandas.core.dtypes.dtypesr%   r&   r'   r(   Zpandas.core.dtypes.missingr)   r   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   Zpandas.core.arraysr4   r5   r6   Zpandas.core.commoncorecommonrB  Z pandas.core.computation.pytablesr7   r8   Zpandas.core.constructionr9   Zpandas.core.indexes.apir:   Zpandas.core.internalsr;   r<   Zpandas.io.commonr=   Zpandas.io.formats.printingr>   r?   collections.abcr@   rA   rB   typesrC   r   rD   rE   rF   Zpandas._typingrG   rH   rI   rJ   rK   rL   rM   rN   rO   r`  r^   rX   r`   rc   rh   rr   rs   r  rt   ru   r  rV  rz   r{   Zconfig_prefixZregister_optionZis_boolZis_one_of_factoryr   r   r   r   r   r   r   r  r  r  r	  rL  rN  rO  rm  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r<  rG  r  rE  rD  r  r  r  r  rV   rV   rV   rW   <module>   s8  $	 0(
&            ,:                      (p  *   -  g#c       n dh1C,   '@I&!