o
    Eh                 	   @  s  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+ ddl,m-Z-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z< ddl=m>Z>m?Z?m@Z@mAZA ddlBmCZC ddlDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZO ddlPmQZQmRZRmSZS ddlTmUZU ddlVmW  mXZY ddlZm[Z[m\Z\ ddl]m^Z_m`Z` ddlambZb ddlcmdZdmeZe ddlfmgZg ddlhmiZimjZj erKddlkmlZlmmZmmnZn ddlompZp dd lqmrZrmsZsmtZt dd!lumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z} dd"lcm~Z~ d#Zd$Zd%d& Zdd+d,Zd-d. Ze[Zdd1d2Zd3Zd4ed5< d6Zd4ed7< d8Zd4ed9< d:d:d;d;d<ZeEdgiZd=Zd4ed>< d?Zd4ed@< edA  ejdBdCeejdD ejdEdeeg dFdD W d   n	1 sw   Y  dadCadGdH Z	I			C		J					K	$dddadbZ		c	K					C	dddldmZddqdrZG dsdt dtZG dudv dvZG dwdx dxZG dydz dzeZG d{d| d|eZG d}d~ d~eZG dd deZG dd dZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZ	ddddZdddZe	CddddZeddddZ	CddddZdddZdddZdddZdddZdddZdddńZdddǄZdddɄZddd̈́ZdddЄZddd҄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_string_dtype)libwriters)is_string_array)	timezones)HAS_PYARROW)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StringDtypeTimedeltaIndexconcatisna)CategoricalDatetimeArrayPeriodArray)BaseStringArray)PyTablesExprmaybe_expression)array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 unicoderT   )
isinstancenpZbytes_decode)s rY   2lib/python3.10/site-packages/pandas/io/pytables.py_ensure_decoded   s   
r[   encoding
str | Nonereturnstrc                 C  s   | d u rt } | S N)_default_encodingr\   rY   rY   rZ   _ensure_encoding   s   rc   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
    )rU   r_   namerY   rY   rZ   _ensure_str   s   
rf   scope_levelintc                   sV   |d  t | ttfr fdd| D } n
t| rt|  d} | du s't| r)| 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 )Nri   rg   )r;   Term).0ZtermlevelrY   rZ   
<listcomp>   s
    z _ensure_term.<locals>.<listcomp>rj   N)rU   listtupler;   rk   len)whererg   rY   rm   rZ   _ensure_term   s   	
rt   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)frx   try   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)Z	validatorZdefault_format)rx   ry   Nc                  C  sN   t d u r%dd l} | a tt | jjdkaW d    t S 1 s w   Y  t S )Nr   strict)
_table_modtablesr   AttributeErrorfileZ_FILE_OPEN_POLICY!_table_file_open_policy_is_strict)r   rY   rY   rZ   _tables   s   


r   aTr~   path_or_bufFilePath | HDFStorekeyvalueDataFrame | Seriesmode	complevel
int | Nonecomplibappendboolformatindexmin_itemsizeint | dict[str, int] | Nonedropnabool | Nonedata_columns Literal[True] | list[str] | NoneerrorsNonec              
     s   |r 	f
dd}n 	f
dd}t | } t| trIt| |||d}|| W d   dS 1 sBw   Y  dS ||  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   rY   rZ   <lambda>      zto_hdf.<locals>.<lambda>c                   s   | j 	 d
S )N)r   r   r   r   r   r   r\   r   putr   r   rY   rZ   r   +  r   )r   r   r   N)rA   rU   r_   HDFStore)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r\   rz   r   rY   r   rZ   to_hdf
  s    

"r   rrs   str | list | Nonestartstopcolumnslist[str] | Noneiterator	chunksizec
                 K  s  |dvrt d| d|durt|dd}t| tr'| js"td| }d}n:t| } t| ts4td	zt	j
| }W n tt fyI   d}Y nw |sTtd
|  dt| f||d|
}d}z9|du r| }t|dkrtt 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    1 sw   Y   w )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.

    Notes
    -----
    When ``errors="surrogatepass"``, ``pd.options.future.infer_string`` is true,
    and PyArrow is installed, if a UTF-16 surrogate is encountered when decoding
    to UTF-8, the resulting dtype will be
    ``pd.StringDtype(storage="python", na_value=np.nan)``.

    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.Nri   rj   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.)rs   r   r   r   r   r   
auto_close)
ValueErrorrt   rU   r   is_openOSErrorrA   r_   NotImplementedErrorospathexists	TypeErrorFileNotFoundErrorgroupsrr   _is_metadata_of_v_pathnameselectLookupErrorr   r   close)r   r   r   r   rs   r   r   r   r   r   kwargsr   r   r   r   Zcandidate_only_groupZgroup_to_checkrY   rY   rZ   read_hdfB  sv   V








r   grouprJ   parent_groupc                 C  sN   | j |j krdS | }|j dkr%|j}||kr|jdkrdS |j}|j dksdS )zDCheck if a given group is a metadata group for a given parent_group.Fri   metaT)Z_v_depthZ	_v_parent_v_name)r   r   currentparentrY   rY   rZ   r     s   

r   c                   @  s  e Zd ZU dZded< ded< 				ddddZdddZedd ZedddZ	dddZ
dddZdddZdd d!Zdd"d#Zdd%d&Zdd'd(Zdd*d+Zdd2d3Zddd7d8Zdd:d;Zdd=d>Zddd?d@ZddAdBZeddCdDZdddFdGZddHdIZ							dddMdNZ			dddQdRZ		dddTdUZ								dddVdWZ		X								Y	X	dddedfZdddgdhZ 			X	X											YdddkdlZ!			dddodpZ"			dddtduZ#ddwdxZ$ddd|d}Z%dddZ&dddZ'		X					XddddZ(dddZ)dddZ*dddZ+				YddddZ,		X												Y	XddddZ-dddZ.dddZ/ddd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_handler_   _moder   NFr   r   r   
fletcher32r   r^   r   c                 K  s   d|v rt dtd}|d ur ||jjvr t d|jj d|d u r,|d ur,|jj}t|| _|d u r7d}|| _d | _|rA|nd| _	|| _
|| _d | _| jd	d|i| d S )
Nr   z-format is not a defined argument for HDFStorer   zcomplib only supports z compression.r   r   r   rY   )r   r   filtersZall_complibsZdefault_complibrA   _pathr   r   
_complevel_complib_fletcher32_filtersopen)selfr   r   r   r   r   r   r   rY   rY   rZ   __init__7  s&   	
zHDFStore.__init__c                 C     | j S r`   r   r   rY   rY   rZ   
__fspath__X  s   zHDFStore.__fspath__c                 C  s   |    | jdusJ | jjS )zreturn the root nodeN)_check_if_openr   rootr   rY   rY   rZ   r   [  s   zHDFStore.rootc                 C  r   r`   r   r   rY   rY   rZ   filenameb     zHDFStore.filenamer   c                 C  
   |  |S r`   )getr   r   rY   rY   rZ   __getitem__f     
zHDFStore.__getitem__c                 C  s   |  || d S r`   r   )r   r   r   rY   rY   rZ   __setitem__i  s   zHDFStore.__setitem__c                 C  r   r`   )remover   rY   rY   rZ   __delitem__l  r   zHDFStore.__delitem__re   c              	   C  s@   z|  |W S  ttfy   Y nw tdt| j d| d)z$allow attribute access to get stores'z' object has no attribute ')r   KeyErrorr   r   type__name__)r   re   rY   rY   rZ   __getattr__o  s   zHDFStore.__getattr__c                 C  s4   |  |}|dur|j}|||dd fv rdS dS )zx
        check for existence of this key
        can match the exact pathname or the pathnm w/o the leading '/'
        Nri   TF)get_noder   )r   r   nodere   rY   rY   rZ   __contains__y  s   
zHDFStore.__contains__rh   c                 C     t |  S r`   )rr   r   r   rY   rY   rZ   __len__     zHDFStore.__len__c                 C  s   t | j}t|  d| dS )N
File path: 
)rC   r   r   )r   ZpstrrY   rY   rZ   __repr__  s   
zHDFStore.__repr__rP   c                 C  s   | S r`   rY   r   rY   rY   rZ   	__enter__     zHDFStore.__enter__exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebackTracebackType | Nonec                 C     |    d S r`   )r   )r   r   r   r   rY   rY   rZ   __exit__  s   zHDFStore.__exit__pandasinclude	list[str]c                 C  sZ   |dkrdd |   D S |dkr%| jdusJ dd | jjddd	D S td
| d)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     g | ]}|j qS rY   r   rl   nrY   rY   rZ   ro         z!HDFStore.keys.<locals>.<listcomp>ZnativeNc                 S  r   rY   r   r   rY   rY   rZ   ro     s    /Table)Z	classnamez8`include` should be either 'pandas' or 'native' but is 'r   )r   r   Z
walk_nodesr   )r   r   rY   rY   rZ   keys  s   
zHDFStore.keysIterator[str]c                 C  r   r`   )iterr  r   rY   rY   rZ   __iter__  r   zHDFStore.__iter__Iterator[tuple[str, list]]c                 c  s     |   D ]}|j|fV  qdS )z'
        iterate on key->group
        N)r   r   )r   grY   rY   rZ   items  s   zHDFStore.itemsc                 K  s   t  }| j|kr)| jdv r|dv rn|dv r&| jr&td| j d| j d|| _| jr0|   | jrE| jdkrEt  j| j| j| j	d| _
trP| jrPd	}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   Z	open_filer   )r   r   r   r   msgrY   rY   rZ   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   rY   rY   rZ   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   rY   rY   rZ   r      s   
zHDFStore.is_openfsyncc                 C  s^   | j dur+| j   |r-tt t| j   W d   dS 1 s$w   Y  dS dS 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  rY   rY   rZ   r  	  s   


"zHDFStore.flushc                 C  sV   t   | |}|du rtd| d| |W  d   S 1 s$w   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   rY   rY   rZ   r     s   
$zHDFStore.getr   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  ri   rj   c                   s   j | || dS )N)r   r   rs   r   read_start_stop_wherer   rX   rY   rZ   func  s   zHDFStore.select.<locals>.funcrs   nrowsr   r   r   r   r   )r   r   rt   _create_storer
infer_axesTableIteratorr  
get_result)r   r   rs   r   r   r   r   r   r   r   r  itrY   r  rZ   r   <  s(   
@
zHDFStore.selectr   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
        ri   rj   z&can only read_coordinates with a tablers   r   r   )rt   
get_storerrU   r  r   read_coordinates)r   r   rs   r   r   tblrY   rY   rZ   select_as_coordinates  s
   

zHDFStore.select_as_coordinatescolumnc                 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%  rU   r  r   read_column)r   r   r)  r   r   r'  rY   rY   rZ   select_column  s   
#
zHDFStore.select_columnc
                   st  t |dd}t|ttfrt|dkr|d }t|tr)j|||||||	dS t|ttfs4tdt|s<td|du rD|d }fdd	|D 	|}
d}t
|
|fgt|D ]-\}}|du rptd
| d|js|td|j d|du r|j}q`|j|krtdq`d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
        ri   rj   r   )r   rs   r   r   r   r   r   r   zkeys must be a list/tuplez keys must have a non-zero lengthNc                      g | ]}  |qS rY   )r%  rl   kr   rY   rZ   ro   %      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 rY   )rU   r  rl   xrY   rY   rZ   ro   :      c                 S  s   h | ]	}|j d  d  qS r   )non_index_axesrl   r{   rY   rY   rZ   	<setcomp>=  r3  z.HDFStore.select_as_multiple.<locals>.<setcomp>c                   s*    fddD }t |dd S )Nc                   s   g | ]}|j  d qS )rs   r   r   r   r  r6  )r  r  r  r   rY   rZ   ro   B  s    z=HDFStore.select_as_multiple.<locals>.func.<locals>.<listcomp>F)axisverify_integrity)r4   _consolidate)r  r  r  Zobjs)r9  r   tblsr  rZ   r  ?  s   z)HDFStore.select_as_multiple.<locals>.funcr  T)coordinates)rt   rU   rp   rq   rr   r_   r   r   r   r%  	itertoolschainzipr   is_tablepathnamer  popr!  r"  )r   r  rs   selectorr   r   r   r   r   r   rX   r  r{   r.  Z_tblsr  r#  rY   )r9  r   r   r<  rZ   select_as_multiple  sf   +

 
zHDFStore.select_as_multipleTr~   r   r   r   r   r   r   r   r   r   track_timesr   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_formatrx   )r   r   r   r   r   r   r   r   r\   r   rF  r   )r   _validate_format_write_to_group)r   r   r   r   r   r   r   r   r   r   r   r\   r   rF  r   rY   rY   rZ   r   Z  s&   8

zHDFStore.putc              
   C  s   t |dd}z| |}W n? ty     ty     tyL } z%|dur,td|| |}|durB|jdd W Y d}~dS W Y d}~nd}~ww t	|||r]|j
jdd dS |jsdtd|j|||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

        ri   rj   Nz5trying to remove a node with a non-None where clause!T	recursivez7can only remove with where on objects written as tablesr$  )rt   r%  r   AssertionError	Exceptionr   r   Z	_f_removecomall_noner   rA  delete)r   r   rs   r   r   rX   errr   rY   rY   rZ   r     s8   
zHDFStore.removebool | list[str]r   c                 C  sl   |	durt d|du rtd}|du rtdpd}| |}| 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_tablerG  ry   )r   axesr   r   r   r   r   r   r   expectedrowsr   r   r\   r   )r   r   rH  rI  )r   r   r   r   rS  r   r   r   r   r   r   r   r   rT  r   r   r\   r   rY   rY   rZ   r     s6   I

zHDFStore.appendddictc                   s  |durt dt|tstd||vrtdttttjtt	t
  }d}	g }
| D ]\}  du rG|	durDtd|}	q4|
  q4|	durkj| }|t|
}t||}||||	< |du rs|| }|rfdd| D }t|}|D ]}||}qj| |dd}| D ]1\} ||kr|nd}j |d	}|dur fd
d| D nd}| j||f||d| qd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)ZhowN)r   r   )rl   cols)r   rY   rZ   	<genexpr>  s     z.HDFStore.append_to_multiple.<locals>.<genexpr>r   r9  c                   s   i | ]\}}| v r||qS rY   rY   rl   r   r   )vrY   rZ   
<dictcomp>  s    z/HDFStore.append_to_multiple.<locals>.<dictcomp>)r   r   )r   rU   rV  r   nextr  setrangendim	_AXES_MAPr   r
  extendrS  
differencer-   sortedget_indexertakevaluesintersectionlocrC  reindexr   )r   rU  r   rD  r   rS  r   r   r9  Z
remain_keyZremain_valuesr.  orderedZorddZidxsZvalid_indexr   r   dcvalZfilteredrY   )r\  r   rZ   append_to_multipleE  s\   
&

zHDFStore.append_to_multiple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   rp  rq  )r   r%  rU   r  r   create_index)r   r   r   rp  rq  rX   rY   rY   rZ   create_table_index  s   

zHDFStore.create_table_indexrp   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 | ]$}t |tjjs&t|jd ds$t|dds$t |tjjr&|jdkr|qS )pandas_typeNry   )	rU   r   linkZLinkgetattr_v_attrsry   r  r   )rl   r	  rY   rY   rZ   ro     s    

z#HDFStore.groups.<locals>.<listcomp>)r   r   r   r   walk_groupsr   rY   rY   rZ   r     s   zHDFStore.groupsr  rs   *Iterator[tuple[str, list[str], list[str]]]c                 c  s    t   |   | jdusJ tdusJ | j|D ]A}t|jdddur'qg }g }|j D ]!}t|jdd}|du rKt	|tj
jrJ||j q0||j q0|jd||fV  qd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
        Nrt  r  )r   r   r   r   rx  rv  rw  Z_v_childrenrh  rU   r   ZGroupr   r   r   rstrip)r   rs   r	  r   Zleaveschildrt  rY   rY   rZ   walk  s&   'zHDFStore.walkNode | Nonec                 C  s~   |    |dsd| }| jdusJ tdusJ z
| j| j|}W n tjjy0   Y dS w t|tj	s=J t
||S )z9return the node with the key or None if it does not existr  N)r   
startswithr   r   r   r   
exceptionsZNoSuchNodeErrorrU   rJ   r   )r   r   r   rY   rY   rZ   r   1  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   rX   rY   rY   rZ   r%  A  s   

zHDFStore.get_storerr  propindexes	overwritec	              	   C  s   t |||||d}	|du rt|  }t|ttfs|g}|D ]E}
| |
}|durd|
|	v r5|r5|	|
 | |
}t|tr[d}|rKd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     g | ]}|j r|jqS rY   )
is_indexedre   rl   r   rY   rY   rZ   ro   y      z!HDFStore.copy.<locals>.<listcomp>r   )r   r   r\   rb   )r   rp   r  rU   rq   r%  r   r   r  rS  r   rv  r\   r   )r   r   r   r  r  r   r   r   r  Z	new_storer.  rX   datar   rY   rY   rZ   copyK  s8   





zHDFStore.copyc           
      C  s  t | j}t|  d| d}| jr~t|  }t|rxg }g }|D ]K}z| |}|durA|t |j	p5| |t |p>d W q" t
yJ     tym } z|| t |}	|d|	 d W Y d}~q"d}~ww |td||7 }|S |d7 }|S |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: r0     ZEmptyzFile is CLOSED)rC   r   r   r   re  r  rr   r%  r   rB  rL  rM  rB   )
r   r   outputZlkeysr  rh  r.  rX   ZdetailZdstrrY   rY   rZ   info  s8   


zHDFStore.infoc                 C  s   | j st| j dd S )Nz file is not open!)r   r   r   r   rY   rY   rZ   r     s   zHDFStore._check_if_openr   c              
   C  s>   z	t |  }W |S  ty } z	td| d|d}~ww )zvalidate / deprecate formatsz#invalid HDFStore format specified [r0  N)_FORMAT_MAPlowerr   r   )r   r   rQ  rY   rY   rZ   rH    s   zHDFStore._validate_formatrT   DataFrame | Series | Noner\   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 rZ|du rHt  tdus2J t|dds?t |tj	j
rDd}d}ntdt |trPd	}nd
}|dkrZ|d7 }d|vrttd}z|| }	W n ty }
 ztd| dt| d| |
d}
~
ww |	| |||dS |du r|dur|dkrt|dd}|dur|jdkrd}n%|jdkrd}n|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 n ty }
 ztd| dt| d| |
d}
~
ww |	| |||dS )z"return a suitable class to operateNz(value must be None, Series, or DataFramert  
table_typery   frame_tablegeneric_tablezKcannot create a storer if the object is not existing nor a value are passedseriesframeZ_table)r  r  z=cannot properly create the storer for: [_STORER_MAP] [group->,value->z	,format->r\   r   series_tabler   ri   appendable_seriesappendable_multiseriesappendable_frameappendable_multiframe)r  r  r  r  r  wormz<cannot properly create the storer for: [_TABLE_MAP] [group->)rU   r1   r+   r   r[   rv  rw  r   r   ry   r  SeriesFixed
FrameFixedr   r   nlevelsGenericTableAppendableSeriesTableAppendableMultiSeriesTableAppendableFrameTableAppendableMultiFrameTable	WORMTable)r   r   r   r   r\   r   ptttZ_STORER_MAPclsrQ  r   Z
_TABLE_MAPrY   rY   rZ   r    s   





zHDFStore._create_storerc                 C  s   t |dd r|dks|rd S | ||}| j|||||d}|r9|jr-|jr1|dkr1|jr1td|js8|  n|  |jsF|rFtd|j||||||	|
||||||d t|t	rg|ri|j
|d d S d S d S )	Nemptyry   r  rx   zCan only append to Tablesz0Compression not supported on Fixed format stores)objrS  r   r   r   r   r   r   rT  r   r   r   rF  )r   )rv  _identify_groupr  rA  	is_existsr   set_object_infowriterU   r  rr  )r   r   r   r   rS  r   r   r   r   r   r   r   rT  r   r   r   r\   r   rF  r   rX   rY   rY   rZ   rI  $  s>   
zHDFStore._write_to_groupr   rJ   c                 C  s   |  |}|  | S r`   )r  r   r  )r   r   rX   rY   rY   rZ   r  b  s   
zHDFStore._read_groupc                 C  sN   |  |}| jdusJ |dur|s| jj|dd d}|du r%| |}|S )z@Identify HDF5 group based on key, delete/create group if needed.NTrJ  )r   r   remove_node_create_nodes_and_group)r   r   r   r   rY   rY   rZ   r  g  s   

zHDFStore._identify_groupc                 C  sv   | j dusJ |d}d}|D ](}t|sq|}|ds"|d7 }||7 }| |}|du r6| j ||}|}q|S )z,Create nodes from key and return group name.Nr  )r   splitrr   endswithr   Zcreate_group)r   r   pathsr   pnew_pathr   rY   rY   rZ   r  y  s   


z HDFStore._create_nodes_and_group)r   NNF)r   r_   r   r   r   r   r^   r   r^   r_   r   r_   )r   r_   r^   r   )re   r_   )r   r_   r^   r   r^   rh   )r^   rP   )r   r   r   r   r   r   r^   r   )r   )r   r_   r^   r   )r^   r  )r^   r  )r   )r   r_   r^   r   r^   r   r^   r   F)r  r   r^   r   )NNNNFNF)r   r_   r   r   r   r   r   r   NNNr   r_   r   r   r   r   NN)r   r_   r)  r_   r   r   r   r   )NNNNNFNF)r   r   r   r   r   r   )NTFNNNNNNr~   TF)r   r_   r   r   r   r   r   r   r   r   r   r   r   r   r   r_   rF  r   r   r   r^   r   )NNTTNNNNNNNNNNr~   )r   r_   r   r   r   rR  r   r   r   r   r   r   r   r   r   r   r   r   r   r_   r^   r   )NNF)rU  rV  r   r   r^   r   )r   r_   rp  r   rq  r]   r^   r   )r^   rp   )r  )rs   r_   r^   ry  )r   r_   r^   r}  )r   r_   r^   r  )r  TNNNFT)r   r_   r  r   r   r   r   r   r  r   r^   r   )r   r_   r^   r_   )NNrT   r~   )r   r  r\   r_   r   r_   r^   r  )NTFNNNNNNFNNNr~   T)r   r_   r   r   r   rR  r   r   r   r   r   r   r   r   r   r   r   r_   rF  r   r^   r   )r   rJ   )r   r_   r   r   r^   rJ   )r   r_   r^   rJ   )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+  rE  r   r   r   ro  rs  r   r|  r   r%  r  r  r   rH  r  rI  r  r  r  rY   rY   rY   rZ   r     s
  
 A
!











*

-
 `$+}L=kd
('
<

;
5
`
>
r   c                   @  s`   e Zd ZU dZded< ded< ded< 							ddddZdddZdddZ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   r  rX   NFr   r   r   r^   r   c                 C  s   || _ || _|| _|| _| jjr'|d u rd}|d u rd}|d u r"|}t||}|| _|| _|| _d | _	|s9|	d urE|	d u r?d}	t
|	| _nd | _|
| _d S )Nr   順 )r   rX   r  rs   rA  minr  r   r   r=  rh   r   r   )r   r   rX   r  rs   r  r   r   r   r   r   rY   rY   rZ   r     s,   

zTableIterator.__init__rE   c                 c  s    | j }| jd u rtd|| jk r:t|| j | j}| d d | j|| }|}|d u s1t|s2q|V  || jk s|   d S )Nz*Cannot iterate until get_result is called.)	r   r=  r   r   r  r   r  rr   r   )r   r   r   r   rY   rY   rZ   r    s   


	zTableIterator.__iter__c                 C  s   | j r
| j  d S d S r`   )r   r   r   r   rY   rY   rZ   r     s   zTableIterator.closer=  c                 C  s   | j d urt| jtstd| jj| jd| _| S |r3t| jts&td| jj| j| j| j	d}n| j}| 
| j| j	|}|   |S )Nz0can only use an iterator or chunksize on a table)rs   z$can only read_coordinates on a tabler$  )r   rU   rX   r  r   r&  rs   r=  r   r   r  r   )r   r=  rs   resultsrY   rY   rZ   r"    s   
zTableIterator.get_result)NNFNF)r   r   rX   r  r   r   r   r   r   r   r^   r   r^   rE   r  r  )r=  r   )	r   r  r  r  r  r   r  r   r"  rY   rY   rY   rZ   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													dMdNddZe	dOddZ
e	dPddZdQddZdPddZdRddZdSddZe	dSd d!ZdTd'd(Zd)d* Ze	d+d, Ze	d-d. Ze	d/d0 Ze	d1d2 ZdUd4d5ZdVdWd6d7ZdWd8d9ZdXd=d>ZdVd?d@ZdYdAdBZdWdCdDZdWdEdFZdWdGdHZdZdIdJZ dZdKdLZ!dS )[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_nameNre   r_   cnamer]   r^   r   c                 C  s   t |ts	td|| _|| _|| _|| _|p|| _|| _|| _	|| _
|	| _|
| _|| _|| _|| _|| _|d ur>| | t | jtsFJ t | jtsNJ d S )Nz`name` must be a str.)rU   r_   r   rh  rq  typre   r  r9  posr  r  r  rl  ry   r   metadataset_pos)r   re   rh  rq  r  r  r9  r  r  r  r  rl  ry   r   r  rY   rY   rZ   r     s(   


zIndexCol.__init__rh   c                 C     | j jS r`   )r  itemsizer   rY   rY   rZ   r  <  s   zIndexCol.itemsizec                 C     | j  dS )N_kindrd   r   rY   rY   rZ   	kind_attrA     zIndexCol.kind_attrr  c                 C  s,   || _ |dur| jdur|| j_dS dS dS )z,set the position of this column in the TableN)r  r  Z_v_pos)r   r  rY   rY   rZ   r  E  s   zIndexCol.set_posc                 C  @   t tt| j| j| j| j| jf}ddd t	g d|D S )N,c                 S     g | ]\}}| d | qS z->rY   r[  rY   rY   rZ   ro   P      z%IndexCol.__repr__.<locals>.<listcomp>)re   r  r9  r  rq  )
rq   maprC   re   r  r9  r  rq  joinr@  r   ZtemprY   rY   rZ   r   K  s   zIndexCol.__repr__otherobjectc                      t  fdddD S )compare 2 col itemsc                 3  (    | ]}t |d t  |d kV  qd S r`   rv  r  r  r   rY   rZ   rY  X  
    
z"IndexCol.__eq__.<locals>.<genexpr>)re   r  r9  r  rW  r   r  rY   r  rZ   __eq__V     zIndexCol.__eq__c                 C  s   |  | S r`   )r  r  rY   rY   rZ   __ne__]  r   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 columnrX  F)hasattrry   rv  rX  r  r  r   rY   rY   rZ   r  `  s   zIndexCol.is_indexedrh  
np.ndarrayr\   r   3tuple[np.ndarray, np.ndarray] | tuple[Index, Index]c              
   C  st  t |tjsJ t||jjdur|| j  }t| j	}t
||||}i }t| j|d< | jdur:t| j|d< t}t|jdsIt |jtrLt}n|jdkrYd|v rYdd }z
||fi |}W nL ty }	 z(|dkrtd	rt|	d
rtr||fdtdtjdi|}n W Y d}	~	nd}	~	w ty   d|v rd|d< ||fi |}Y nw t|| j}
|
|
fS )zV
        Convert the data from this selection to the appropriate pandas type.
        Nre   r  Mi8c                 [  s    t j| |dd d|d S )Nr  )r  re   )r/   Zfrom_ordinalsr   Z_rename)r2  kwdsrY   rY   rZ   r     s    z"IndexCol.convert.<locals>.<lambda>surrogatepassfuture.infer_stringsurrogates not alloweddtypepythonZstoragena_value)rU   rV   ndarrayr   r  fieldsr  r  r[   rq  _maybe_convertr  r  r-   r   is_np_dtyper'   r,   UnicodeEncodeErrorr   r_   r  r   r2   nanr   _set_tzr  )r   rh  r   r\   r   val_kindr   factoryZnew_pd_indexrQ  Zfinal_pd_indexrY   rY   rZ   converth  sV   

zIndexCol.convertc                 C  r   )zreturn the valuesrh  r   rY   rY   rZ   	take_data  r   zIndexCol.take_datac                 C  r  r`   )ry   rw  r   rY   rY   rZ   attrs     zIndexCol.attrsc                 C  r  r`   ry   descriptionr   rY   rY   rZ   r	    r  zIndexCol.descriptionc                 C  s   t | j| jdS )z!return my current col descriptionN)rv  r	  r  r   rY   rY   rZ   col     zIndexCol.colc                 C  r   zreturn my cython valuesr  r   rY   rY   rZ   cvalues     zIndexCol.cvaluesrE   c                 C  s
   t | jS r`   )r  rh  r   rY   rY   rZ   r    r   zIndexCol.__iter__c                 C  s\   t | jdkr(t|tr|| j}|dur*| jj|k r,t j	|| j
d| _dS dS dS 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  )r[   rq  rU   rV  r   re   r  r  r   	StringColr  )r   r   rY   rY   rZ   maybe_set_size  s   
zIndexCol.maybe_set_sizec                 C     d S r`   rY   r   rY   rY   rZ   validate_names  r   zIndexCol.validate_nameshandlerAppendableTabler   c                 C  s:   |j | _ |   | | | | | | |   d S r`   )ry   validate_colvalidate_attrvalidate_metadatawrite_metadataset_attr)r   r  r   rY   rY   rZ   validate_and_set  s   


zIndexCol.validate_and_setc                 C  s^   t | jdkr-| j}|dur-|du r| j}|j|k r*t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)r[   rq  r
  r  r   r  )r   r  crY   rY   rZ   r    s   
zIndexCol.validate_colc                 C  sJ   |rt | j| jd }|d ur!|| jkr#td| d| j dd S d S d S )Nzincompatible kind in col [ - r0  )rv  r  r  rq  r   )r   r   Zexisting_kindrY   rY   rZ   r    s   zIndexCol.validate_attrc                 C  s   | j D ]]}t| |d}|| ji }||}||v rT|durT||krT|dv rBt|||f }tj|tt	 d d||< t
| |d qtd| j d| d| d| d	|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 [r0  )_info_fieldsrv  
setdefaultre   r   rv   warningswarnr   r   setattrr   )r   r  r   r   idxZexisting_valuewsrY   rY   rZ   update_info  s.   

zIndexCol.update_infoc                 C  s(   | | j}|dur| j| dS dS )z!set my state from the passed infoN)r   re   __dict__update)r   r  r%  rY   rY   rZ   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  rq  r   rY   rY   rZ   r  	     zIndexCol.set_attrc                 C  sT   | j dkr"| j}|| j}|dur$|dur&t||ddds(tddS dS dS 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_metadatarY   rY   rZ   r  	  s   
zIndexCol.validate_metadatac                 C  s"   | j dur|| j| j  dS dS )zset the meta dataN)r  r  r  )r   r  rY   rY   rZ   r  /	  s   
zIndexCol.write_metadata)NNNNNNNNNNNNN)re   r_   r  r]   r^   r   r  r  )r  rh   r^   r   r  r  r^   r   r  )rh  r  r\   r_   r   r_   r^   r  r  r`   r  )r  r  r   r   r^   r   )r   r   r^   r   )r  r  r^   r   )"r   r  r  r  r  r  r  r   r   r  r  r  r  r   r  r  r  r  r  r  r	  r
  r  r  r  r  r  r  r  r'  r*  r  r  r  rY   rY   rY   rZ   r    sd   
 +




@









	


r  c                   @  s2   e Zd ZdZedddZdddZdddZdS )GenericIndexColz:an index which is not represented in the data of the tabler^   r   c                 C     dS NFrY   r   rY   rY   rZ   r  8	     zGenericIndexCol.is_indexedrh  r  r\   r_   r   tuple[Index, Index]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
        )rU   rV   r  r   r0   rr   )r   rh  r   r\   r   r   rY   rY   rZ   r  <	  s   zGenericIndexCol.convertr   c                 C  r  r`   rY   r   rY   rY   rZ   r  N	  r   zGenericIndexCol.set_attrNr  )rh  r  r\   r_   r   r_   r^   r4  r  )r   r  r  r  r  r  r  r  rY   rY   rY   rZ   r0  5	  s    
r0  c                      s  e Zd ZdZdZdZddgZ												d>d? fddZed@ddZ	ed@ddZ
d@ddZdAddZdBddZdd  ZedCd#d$Zed%d& ZedDd)d*ZedEd+d,Zed-d. Zed/d0 Zed1d2 Zed3d4 ZdFd5d6ZdGd:d;ZdFd<d=Z  ZS )H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  rl  Nre   r_   r  r]   r  DtypeArg | Noner^   r   c                   s2   t  j|||||||||	|
|d || _|| _d S )N)re   rh  rq  r  r  r  r  rl  ry   r   r  )superr   r  r  )r   re   rh  rq  r  r  r  r  rl  ry   r   r  r  r  	__class__rY   rZ   r   c	  s   
zDataCol.__init__c                 C  r  )N_dtyperd   r   rY   rY   rZ   
dtype_attr	  r  zDataCol.dtype_attrc                 C  r  )N_metard   r   rY   rY   rZ   	meta_attr	  r  zDataCol.meta_attrc                 C  r  )Nr  c                 S  r  r  rY   r[  rY   rY   rZ   ro   	  r  z$DataCol.__repr__.<locals>.<listcomp>)re   r  r  rq  shape)
rq   r  rC   re   r  r  rq  r>  r  r@  r  rY   rY   rZ   r   	  s   zDataCol.__repr__r  r  r   c                   r  )r  c                 3  r  r`   r  r  r  rY   rZ   rY  	  r  z!DataCol.__eq__.<locals>.<genexpr>)re   r  r  r  r  r  rY   r  rZ   r  	  r  zDataCol.__eq__r  rL   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_kindrq  )r   r  
dtype_namerY   rY   rZ   set_data	  s   zDataCol.set_datac                 C  r   )zreturn the datar  r   rY   rY   rZ   r  	  r   zDataCol.take_datarh  rH   c                 C  s   |j }|j}|j}|jdkrd|jf}t|tr&|j}| j||j j	d}|S t
|ds1t|tr8| |}|S t
|drE| |}|S t|rUt j||d d}|S t|ra| ||}|S | j||j	d}|S )zW
        Get an appropriately typed and shaped pytables.Col object for values.
        ri   rq  r  mr   r  r>  )r  r  r>  ra  sizerU   r6   codesget_atom_datare   r   r  r'   get_atom_datetime64get_atom_timedelta64r"   r   Z
ComplexColr$   get_atom_string)r  rh  r  r  r>  rH  atomrY   rY   rZ   	_get_atom	  s.   





zDataCol._get_atomc                 C  s   t  j||d dS )Nr   rF  r   r  r  r>  r  rY   rY   rZ   rL  	     zDataCol.get_atom_stringrq  	type[Col]c                 C  sR   | dr|dd }d| d}n| drd}n	| }| d}tt |S )z0return the PyTables column class for this columnuint   NZUIntrH   periodInt64Col)r~  
capitalizerv  r   )r  rq  Zk4Zcol_nameZkcaprY   rY   rZ   get_atom_coltype	  s   


zDataCol.get_atom_coltypec                 C  s   | j |d|d dS )NrD  r   r>  rX  r  r>  rq  rY   rY   rZ   rI  	  r+  zDataCol.get_atom_datac                 C     t  j|d dS Nr   rY  r   rV  r  r>  rY   rY   rZ   rJ  	     zDataCol.get_atom_datetime64c                 C  r\  r]  r^  r_  rY   rY   rZ   rK  	  r`  zDataCol.get_atom_timedelta64c                 C     t | jdd S )Nr>  )rv  r  r   rY   rY   rZ   r>  	     zDataCol.shapec                 C  r   r  rC  r   rY   rY   rZ   r  	  r  zDataCol.cvaluesc                 C  sh   |r.t | j| jd}|dur|t| jkrtdt | j| jd}|dur0|| jkr2tddS dS 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!)rv  r  r  rp   rh  r   r;  r  )r   r   Zexisting_fieldsZexisting_dtyperY   rY   rZ   r  	  s   zDataCol.validate_attrr  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sRJ t|}|drct||dd}n|dkrotj|dd}n|dkrztjd	d
 |D td}W nl ty   tjdd
 |D td}Y nXw |dkr|	}| }|du rtg tjd}nt|}| r||  }||dk  |t j8  < tj|||
dd}nz	|j|dd}W n t y   |jddd}Y nw t|dkrt!||||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     g | ]}t |qS rY   r   Zfromordinalrl   r\  rY   rY   rZ   ro   9
  r/  z#DataCol.convert.<locals>.<listcomp>c                 S  ri  rY   r   Zfromtimestamprk  rY   rY   rZ   ro   =
  r/  r,  F)
categoriesrl  validater  Or  r   r\   r   )#rU   rV   r  r   r  r  r  r  r?  r@  rq  r[   r   r  rl  r  r~  r   asarrayr  r   ravelr-   Zfloat64r5   anyastyperh   Zcumsum_valuesr6   Z
from_codesr   _unconvert_string_arrayrh  )r   rh  r   r\   r   	convertedrA  rq  r   r  rl  r  r  rn  rH  maskrY   rY   rZ   r  
  sj   







 
zDataCol.convertc                 C  sH   t | j| j| j t | j| j| j | jdusJ t | j| j| j dS )zset the data for this columnN)r$  r  r  rh  r=  r   r  r;  r   rY   rY   rZ   r  f
  s   zDataCol.set_attr)NNNNNNNNNNNN)re   r_   r  r]   r  r6  r^   r   r  r/  )r  rL   r^   r   )rh  rL   r^   rH   )rq  r_   r^   rR  rq  r_   r^   rH   r  )rh  r  r\   r_   r   r_   )r   r  r  r  r  r  r   r   r  r;  r=  r   r  rB  r  classmethodrN  rL  rX  rI  rJ  rK  r>  r  r  r  r  __classcell__rY   rY   r8  rZ   r5  R	  sZ     










dr5  c                   @  sP   e Zd ZdZdZdddZedd Ze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-   rh  r  r   r   rY   rY   rZ   r  s
  s   zDataIndexableCol.validate_namesc                 C  s   t  j|dS )N)r  rO  rP  rY   rY   rZ   rL  x
  rb  z DataIndexableCol.get_atom_stringrq  r_   rH   c                 C  s   | j |d S )NrD  rZ  r[  rY   rY   rZ   rI  |
  rb  zDataIndexableCol.get_atom_datac                 C  
   t   S r`   r^  r_  rY   rY   rZ   rJ  
     
z$DataIndexableCol.get_atom_datetime64c                 C  r  r`   r^  r_  rY   rY   rZ   rK  
  r  z%DataIndexableCol.get_atom_timedelta64Nr  r{  )r   r  r  r  r  r  r|  rL  rI  rJ  rK  rY   rY   rY   rZ   r~  n
  s    


r~  c                   @  s   e Zd ZdZdS )GenericDataIndexableColz(represent a generic pytables data columnN)r   r  r  r  rY   rY   rY   rZ   r  
  s    r  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< 		dPdQddZedRddZ	edSddZ
edd  ZdTd!d"ZdUd#d$ZdVd%d&Zed'd( Zed)d* Zed+d, Zed-d. ZedWd/d0ZedRd1d2Zed3d4 ZdUd5d6ZdUd7d8Zed9d: ZedRd;d<Zed=d> ZdXd@dAZdYdUdCdDZdRdEdFZ	B	B	B	BdZd[dJdKZdUdLdMZ	Bd\d]dNdOZ dBS )^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.
    r_   pandas_kindrx   format_typetype[DataFrame | Series]obj_typerh   ra  r   r   Fr   rA  rT   r~   r   rJ   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`   )
rU   r   r   r   rJ   r   r   rc   r\   r   )r   r   r   r\   r   rY   rY   rZ   r   
  s   

zFixed.__init__c                 C  s*   | j d dko| j d dko| j d dk S )Nr   ri   
      )versionr   rY   rY   rZ   is_old_version
  s   *zFixed.is_old_versiontuple[int, int, int]c                 C  sf   t t| jjdd}ztdd |dD }t|dkr$|d }W |S W |S  ty2   d}Y |S w )	zcompute and set our versionpandas_versionNc                 s  s    | ]}t |V  qd S r`   rh   r1  rY   rY   rZ   rY  
  s    z Fixed.version.<locals>.<genexpr>.r  r4  )r   r   r   )r[   rv  r   rw  rq   r  rr   r   )r   r  rY   rY   rZ   r  
  s   
zFixed.versionc                 C  s   t t| jjdd S )Nrt  )r[   rv  r   rw  r   rY   rY   rZ   rt  
  rQ  zFixed.pandas_typec                 C  s^   |    | j}|dur,t|ttfr"ddd |D }d| d}| jdd| d	S | jS )
(return a pretty representation of myselfNr  c                 S     g | ]}t |qS rY   rC   r1  rY   rY   rZ   ro   
      z"Fixed.__repr__.<locals>.<listcomp>[r0  12.12z	 (shape->))r   r>  rU   rp   rq   r  rt  )r   rX   ZjshaperY   rY   rZ   r   
  s   zFixed.__repr__c                 C  s   t | j| j_t t| j_dS )zset my pandas type & versionN)r_   r  r  rt  _versionr  r   rY   rY   rZ   r  
  s   zFixed.set_object_infoc                 C  s   t  | }|S r`   rp  )r   Znew_selfrY   rY   rZ   r  
  s   
z
Fixed.copyc                 C  r   r`   )r  r   rY   rY   rZ   r>  
  r   zFixed.shapec                 C  r  r`   r   r   r   rY   rY   rZ   rB  
  r  zFixed.pathnamec                 C  r  r`   )r   r   r   rY   rY   rZ   r   
  r  zFixed._handlec                 C  r  r`   )r   r   r   rY   rY   rZ   r   
  r  zFixed._filtersc                 C  r  r`   )r   r   r   rY   rY   rZ   r   
  r  zFixed._complevelc                 C  r  r`   )r   r   r   rY   rY   rZ   r   
  r  zFixed._fletcher32c                 C  r  r`   )r   rw  r   rY   rY   rZ   r  
  r  zFixed.attrsc                 C  r1  zset our object attributesNrY   r   rY   rY   rZ   	set_attrs
      zFixed.set_attrsc                 C  r1  )zget our object attributesNrY   r   rY   rY   rZ   	get_attrs
  r  zFixed.get_attrsc                 C  r   )zreturn my storabler   r   rY   rY   rZ   storable
  r  zFixed.storablec                 C  r1  r2  rY   r   rY   rY   rZ   r  
  r3  zFixed.is_existsc                 C  ra  )Nr  )rv  r  r   rY   rY   rZ   r    rb  zFixed.nrowsLiteral[True] | Nonec                 C  s   |du rdS dS )z%validate against an existing storableNTrY   r  rY   rY   rZ   ro    s   zFixed.validateNc                 C  r1  )+are we trying to operate on an old version?NrY   )r   rs   rY   rY   rZ   validate_version  r  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)r  r  )r   rX   rY   rY   rZ   r     s
   zFixed.infer_axesr   r   r   c                 C     t d)Nz>cannot read on an abstract storer: subclasses should implementr   r   rs   r   r   r   rY   rY   rZ   r    s   z
Fixed.readc                 K  r  )Nz?cannot write on an abstract storer: subclasses should implementr  r   r  r   rY   rY   rZ   r  &  s   zFixed.writec                 C  s,   t |||r| jj| jdd dS td)zs
        support fully deleting the node in its entirety (only) - where
        specification must be None
        TrJ  Nz#cannot delete on an abstract storer)rN  rO  r   r  r   r   )r   rs   r   r   rY   rY   rZ   rP  +  s   zFixed.delete)rT   r~   )
r   r   r   rJ   r\   r]   r   r_   r^   r   r  )r^   r  r  r  )r^   r  r  )r^   r  r`   NNNNr   r   r   r   r  )r   r   r   r   r^   r   )!r   r  r  r  r  r  rA  r   r  r  r  rt  r   r  r  r>  rB  r   r   r   r   r  r  r  r  r  r  ro  r  r   r  r  rP  rY   rY   rY   rZ   r  
  sj   
 















r  c                   @  s   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Zdd Zdd Zd=ddZed>ddZd=ddZd=ddZd=ddZd?d@d!d"Z	d?dAd$d%ZdBd'd(ZdCd*d+Z	d?dDd,d-Z	d?dEd0d1ZdFd4d5Z	dGdHd:d;ZdS )IGenericFixedza generified fixed versiondatetimerU  c                 C  s   i | ]\}}||qS rY   rY   )rl   r.  r\  rY   rY   rZ   r]  =  r/  zGenericFixed.<dictcomp>r   
attributesr^   r_   c                 C  s   | j |dS )N )_index_type_mapr   )r   r  rY   rY   rZ   _class_to_aliasA  s   zGenericFixed._class_to_aliasc                 C  s   t |tr|S | j|tS r`   )rU   r   _reverse_index_mapr   r-   )r   aliasrY   rY   rZ   _alias_to_classD  s   
zGenericFixed._alias_to_classc                 C  s   |  tt|dd}|tkrd	dd}|}n|tkr#d	dd}|}n|}i }d|v r7|d |d< |tu r7t}d|v rXt|d trL|d 	d|d< n|d |d< |tu sXJ ||fS )
Nindex_classr  c                 S  s>   t j| j| j|d}tj|d d}|d ur|d|}|S )N)r  r  rd   UTC)r7   _simple_newrh  r  r,   tz_localize
tz_convert)rh  r  r  ZdtaresultrY   rY   rZ   rz   S  s   
z*GenericFixed._get_index_factory.<locals>.fc                 S  s$   t |}tj| |d}tj|d dS )Nrh  rd   )r)   r8   r  r/   )rh  r  r  r  ZparrrY   rY   rZ   rz   `  s   r  r  zutf-8r  )
r  r[   rv  r,   r/   r-   r3   rU   bytesrW   )r   r  r  rz   r  r   rY   rY   rZ   _get_index_factoryJ  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   rs   rY   rY   rZ   validate_read{  s   zGenericFixed.validate_readr   c                 C  r1  )NTrY   r   rY   rY   rZ   r    r3  zGenericFixed.is_existsc                 C  s   | j | j_ | j| j_dS r  )r\   r  r   r   rY   rY   rZ   r    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~   )rc   rv  r  r\   r[   r   r  r$  )r   r   rY   rY   rZ   r    s
   
zGenericFixed.get_attrsc                 K  r   r`   )r  r  rY   rY   rZ   r    r   zGenericFixed.writeNr   r   r   r   c                 C  s   ddl }t| j|}|j}t|dd}t||jr2|d || }t|dd}	|	dur1t||	d}n@tt|dd}	t|dd}
|
durLtj	|
|	d}n||| }|	rg|	
drgt|d	d}t||d
d}n|	dkrrtj|dd}|rw|jS |S )z2read an array for the specified node (off of groupr   N
transposedF
value_typerh  r>  rc  r  Trd  rf  rg  )r   rv  r   rw  rU   ZVLArraypd_arrayr[   rV   r  r~  r   rs  T)r   r   r   r   r   r   r  r  retr  r>  r  rY   rY   rZ   
read_array  s.   zGenericFixed.read_arrayr-   c                 C  sd   t t| j| d}|dkr| j|||dS |dkr+t| j|}| j|||d}|S td| )N_varietymultir   r   regularzunrecognized index variety: )r[   rv  r  read_multi_indexr   read_index_noder   )r   r   r   r   Zvarietyr   r   rY   rY   rZ   
read_index  s   zGenericFixed.read_indexr   c                 C  s   t |trt| j| dd | || d S t| j| dd td|| j| j}| ||j	 t
| j|}|j|j_|j|j_t |ttfrQ| t||j_t |tttfr^|j|j_t |trq|jd urst|j|j_d S d S d S )Nr  r  r  r   )rU   r.   r$  r  write_multi_index_convert_indexr\   r   write_arrayrh  rv  r   rq  rw  re   r,   r/   r  r   r  r3   r  r  _get_tz)r   r   r   ry  r   rY   rY   rZ   write_index  s    



zGenericFixed.write_indexr.   c                 C  s   t | j| d|j tt|j|j|jD ]P\}\}}}t|j	t
r't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  	enumerater@  levelsrH  namesrU   r  r(   r   r  r\   r   r  rh  rv  r   rq  rw  re   )r   r   r   ilevlevel_codesre   	level_keyZ
conv_levelr   	label_keyrY   rY   rZ   r    s$   
zGenericFixed.write_multi_indexc                 C  s   t | j| d}g }g }g }t|D ]6}| d| }	t | j|	}
| j|
||d}|| ||j | d| }| j|||d}|| qt|||ddS )Nr  r  r  r  T)r  rH  r  r:  )	rv  r  r`  r   r  r   re   r  r.   )r   r   r   r   r  r  rH  r  r  r  r   r  r  r  rY   rY   rZ   r     s    
zGenericFixed.read_multi_indexr   rJ   c              
   C  sX  ||| }d|j v rt|j jdkrtj|j j|j jd}t|j j}d }d|j v r6t|j j	}t|}|j }| 
|\}}	|dv rW|t||| j| jdfdti|	}
nPz|t||| j| jdfi |	}
W n= ty } z1| jdkrtd	rt|d
rtr|t||| j| jdfdtdtjdi|	}
n W Y d }~nd }~ww ||
_	|
S )Nr>  r   rh  re   )r   r  r  r  r  r  r  r  r  )rw  rV   prodr>  r  r  r[   rq  rf   re   r  _unconvert_indexr\   r   r  r  r   r_   r  r   r2   r  )r   r   r   r   r  rq  re   r  r  r   r   rQ  rY   rY   rZ   r    sf   


zGenericFixed.read_index_noder   rL   c                 C  sJ   t d|j }| j| j|| t| j|}t|j|j	_
|j|j	_dS )zwrite a 0-len arrayri   N)rV   r  ra  r   create_arrayr   rv  r_   r  rw  r  r>  )r   r   r   Zarrr   rY   rY   rZ   write_array_emptyN  s
   zGenericFixed.write_array_emptyr  rK   r
  Index | Nonec                 C  s  t |dd}|| jv r| j| j| |jdk}d}t|jtr$td|s0t	|dr0|j
}d}d }| jd urStt t j|j}W d    n1 sNw   Y  |d uru|sn| jj| j|||j| jd}||d d < n| || n|jjtjkrtj|dd}	|rn|	d	krnt|	||f }
tj|
tt d
 | j| j|t  }| | nt!|jdr| j"| j||#d t$|jt%| j|j&_'nt|jt(r| j"| j||j) t%| j|}t*|j+|j&_+d|jj, d|j&_'nWt!|jdr| j"| j||#d dt%| j|j&_'n:t|t-r8| j| j|t  }| |.  t%| j|}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[r0  rE  rf  )0r=   r   r   r  rG  rU   r  r&   r   r  r  r   r   r   r   ZAtomZ
from_dtypeZcreate_carrayr>  r  r   rV   Zobject_r   infer_dtyperw   r"  r#  r   r   Zcreate_vlarray
ObjectAtomr   r  r  viewr_   rv  rw  r  r'   asi8r  r  unitr9   to_numpyr  )r   r   r  r
  r   Zempty_arrayr  rM  cainferred_typer&  Zvlarrr   rY   rY   rZ   r  W  sr   





zGenericFixed.write_arrayr  r  r  r  r  )r   r_   r   r   r   r   r^   r-   )r   r_   r   r-   r^   r   )r   r_   r   r.   r^   r   )r   r_   r   r   r   r   r^   r.   )r   rJ   r   r   r   r   r^   r-   )r   r_   r   rL   r^   r   r`   )r   r_   r  rK   r
  r  r^   r   )r   r  r  r  r,   r/   r  r
  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rY   rY   rY   rZ   r  9  s4   
 

1


&


7
r  c                      sR   e Zd ZU dZdgZded< edd Z				ddddZd fddZ	  Z
S )r  r  re   rD   c              	   C  s*   zt | jjfW S  ttfy   Y d S w r`   )rr   r   rh  r   r   r   rY   rY   rZ   r>    s
   zSeriesFixed.shapeNr   r   r   r^   r1   c           	      C  s   |  || | jd||d}| jd||d}zt||| jdd}W |S  tyX } z*| jdkrLtdrLt|	drLt
rLt||| jdtd	tjd
d}n W Y d }~|S d }~ww )Nr   r  rh  F)r   re   r  r  r  r  r  r  )r   re   r  r  )r  r  r  r1   re   r  r   r   r_   r  r   r2   rV   r  )	r   rs   r   r   r   r   rh  r  rQ  rY   rY   rZ   r    s4   

	zSeriesFixed.readr   c                   s<   t  j|fi | | d|j | d| |j| j_d S )Nr   rh  )r7  r  r  r   r  re   r  r  r8  rY   rZ   r    s   zSeriesFixed.writer  r   r   r   r   r^   r1   r  )r   r  r  r  r  r  r  r>  r  r  r}  rY   rY   r8  rZ   r    s   
 
r  c                      sR   e Zd ZU ddgZded< edddZ				ddddZd fddZ  Z	S )BlockManagerFixedra  nblocksrh   r^   Shape | Nonec                 C  s   zJ| j }d}t| jD ]}t| jd| d}t|dd }|d ur'||d 7 }q| jj}t|dd }|d urAt|d|d  }ng }|| |W S  tyT   Y d S w )Nr   block_itemsr>  ri   )	ra  r`  r  rv  r   Zblock0_valuesrp   r   r   )r   ra  r
  r  r   r>  rY   rY   rZ   r>    s&   
zBlockManagerFixed.shapeNr   r   r   r+   c                 C  sX  |  || |  d}g }t| jD ]}||kr||fnd\}}	| jd| ||	d}
||
 q|d }g }t| jD ]F}| d| d}| jd| d||	d}||	| }t
|j||d d	d
}t rt|tjrt|ddr|ttjd}|| q>t|dkrt|ddd}t r| }|j|d	d}|S t
|d |d dS )Nr   r  r9  r  r  r  rw  ri   Fr   r   r  Tr  )r  )r9  r  )r   r  r   r   )r  r  Z_get_block_manager_axisr`  ra  r  r   r  r  rf  r+   r  r   rU   rV   r  r   rv  r2   r  rr   r4   r   r  rk  )r   rs   r   r   r   Zselect_axisrS  r  r  r  axr
  Zdfs	blk_itemsrh  dfoutrY   rY   rZ   r  	  s:   

zBlockManagerFixed.readr   c                   s   t  j|fi | t|jtr|d}|j}| s | }|j| j	_t
|jD ]\}}|dkr9|js9td| d| | q*t|j| j	_t
|jD ]"\}}|j|j}| jd| d|j|d | d| d| qOd S )Nr  r   z/Columns index has to be unique for fixed formatr9  rw  )r
  r  )r7  r  rU   _mgrr?   _as_managerZis_consolidatedZconsolidatera  r  r  rS  Z	is_uniquer   r  rr   blocksr  r
  rg  mgr_locsr  rh  )r   r  r   r  r  r  blkr  r8  rY   rZ   r  6  s"   

zBlockManagerFixed.write)r^   r  r  )r   r   r   r   r^   r+   r  )
r   r  r  r  r  r  r>  r  r  r}  rY   rY   r8  rZ   r    s   
 -r  c                   @  s   e Zd ZdZeZdS )r  r  N)r   r  r  r  r+   r  rY   rY   rY   rZ   r  P  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 fd"d#Z	e
dd$d%Zdd&d'Zdd)d*Zdd+d,Ze
dd.d/Zdd3d4Ze
dd6d7Ze
dd8d9Ze
d:d; Ze
d<d= Ze
d>d? Ze
d@dA Ze
ddCdDZe
ddEdFZe
ddGdHZe
ddJdKZddMdNZdOdP ZddRdSZddUdVZddYdZZdd[d\Z dd]d^Z!dd_d`Z"dddadbZ#ddcddZ$e%dedf Z&	dddhdiZ'	dddndoZ(e)ddqdrZ*dsdt Z+	
			dddwdxZ,e-dd{d|Z.ddddZ/dddZ0	ddddZ1			dddd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_tablery   r_   r  r  ri   zint | list[Hashable]r  Trp   r  Nr~   r   r   r   rJ   r\   r]   r   
index_axeslist[IndexCol] | Noner5   list[tuple[AxisInt, Any]] | Nonevalues_axeslist[DataCol] | Noner   list | Noner  dict | Noner^   r   c                   sP   t  j||||d |pg | _|pg | _|pg | _|pg | _|	p!i | _|
| _d S )Nr  )r7  r   r  r5  r  r   r  r   )r   r   r   r\   r   r  r5  r  r   r  r   r8  rY   rZ   r   u  s   





zTable.__init__c                 C  s   | j dd S )N_r   )r  r  r   rY   rY   rZ   table_type_short     zTable.table_type_shortc                 C  s   |    t| jrd| jnd}d| d}d}| jr-d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  r  z,dc->[r0  r  c                 S  r  rY   r_   r1  rY   rY   rZ   ro     r  z"Table.__repr__.<locals>.<listcomp>r  c                 S  r   rY   rd   r  rY   rY   rZ   ro     r  r  z (typ->z,nrows->z,ncols->z,indexers->[r  )r   rr   r   r  r  r  r  rt  r  r  ncols)r   Zjdcrm  ZverZjverZjindex_axesrY   rY   rZ   r     s(   zTable.__repr__r  c                 C  s"   | j D ]}||jkr|  S qdS )zreturn the axis for cN)rS  re   )r   r  r   rY   rY   rZ   r     s
   

zTable.__getitem__c              
   C  s   |du rdS |j | j krtd|j  d| j  ddD ]\}t| |d}t||d}||krwt|D ]7\}}|| }||krh|dkrZ|j|jkrZtd|jd  d	|j d
|j dtd| d| d| dq1td| d| d| dqdS )z"validate against an existing tableNz'incompatible table_type with existing [r  r0  )r  r5  r  r  Cannot serialize the column [r   z%] because its data contents are not [z] but [] object dtypezinvalid combination of [z] on appending data [z] vs current table [)r  r   rv  r  rq  r   rh  rM  )r   r  r  svZovr  ZsaxZoaxrY   rY   rZ   ro    sP   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)rU   r  rp   r   rY   rY   rZ   is_multi_index  s   zTable.is_multi_indexr  r    tuple[DataFrame, list[Hashable]]c              
   C  sT   t |jj}z| }W n ty } ztd|d}~ww t|ts&J ||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)rN  Zfill_missing_namesr   r  Zreset_indexr   rU   r+   )r   r  r  Z	reset_objrQ  rY   rY   rZ   validate_multiindex  s   zTable.validate_multiindexrh   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 r4  )r  r>  rl   r  rY   rY   rZ   ro     r  z(Table.nrows_expected.<locals>.<listcomp>)rV   r  r  r   rY   rY   rZ   nrows_expected  s   zTable.nrows_expectedc                 C  s
   d| j v S )zhas this table been createdry   r  r   rY   rY   rZ   r    s   
zTable.is_existsc                 C  ra  Nry   rv  r   r   rY   rY   rZ   r    rb  zTable.storablec                 C  r   )z,return the table group (this is my storable))r  r   rY   rY   rZ   ry     r  zTable.tablec                 C  r  r`   )ry   r  r   rY   rY   rZ   r    r  zTable.dtypec                 C  r  r`   r  r   rY   rY   rZ   r	    r  zTable.descriptionitertools.chain[IndexCol]c                 C  s   t | j| jS r`   )r>  r?  r  r  r   rY   rY   rZ   rS    r  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`   )rr   rh  r  rY   rY   rZ   rY    s    zTable.ncols.<locals>.<genexpr>)sumr  r   rY   rY   rZ   r    s   zTable.ncolsc                 C  r1  r2  rY   r   rY   rY   rZ   is_transposed  r3  zTable.is_transposed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 r4  r  r  rY   rY   rZ   ro     r  z*Table.data_orientation.<locals>.<listcomp>c                 S  s   g | ]}t |jqS rY   )rh   r9  r  rY   rY   rZ   ro     r/  )rq   r>  r?  r5  r  r   rY   rY   rZ   data_orientation  s   zTable.data_orientation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   ri   c                 S  s   g | ]}|j |fqS rY   r  r  rY   rY   rZ   ro     r/  z$Table.queryables.<locals>.<listcomp>c                   s   g | ]
\}} | d fqS r`   rY   )rl   r9  rh  )
axis_namesrY   rZ   ro     s    c                   s&   g | ]}|j t jv r|j|fqS rY   )re   r_  r   r  rk  r   rY   rZ   ro     s     )r  r5  r  rV  )r   Zd1Zd2Zd3rY   )r  r   rZ   
queryables  s   

zTable.queryablesc                 C     dd | j D S )zreturn a list of my index colsc                 S  s   g | ]}|j |jfqS rY   )r9  r  r  rY   rY   rZ   ro   '  r  z$Table.index_cols.<locals>.<listcomp>r  r   rY   rY   rZ   
index_cols$  r  zTable.index_colsr   c                 C  r  )zreturn a list of my values colsc                 S  r   rY   r  r  rY   rY   rZ   ro   +  r  z%Table.values_cols.<locals>.<listcomp>)r  r   rY   rY   rZ   values_cols)  r  zTable.values_colsr   c                 C  s   | j j}| d| dS )z)return the metadata pathname for this keyz/meta/z/metar  r  rY   rY   rZ   _get_metadata_path-  s   zTable._get_metadata_pathrh  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
        Frp  ry   )r   r\   r   r   N)r   r   r  r1   r\   r   r   )r   r   rh  rY   rY   rZ   r  2  s   	

zTable.write_metadatac                 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)rv  r   r   r   r  r   rY   rY   rZ   r.  D  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)r_   r  r  r  r  r5  r   r   r\   r   r  r  r   rY   rY   rZ   r  J  s   





zTable.set_attrsc                 C  s   t | jddpg | _t | jddpg | _t | jddpi | _t | jdd| _tt | jdd| _tt | jdd| _	t | jd	dpBg | _
d
d | jD | _dd | jD | _dS )r  r5  Nr   r  r   r\   r   r~   r  c                 S     g | ]}|j r|qS rY   r  r  rY   rY   rZ   ro   `  r/  z#Table.get_attrs.<locals>.<listcomp>c                 S     g | ]}|j s|qS rY   r   r  rY   rY   rZ   ro   a  r/  )rv  r  r5  r   r  r   rc   r\   r[   r   r  
indexablesr  r  r   rY   rY   rZ   r  W  s   zTable.get_attrsc                 C  sF   |dur| j r!tddd | jD  }tj|tt d dS dS dS )r  Nr  c                 S  r  rY   r  r1  rY   rY   rZ   ro   g  r  z*Table.validate_version.<locals>.<listcomp>r  )r  ru   r  r  r"  r#  r   r   )r   rs   r&  rY   rY   rZ   r  c  s   
zTable.validate_versionc                 C  sR   |du rdS t |tsdS |  }|D ]}|dkrq||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
        Nrh  zmin_itemsize has the key [z%] which is not an axis or data_column)rU   rV  r  r   )r   r   qr.  rY   rY   rZ   validate_min_itemsizen  s   

zTable.validate_min_itemsizec                   s   g }j jjtjjD ]5\}\}}t|}|}|dur%d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  )re   r9  r  rq  r  ry   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<  )
re   r  rh  rq  r  r  ry   r   r  r  )
rU   r_   r5  r~  rv  _maybe_adjust_namer  r@  r.  ry   )r  r  klassrM  adj_namerh  r  rq  mdr   r  )base_posrm  descr   table_attrsrY   rZ   rz     s0   

zTable.indexables.<locals>.fc                   s   g | ]	\}} ||qS rY   rY   )rl   r  r  )rz   rY   rZ   ro     r3  z$Table.indexables.<locals>.<listcomp>)r	  ry   r  r  r  rv  r.  r  r   r_  r   rr   rc  r  )r   _indexablesr  r9  re   rM  r(  r   r  rq  	index_colrY   )r)  rm  r*  rz   r   r+  rZ   r"    s2   




 %zTable.indexablesrq  c              	   C  sP  |   sdS |du rdS |du s|du rdd | jD }t|ttfs&|g}i }|dur0||d< |dur8||d< | j}|D ]h}t|j|d}|dur|jrx|j	}|j
}	|j}
|durc|
|krc|  n|
|d< |durt|	|krt|  n|	|d< |js|jdrtd	|jdi | q=|| jd
 d v rtd| d| d| dq=d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  r  rY   )r  r  r  rY   rY   rZ   ro     r  z&Table.create_index.<locals>.<listcomp>rp  rq  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   ri   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.rY   )r   rS  rU   rq   rp   ry   rv  rX  r  r   rp  rq  Zremove_indexr   r~  r   rr  r5  r   )r   r   rp  rq  kwry   r  r\  r   Zcur_optlevelZcur_kindrY   rY   rZ   rr    sX   

zTable.create_indexr   r   r   9list[tuple[np.ndarray, np.ndarray] | tuple[Index, Index]]c           	      C  sZ   t | |||d}| }g }| jD ]}|| 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$  rr  )
	Selectionr   rS  r*  r  r  r   r\   r   r   )	r   rs   r   r   	selectionrh  r  r   resrY   rY   rZ   
_read_axes%  s   
zTable._read_axesr  c                 C     |S )zreturn the data for this objrY   r  r  r  rY   rY   rZ   
get_objectG  s   zTable.get_objectc                   s   t |sg S |d \} | j|i }|ddkr&|r&td| d| |du r/t }n|du r5g }t|trPt|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  rY   r-  )existing_data_columnsrY   rZ   ro   h  s
    z/Table.validate_data_columns.<locals>.<listcomp>c                   s   g | ]}| v r|qS rY   rY   )rl   r  )axis_labelsrY   rZ   ro   p  r  )
rr   r  r   r   rp   rU   rV  r_  rc  r  )r   r   r   r5  r9  r  rY   )r9  r8  rZ   validate_data_columnsL  s.   


	zTable.validate_data_columnsr+   ro  c           /        s  t ts| jj}td| dt d du rdg fdd D  |  r=d}d	d | jD  t| j	}| j
}nd
}| j}	| jdksIJ t | jd krVtdg }
|du r^d}t fdddD }j| }t|}|rt|
}| j| d }tt|t|dddsttt|tt|dddr|}|	|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}|rbt|dkrb|d |v rbt+}|d }|du sbt |t,sbtd|r|rz| j'| }W n t-t.fy }  ztd| d| j' d| d} ~ ww d}|pd| }!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=> }(nt |j5t?rt,|j5}'t@|"\}*}+||#|!t||$||%|&|)|'|(|+|*d},|, |	 ||, |d7 }q2dd |D }-t| | jA| j| j| j||
||-|	|d
}.tB| dr:| jC|._C|.D| |rJ|rJ|.E|  |.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  r0  Nr   c                   r,  rY   )_get_axis_numberr  )r  rY   rZ   ro     r/  z&Table._create_axes.<locals>.<listcomp>Tc                 S  r   rY   rZ  r  rY   rY   rZ   ro     r  Fr  ri   z<currently only support ndim-1 indexers in an AppendableTabler  c                 3  s    | ]	}| vr|V  qd S r`   rY   r1  )rS  rY   rZ   rY    s    z%Table._create_axes.<locals>.<genexpr>r  r-  r  r   r  zIncompatible appended table [z]with existing table [Zvalues_block_)existing_colr   r   r\   r   r   r  r,  )re   r  rh  r  r  rq  r  rl  r   r  r  r  c                 S  r  rY   )r  re   )rl   r
  rY   rY   rZ   ro   K  r  )
r   r   r\   r   r  r5  r  r   r  r   r  )FrU   r+   r   r   r   r   r   r  rp   r   r   r  ra  rr   r   r^  rS  r5  r*   rV   r<   re  r!  r  r   r   Z_get_axis_namer  r\   r   r9  r  r'  r  _reindex_axisr:  r7  r;  _get_blocks_and_itemsr  r  r@  r5  r~  r_   
IndexErrorr   _maybe_convert_for_string_atomrh  r%  r  rN  r@  r  re   rv  r  r  r&   rl  rs  rn  rt  r2   r?  r   r  r  r$  ro  )/r   rS  r  ro  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&  re   r<  rQ  new_namedata_convertedr'  r  rq  r  r   r  rl  r  rA  r
  ZdcsZ	new_tablerY   )rS  r  rZ   _create_axesr  s4  
 







"







zTable._create_axesr  rA  c                 C  s~  t | jtr| d} dd }| j}tt|}t|j}||}t|ri|d \}	}
t	|

t	|}| j||	dj}tt|}t|j}||}|D ]}| j|g|	dj}tt|}||j ||| qK|rdd t||D }g }g }|D ];}t|j}z||\}}|| || W q{ ttfy } zdd	d
 |D }td| d|d }~ww |}|}||fS )Nr  c                   s    fdd j D S )Nc                   s   g | ]	} j |jqS rY   )r
  rg  r  )rl   r  mgrrY   rZ   ro   s  r3  zFTable._get_blocks_and_items.<locals>.get_blk_items.<locals>.<listcomp>)r  rI  rY   rI  rZ   get_blk_itemsr  s   z2Table._get_blocks_and_items.<locals>.get_blk_itemsr   rZ  c                 S  s"   i | ]\}}t | ||fqS rY   )rq   tolist)rl   brE  rY   rY   rZ   r]    s    z/Table._get_blocks_and_items.<locals>.<dictcomp>r  c                 S  r  rY   r  )rl   itemrY   rY   rZ   ro     r  z/Table._get_blocks_and_items.<locals>.<listcomp>z+cannot match existing table structure for [z] on appending data)rU   r  r?   r  r   r@   rp   r  rr   r-   rd  rk  rc  r@  rq   rh  rC  r   r?  r   r  r   )r  rA  rB  r  r   rK  rJ  r  r  r9  r9  Z
new_labelsr  Zby_itemsZ
new_blocksZnew_blk_itemsZear
  rM  rE  rQ  ZjitemsrY   rY   rZ   r>  d  sV   








zTable._get_blocks_and_itemsr2  r1  c                   s   |durt |}|dur'jr'tjt sJ jD ]}||vr&|d| qjD ]\}}t |||  fdd}q*|jdurS|j D ]\}}	}
|||
|	 qG S )zprocess axes filtersNr   c                   s    j D ]X} |} |}|d usJ | |kr3jr$|tj}|||} j|d|   S | |v r[tt	 | j
}t|}t trLd| }|||} j|d|   S qtd|  d)NrZ  ri   zcannot find the field [z] for filtering!)Z_AXIS_ORDERSr;  	_get_axisr	  unionr-   r  rj  r>   rv  rh  rU   r+   r   )fieldfiltoprC  Zaxis_numberZaxis_valuesZtakersrh  r  r   rY   rZ   process_filter  s$   





z*Table.process_axes.<locals>.process_filter)	rp   r	  rU   r  insertr5  r=  filterr   )r   r  r2  r   r   r9  labelsrU  rQ  rS  rR  rY   rT  rZ   process_axes  s   

 zTable.process_axesr   r   rT  c                 C  s   |du r
t | jd}d|d}dd | jD |d< |r6|du r$| jp#d}t j|||p-| jd	}||d
< |S | jdur@| j|d
< |S )z:create the description of the table from the axes & valuesNi'  ry   )re   rT  c                 S  s   i | ]}|j |jqS rY   )r  r  r  rY   rY   rZ   r]    r/  z,Table.create_description.<locals>.<dictcomp>r	  	   )r   r   r   r   )maxr  rS  r   r   r  r   r   )r   r   r   r   rT  rU  r   rY   rY   rZ   create_description  s"   	



zTable.create_descriptionc           
      C  s   |  | |  sdS t| |||d}| }|jdurD|j D ]"\}}}| j|| | d d}	|||	j	||   |j
 }q!t|S )zf
        select coordinates (row numbers) from a table; return the
        coordinates object
        Fr$  Nri   r  )r  r   r1  select_coordsrW  r   r*  r  r[  ilocrh  r-   )
r   rs   r   r   r2  ZcoordsrQ  rS  rR  r  rY   rY   rZ   r&    s   

 zTable.read_coordinatesr)  c           
      C  s   |    |  s
dS |durtd| jD ]L}||jkra|js'td| dt| jj	|}|
| j |j||| | j| j| jd}t|d |j}t| jj| dd}	t||d|	d	  S qtd| d
)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 indexablerr  ri   r<  )re   r  r  z] not found in the table)r  r   r   rS  re   r  r   rv  ry   rX  r*  r  r  r   r\   r   r   r  r  r1   r   )
r   r)  rs   r   r   r   r  Z
col_valuesZcvsr  rY   rY   rZ   r*    s0   



zTable.read_column)Nr~   NNNNNN)r   r   r   rJ   r\   r]   r   r_   r  r  r5  r  r  r  r   r  r  r   r^   r   r  )r  r_   r  r  )r  r   r^   r
  r  )r^   r  )r^   r  )r^   r  )r^   r   )r   r_   r^   r_   )r   r_   rh  r  r^   r   r  r`   r  )rq  r]   r^   r   r  )r   r   r   r   r^   r0  r  r   )TNNN)r  r+   ro  r   )r  r+   rA  r   )r2  r1  r^   r+   )r   r   r   r   rT  r   r^   r  r  )r)  r_   r   r   r   r   )4r   r  r  r  r  r  r  r  rA  r   r  r  r   r   ro  r	  r  r  r  r  ry   r  r	  rS  r  r  r  r  r  r  r  r  r.  r  r  r  r$  r   r"  rr  r4  r|  r7  r:  rH  staticmethodr>  rY  r\  r&  r*  r}  rY   rY   r8  rZ   r  U  s   
 


'





	







LW"* sC
7 r  c                   @  s2   e Zd ZdZdZ				ddddZ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   r   r   c                 C  r  )z[
        read the indices and the indexing array, calculate offset rows and return
        z!WORMTable needs to implement readr  r  rY   rY   rZ   r  O  s   
zWORMTable.readr^   r   c                 K  r  )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 writer  r  rY   rY   rZ   r  [  s   zWORMTable.writer  r  r  )r   r  r  r  r  r  r  rY   rY   rY   rZ   r  F  s    r  c                   @  sZ   e Zd ZdZdZ												dd ddZd!d"ddZd#ddZd$d%ddZdS )&r  (support the new appendable table formatsZ
appendableNFTr   r   r   r   r   rF  r^   r   c                 C  s   |s| j r| j| jd | j||||||d}|jD ]}|  q|j sA|j||||	d}|  ||d< |jj	|jfi | |j
|j_
|jD ]}||| qI|j||
d d S )Nry   )rS  r  ro  r   r   r   )r   r   r   rT  rF  )r   )r  r   r  r   rH  rS  r  r\  r  Zcreate_tabler  r  r  
write_data)r   r  rS  r   r   r   r   r   r   rT  r   r   r   rF  ry   r   optionsrY   rY   rZ   r  j  s4   

	


zAppendableTable.writec                   s  | j j}| j}g }|r*| jD ]}t|jjdd}t|tj	r)|
|jddd qt|rD|d }|dd D ]}||@ }q8| }nd}dd	 | jD }	t|	}
|
dksZJ |
d
d	 | jD }dd	 |D }g }t|D ]\}}|f| j ||
|   j }|
|| qo|du rd}tjt||| j d}|| d }t|D ]9}|| t|d | |  kr dS | j| fdd	|	D |dur|  nd fdd	|D d qdS )z`
        we form the data into a 2-d including indexes,values,mask write chunk-by-chunk
        r   rZ  Zu1Frp  ri   Nc                 S  r   rY   )r  r  rY   rY   rZ   ro     r  z.AppendableTable.write_data.<locals>.<listcomp>c                 S     g | ]}|  qS rY   )r  r  rY   rY   rZ   ro     r  c              	   S  s,   g | ]}| tt|j|jd  qS r  )Z	transposerV   Zrollarangera  rk  rY   rY   rZ   ro     s   , r  rh  c                      g | ]}|  qS rY   rY   r  Zend_iZstart_irY   rZ   ro     r  c                   rf  rY   rY   rk  rg  rY   rZ   ro     r  )indexesrz  rh  )r  r  r  r  r5   r  rW  rU   rV   r  r   rv  rr   rt  r  r  r>  reshaper  r  r`  write_data_chunk)r   r   r   r  r  Zmasksr   rz  rE  rh  nindexesrh  bvaluesr  r\  Z	new_shaperowschunksrY   rg  rZ   rb    sP   


zAppendableTable.write_datarm  r  rh  list[np.ndarray]rz  npt.NDArray[np.bool_] | Nonerh  c                 C  s   |D ]}t |js dS q|d jd }|t|kr#t j|| jd}| jj}t|}t|D ]
\}	}
|
|||	 < q/t|D ]\}	}||||	|  < q>|dura| j	t
dd }| sa|| }t|rr| j| | j  dS 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   rh  Frp  )rV   r  r>  rr   r  r  r  r  rt  rv  r   rW  ry   r   r  )r   rm  rh  rz  rh  r\  r  r  rk  r  r%  rE  rY   rY   rZ   rj    s*   z AppendableTable.write_data_chunkr   r   c                 C  sb  |d u st |s4|d u r|d u r| j}| jj| jdd |S |d u r%| j}| jj||d}| j  |S |  s:d S | j}t	| |||d}|
 }t|dd }t |}	|	r| }
t|
|
dk j}t |skdg}|d |	krv||	 |d dkr|dd | }t|D ]}|t||}|j||jd  ||jd  d d |}q| j  |	S )	NTrJ  r  Frp  ri   r   rm  )rr   r  r   r  r   ry   Zremove_rowsr  r   r1  r]  r1   Zsort_valuesdiffrp   r   r   rV  rC  reversedrg  r`  )r   rs   r   r   r  ry   r2  rh  Zsorted_seriesZlnrq  r   Zpgr	  rm  rY   rY   rZ   rP    sF   


zAppendableTable.delete)NFNNNNNNFNNT)
r   r   r   r   r   r   rF  r   r^   r   r  )r   r   r   r   r^   r   )
rm  r  rh  ro  rz  rp  rh  ro  r^   r   r  r  )	r   r  r  r  r  r  rb  rj  rP  rY   rY   rY   rZ   r  d  s&    ;
;,r  c                   @  sZ   e Zd ZU dZdZdZdZeZde	d< e
dd	d
ZedddZ				ddddZdS )r  ra  r  r  r  r  r  r^   r   c                 C  s   | j d jdkS )Nr   ri   )r  r9  r   rY   rY   rZ   r  O  r  z"AppendableFrameTable.is_transposedr  c                 C  s   |r|j }|S )zthese are written transposed)r  r6  rY   rY   rZ   r7  S  s   zAppendableFrameTable.get_objectNr   r   r   c                   s    |   sd S  j|||d}t jr$ j jd d i ni } fddt jD }t|dks:J |d }|| d }	g }
t jD ]\}}| j	vrVqK|| \}}|ddkrht
|}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rt|tjr|d|jd f}t|tjrzt|j||dd}W nL ty } z) jdkrtdrt|drtrt|j||dtdtjdd}n W Y d }~nd }~ww t|t
rt|||d}n	tj |g||d}t! r|j"j#dks-|j$|j"k% s-J |j$|j"f|D ]}t j&j'| dd }|dv rJ|| (|||< q/|
)| qKt|
dkr^|
d }nt*|
dd}t+ |||d} j,|||d}|S )Nr$  r   c                   s"   g | ]\}}| j d  u r|qS r4  r  )rl   r  r  r   rY   rZ   ro   p  s   " z-AppendableFrameTable.read.<locals>.<listcomp>ri   r   r.   r  TZinplacere   rd   Fr  r  r  r  r  r  )r   r   r  r  r  rq  r<  )r_   r  rZ  )r2  r   )-r  r   r4  rr   r5  r  r   r  rS  r  r-   r.   Zfrom_tuples	set_namesr  rv  r  ra  rU   rV   r  ri  r>  r+   r  r   r   r_   r  r   r2   r  Z_from_arraysr   r  rq  ZdtypesrW  ry   r  rv  r   r4   r1  rY  )r   rs   r   r   r   r  r  ZindsZindr   Zframesr  r   Z
index_valsr  rX  r  rh  Zindex_Zcols_r  rQ  r)  r  r2  rY   r   rZ   r  Z  s   





"

zAppendableFrameTable.readr  r_  r  r  )r   r  r  r  r  r  ra  r+   r  r  r  r  r|  r7  r  rY   rY   rY   rZ   r  G  s   
 r  c                      sh   e Zd ZdZdZdZdZeZe	dddZ
edd
dZdd fddZ				dd fddZ  ZS )r  ra  r  r  r  r^   r   c                 C  r1  r2  rY   r   rY   rY   rZ   r    r3  z#AppendableSeriesTable.is_transposedr  c                 C  r5  r`   rY   r6  rY   rY   rZ   r7    r3  z AppendableSeriesTable.get_objectNr   c                   s@   t |ts|jp	d}||}t jd||j d| dS )+we are going to write this as a frame tablerh  r  r   NrY   )rU   r+   re   Zto_framer7  r  r   rL  )r   r  r   r   re   r8  rY   rZ   r    s   


"zAppendableSeriesTable.writer   r   r   r1   c                   s   | j }|d ur!|r!t| jtsJ | jD ]}||vr |d| qt j||||d}|r5|j| jdd |jd d df }|j	dkrFd |_	|S )Nr   r8  Trs  rh  )
r	  rU   r  rp   rV  r7  r  	set_indexr^  re   )r   rs   r   r   r   r	  r   rX   r8  rY   rZ   r    s   

zAppendableSeriesTable.readr  r_  r`   r  r  r  )r   r  r  r  r  r  ra  r1   r  r  r  r|  r7  r  r  r}  rY   rY   r8  rZ   r    s     	r  c                      s*   e Zd ZdZdZdZd fddZ  ZS )	r  ra  r  r  r^   r   c                   sb   |j pd}| |\}| _t| jtsJ t| j}|| t||_t j	dd|i| dS )ru  rh  r  NrY   )
re   r  r  rU   rp   r   r-   r   r7  r  )r   r  r   re   ZnewobjrX  r8  rY   rZ   r    s   



z AppendableMultiSeriesTable.writer  )r   r  r  r  r  r  r  r}  rY   rY   r8  rZ   r    s
    r  c                   @  sd   e Zd ZU dZdZdZdZeZde	d< e
dd	d
Ze
dd ZdddZedd ZdddZdS )r  z:a table that read/writes the generic pytables table formatr  r  r  zlist[Hashable]r  r^   r_   c                 C  r   r`   )r  r   rY   rY   rZ   rt    r   zGenericTable.pandas_typec                 C  s   t | jdd p	| jS r  r  r   rY   rY   rZ   r    rQ  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  r  rY   r   r  rY   rY   rZ   ro     r/  z*GenericTable.get_attrs.<locals>.<listcomp>c                 S  r!  rY   r   r  rY   rY   rZ   ro     r/  c                 S  r   rY   rd   r  rY   rY   rZ   ro     r  )r5  r   r  r"  r  r  r   r   rY   rY   rZ   r    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s-J t||}| |}|dur=dnd}t	|||g|| j||d}	|
|	 q"|S )z0create the indexables from the table descriptionr   Nr,  r   )re   r9  ry   r   r  )re   r  rh  r  ry   r   r  )r	  r.  r0  ry   r  Z_v_namesrU   r_   rv  r  r   )
r   rU  r(  r   r-  r,  r  r   rM  rm  rY   rY   rZ   r"    s.   


	zGenericTable.indexablesc                 K  r  )Nz cannot write on an generic tabler  )r   r   rY   rY   rZ   r  C  s   zGenericTable.writeNr  r  )r   r  r  r  r  r  ra  r+   r  r  r  rt  r  r  r   r"  r  rY   rY   rY   rZ   r    s   
 



#r  c                      s`   e Zd ZdZdZeZdZe	dZ
edddZdd fddZ								dd fddZ  ZS )r  za frame with a multi-indexr  r  z^level_\d+$r^   r_   c                 C  r1  )NZappendable_multirY   r   rY   rY   rZ   r  O  r3  z*AppendableMultiFrameTable.table_type_shortNr   c                   s|   |d u rg }n	|du r|j  }| |\}| _t| jts J | jD ]}||vr/|d| q#t jd||d| d S )NTr   rv  rY   )	r   rL  r  r  rU   rp   rV  r7  r  )r   r  r   r   r   r8  rY   rZ   r  T  s   

zAppendableMultiFrameTable.writer   r   r   c                   sD   t  j||||d}| j}|j fdd|jjD |_|S )Nr8  c                   s    g | ]} j |rd n|qS r`   )
_re_levelssearch)rl   re   r   rY   rZ   ro   l  s     z2AppendableMultiFrameTable.read.<locals>.<listcomp>)r7  r  rw  r  r   rt  r  )r   rs   r   r   r   r  r8  r   rZ   r  `  s   zAppendableMultiFrameTable.readr  r`   r  r  r  )r   r  r  r  r  r+   r  ra  recompilerx  r  r  r  r  r}  rY   rY   r8  rZ   r  G  s    
r  r  r+   r9  rM   rX  r-   c                 C  s   |  |}t|}|d urt|}|d u s||r!||r!| S t| }|d ur6t| j|dd}||sOtd d g| j }|||< | jt| } | S )NF)sort)	rO  r>   Zequalsuniqueri  slicera  rj  rq   )r  r9  rX  r  r  ZslicerrY   rY   rZ   r=  r  s   

r=  r  r   str | tzinfoc                 C  s   t | }|S )z+for a tz-aware type, return an encoded zone)r   Zget_timezone)r  ZzonerY   rY   rZ   r    s   
r  rh  np.ndarray | Indexre  r,   c                 C  r  r`   rY   rh  r  re  rY   rY   rZ   r     s   r   r  c                 C  r  r`   rY   r  rY   rY   rZ   r     r3  str | tzinfo | Nonenp.ndarray | DatetimeIndexc                 C  s   t | tr| jdu s| j|ksJ | jdur| S |dur?t | tr%| j}nd}|  } t|}t| |d} | d|} | S |rHt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
    Nrd   r  M8[ns]rh  )
rU   r,   r  re   rt  r[   r  r  rV   rs  )rh  r  re  re   rY   rY   rZ   r     s    


re   c              
   C  st  t | tsJ |j}t|\}}t|}t|}t|j	ds*t
|j	s*t|j	r=t| |||t|dd t|dd |dS t |trFtdtj|dd}	t|}
|	dkrotjd	d
 |
D tjd}t| |dt  |dS |	dkrt|
||}|j	j}t| |dt ||dS |	dv rt| ||||dS t |tjr|j	tksJ |dksJ |t  }t| ||||dS )Niur  r  )rh  rq  r  r  r  r  zMultiIndex not supported here!Fr  r   c                 S  rd  rY   )Z	toordinalrk  rY   rY   rZ   ro     r  z"_convert_index.<locals>.<listcomp>rh  )r  r  )integerZfloating)rh  rq  r  r  r  )rU   r_   re   r?  r@  r~  rN  r   r  r  r%   r!   r  rv  r.   r   r  rV   rs  Zint32r   Z	Time32Col_convert_string_arrayr  r  r  r  r  )re   r   r\   r   r  ry  rA  rq  rM  r  rh  r  rY   rY   rZ   r    s^   








r  rq  c                 C  s   | dr|dkrt| }|S t| |}|S |dkr"t| }|S |dkrLztjdd | D td}W |S  tyK   tjdd | D td}Y |S w |dv rWt| }|S |d	v ret| d ||d
}|S |dkrrt| d }|S td| )Nrc  rf  r   c                 S  ri  rY   rj  rk  rY   rY   rZ   ro     r/  z$_unconvert_index.<locals>.<listcomp>rh  c                 S  ri  rY   rl  rk  rY   rY   rZ   ro     r/  )r  floatr   r  rr  r  r   zunrecognized index type )	r~  r,   r  r3   rV   rs  r  r   rx  )r  rq  r\   r   r   rY   rY   rZ   r    s:   

	r  rl  rL   r   c                 C  s  t |jtr
| }|jtkr|S ttj|}|jj}t	j
|dd}	|	dkr*td|	dkr2td|	dks<|dks<|S t|}
| }|||
< |rY|
 rYt||jkrYtd	t	j
|dd}	|	dkrt|jd
 D ]+}|| }t	j
|dd}	|	dkrt||kr|| nd| }td| d|	 dqkt||||j}|j}t |trt|| p|dpd
}t|pd
|}|d ur||}|d ur||kr|}|jd| dd}|S )NFr  r   z+[date] is not implemented as a table columnr  z>too many timezones in this block, create separate data columnsr  r  z8NaN representation is too large for existing column sizer   zNo.r  z2]
because its data contents are not [string] but [r  rh  z|Srp  )rU   r  r2   r  r  r   rV   r  re   r   r  r   r5   r  ru  rr   r  r   r`  r>  r  ri  rV  rh   r   r[  r  rv  )re   rl  r<  r   r   r\   r   r   rA  r  rz  r  r  r
  Zerror_column_labelrG  r  ZecirY   rY   rZ   r@  "  sX   




r@  r  c                 C  sb   t | rt|  d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  )r  r  ri   Srh  )rr   r1   rt  r_   encoderw  ri  r>  r    r[  
libwritersmax_len_string_arrayrV   rs  )r  r\   r   Zensuredr  rY   rY   rZ   r  q  s   

r  c                 C  s   | j }tj|  td} t| rEtt| }d| }t	| d t
r9t| ddjj||dd}| } d| j_n| j|ddjtdd} |d	u rKd
}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.
    rh  Ur   Frp  r  )r   r  TNr  )r>  rV   rs  rt  r  rr   r  r  r    rU   r  r1   r_   rW   r  flagsZ	writeablerv  Z!string_array_replace_from_nan_repri  )r  r   r\   r   r>  r  r  ZserrY   rY   rZ   rx    s    


rx  r  c                 C  s6   t |tsJ t|t|rt|||}|| } | S r`   )rU   r_   r   _need_convert_get_converter)rh  r  r\   r   convrY   rY   rZ   r    s
   r  c                   sH   dkrdd S dv rfddS dkr fddS t d )Nrc  c                 S  s   t j| ddS )Nr  rh  rV   rs  r2  rY   rY   rZ   r         z _get_converter.<locals>.<lambda>c                   s   t j|  dS )Nrh  r  r  rD  rY   rZ   r     r  r  c                   s   t | d  dS )Nrr  )rx  r  r  rY   rZ   r     s    zinvalid kind )r   )rq  r\   r   rY   )r\   r   rq  rZ   r    s   r  c                 C  s   | dv sd| v r
dS dS )N)rc  r  rc  TFrY   rD  rY   rY   rZ   r    s   r  r  Sequence[int]c                 C  sl   t |tst|dk rtd|d dkr4|d dkr4|d dkr4td| }|r4| 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   ri   r  r  zvalues_block_(\d+)Zvalues_)rU   r_   rr   r   rz  ry  r   )re   r  rE  grprY   rY   rZ   r%    s   $
r%  	dtype_strc                 C  s   t | } | drd}|S | drd}|S | drd}|S | dr(d}|S | dr1| }|S | dr:d	}|S | d
rCd
}|S | drLd}|S | drUd}|S | dkr]d}|S | dkred}|S td|  d)zA
    Find the "kind" string describing the given dtype name.
    )r  r  r  r  r.  )rh   rS  r  rc  Z	timedeltarf  r   r,  rU  r  r_   zcannot interpret dtype of [r0  )r[   r~  r   )r  rq  rY   rY   rZ   r@    sF   








r@  c                 C  sv   t | tr| j} t | jtrd| jj d}n| jj}| jjdv r*t	| 
d} nt | tr2| j} t	| } | |fS )zJ
    Convert the passed data into a storable form and a dtype string.
    r  r0  ZmMr  )rU   r6   rH  r  r'   r  re   rq  rV   rs  r  r/   r  )r  rA  rY   rY   rZ   r?    s   


r?  c                   @  s:   e Zd ZdZ			ddd
dZdd Zdd Zdd ZdS )r1  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

    Nry   r  r   r   r   r^   r   c                 C  sV  || _ || _|| _|| _d | _d | _d | _d | _t|rt	t
d tj|dd}|dv r}t|}|jtjkrV| j| j}}|d u rDd}|d u rL| j j}t||| | _n't|jjtjr}| jd urj|| jk  sv| jd urz|| jk rzt
d|| _W d    n1 sw   Y  | jd u r| || _| jd ur| j \| _| _d S d S d S )NFr  )r  Zbooleanr   z3where must have index locations >= start and < stop)ry   rs   r   r   	conditionrW  Ztermsr=  r#   r   r   r   r  rV   rs  r  Zbool_r  re  
issubclassr   r  ru  generateZevaluate)r   ry   rs   r   r   ZinferredrY   rY   rZ   r   6  sF   



zSelection.__init__c              
   C  sr   |du rdS | j  }z
t||| j jdW S  ty8 } zd| }td| d| d}t||d}~ww )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
                )	ry   r  r:   r\   	NameErrorr  r  r   r   )r   rs   r#  rQ  Zqkeysr  rY   rY   rZ   r  c  s"   

	zSelection.generatec                 C  sX   | j dur| jjj| j  | j| jdS | jdur!| jj| jS | jjj| j| jdS )(
        generate the selection
        Nr  )	r  ry   Z
read_wherer   r   r   r=  r&  r  r   rY   rY   rZ   r   z  s   

zSelection.selectc                 C  s   | j | j}}| jj}|du rd}n|dk r||7 }|du r!|}n|dk r)||7 }| jdur<| jjj| j ||ddS | jdurD| jS t	||S )r  Nr   T)r   r   r|  )
r   r   ry   r  r  Zget_where_listr   r=  rV   re  )r   r   r   r  rY   rY   rZ   r]    s"   

zSelection.select_coordsr  )ry   r  r   r   r   r   r^   r   )r   r  r  r  r   r  r   r]  rY   rY   rY   rZ   r1  *  s    -r1  )r\   r]   r^   r_   )rg   rh   )r   NNFNTNNNNr~   rT   )r   r   r   r_   r   r   r   r_   r   r   r   r]   r   r   r   r]   r   r   r   r   r   r   r   r   r   r_   r\   r_   r^   r   )	Nr   r~   NNNNFN)r   r   r   r_   r   r_   rs   r   r   r   r   r   r   r   r   r   r   r   )r   rJ   r   rJ   r^   r   r`   )r  r+   r9  rM   rX  r-   r^   r+   )r  r   r^   r  r  )rh  r  r  r  re  r   r^   r,   )rh  r  r  r   re  r   r^   r  )rh  r  r  r  re  r   r^   r  )
re   r_   r   r-   r\   r_   r   r_   r^   r  )rq  r_   r\   r_   r   r_   r^   r  )re   r_   rl  rL   r   r   )r  r  r\   r_   r   r_   r^   r  )rh  r  r  r_   r\   r_   r   r_   )rq  r_   r\   r_   r   r_   )rq  r_   r^   r   )re   r_   r  r  r^   r_   )r  r_   r^   r_   )r  rL   )r  Z
__future__r   
contextlibr   r  r  r   r   r>  r   rz  textwrapr   typingr   r   r	   r
   r   r   r   r"  ZnumpyrV   Zpandas._configr   r   r   r   Zpandas._libsr   r   r  Zpandas._libs.libr   Zpandas._libs.tslibsr   Zpandas.compatr   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/   r0   r1   r2   r3   r4   r5   Zpandas.core.arraysr6   r7   r8   Zpandas.core.arrays.string_r9   Zpandas.core.commoncorecommonrN  Z pandas.core.computation.pytablesr:   r;   Zpandas.core.constructionr<   r  r=   Zpandas.core.indexes.apir>   Zpandas.core.internalsr?   r@   Zpandas.io.commonrA   Zpandas.io.formats.printingrB   rC   Zcollections.abcrD   rE   rF   typesrG   r   rH   rI   rJ   Zpandas._typingrK   rL   rM   rN   rO   rP   rQ   rR   rS   r  ra   r[   rc   rf   rk   rt   ru   r  rv   rw   r  rb  r|   r}   Zconfig_prefixZregister_optionZis_boolZis_one_of_factoryr   r   r   r   r   r   r   r!  r  r0  r5  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r=  r  r   r  r  r@  r  rx  r  r  r  r%  r@  r?  r1  rY   rY   rY   rZ   <module>   sB   $	 4(



: 
#           (p  8   -   2g       x dz1C,

'
@

O

*




#