U
    `»{jB  ã                   @  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ZddlmZ ddlmZmZmZ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 dd	l m!Z!m"Z# dd
l$m%Z% ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZE ddlFmGZG ddlHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQ ddlRmSZS ddlTmUZUmVZVmWZW ddlXmY  mZZ[ ddl\m]Z]m^Z^ ddl_m`Z` ddlambZb ddlcmdZdmeZe ddlfmgZg ddlhmiZimjZj e�rNddlkmlZlmmZmmnZn ddlcmoZo dZpdZqd d!„ Zrd"d#„ Zsd$d%„ Zte]Zud&d'œd(d)„Zvd*Zwd+exd,< d-Zyd+exd.< d/Zzd+exd0< d1d1d2d2d3œZ{eIdgiZ|d4Z}d+exd5< d6Z~d+exd7< e d8¡�8 ej€d9d:e}ej�d;� ej€d<de~e ‚d1d2dg¡d;� W 5 Q R X daƒd:a„d=d>„ Z…dºdBdCdDdCdEdFdGdFdGdHdIdJdCdCdKdLœdMdN„Z†d»dBdCdCdPdEdEdQdGdEdRœ	dSdT„Z‡dUdUdGdVœdWdX„ZˆG dYdZ„ dZƒZ‰G d[d\„ d\ƒZŠG d]d^„ d^ƒZ‹G d_d`„ d`e‹ƒZŒG dadb„ dbe‹ƒZ�G dcdd„ dde�ƒZŽG dedf„ dfeŽƒZ�G dgdh„ dhƒZ�G didj„ dje�ƒZ‘G dkdl„ dle‘ƒZ’G dmdn„ dne‘ƒZ“G dodp„ dpe“ƒZ”G dqdr„ dre�ƒZ•G dsdt„ dte•ƒZ–G dudv„ dve•ƒZ—G dwdx„ dxe—ƒZ˜G dydz„ dze˜ƒZ™G d{d|„ d|e™ƒZšG d}d~„ d~e˜ƒZ›G dd€„ d€e˜ƒZœd¼d�d&d‚d�dƒœd„d…„Z�d†d‡dˆœd‰dŠ„Zžed½d‹d‡dGdŒd�œdŽd�„ƒZŸed¾d‹dKdGd�d�œd‘d�„ƒZŸd¿d‹d’dGd“d�œd”d�„ZŸdCd‚dCdCd^d•œd–d—„Z dCdCdCd‹d˜œd™dš„Z¡dCd›dœd�œdždŸ„Z¢d�dCdCd�d œd¡d¢„Z£d�dCdCd�d œd£d¤„Z¤d�dCdCdCd¥œd¦d§„Z¥dCdCdCd¨œd©dª„Z¦dCdGd«œd¬d­„Z§dCd®dCd¯œd°d±„Z¨dCdCd²œd³d´„Z©d›dµœd¶d·„ZªG d¸d¹„ d¹ƒZ«d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ÚHashableÚIteratorÚLiteralÚSequenceÚcastÚoverload)ÚconfigÚ
get_option)ÚlibÚwriters)Ú	timezones)ÚAnyArrayLikeÚ	ArrayLikeÚDtypeArgÚFilePathÚShapeÚnpt)Úimport_optional_dependency)Úpatch_pickle)ÚAttributeConflictWarningÚClosedFileErrorÚIncompatibilityWarningÚPerformanceWarningÚPossibleDataLossError)Úcache_readonly)Úfind_stack_level)
Úensure_objectÚis_categorical_dtypeÚis_complex_dtypeÚis_datetime64_dtypeÚis_datetime64tz_dtypeÚis_extension_array_dtypeÚis_list_likeÚis_string_dtypeÚis_timedelta64_dtypeÚneeds_i8_conversion)Úarray_equivalent)	Ú	DataFrameÚDatetimeIndexÚIndexÚ
MultiIndexÚPeriodIndexÚSeriesÚTimedeltaIndexÚconcatÚisna)Ú
Int64Index)ÚCategoricalÚDatetimeArrayÚPeriodArray)ÚPyTablesExprÚmaybe_expression)Úextract_array)Úensure_index)ÚArrayManagerÚBlockManager)Ústringify_path)ÚadjoinÚpprint_thing)ÚColÚFileÚNode)ÚBlockz0.15.2úUTF-8c                 C  s   t | tjƒr|  d¡} | S )z(if we have bytes, decode them to unicoderJ   )Ú
isinstanceÚnpÚbytes_Údecode)Ús© rP   úQ/var/www/html/bwave/python/venv/lib/python3.8/site-packages/pandas/io/pytables.pyÚ_ensure_decoded‚   s    
rR   c                 C  s   | d krt } | S ©N)Ú_default_encoding©ÚencodingrP   rP   rQ   Ú_ensure_encoding‰   s    rW   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
    )rK   Ústr©ÚnamerP   rP   rQ   Ú_ensure_str‘   s    
r[   Úint©Úscope_levelc                   sV   |d ‰ t | ttfƒr*‡ fdd„| D ƒ} nt| ƒr>t| ˆ d�} | dksNt| ƒrR| S dS )zÔ
    Ensure that the where is a Term or a list of Term.

    This makes sure that we are capturing the scope of variables that are
    passed create the terms here with a frame_level=2 (we are 2 levels down)
    é   c                   s0   g | ](}|d k	rt |ƒr(t|ˆ d d�n|‘qS )Nr_   r]   )r>   ÚTerm)Ú.0Úterm©ÚlevelrP   rQ   Ú
<listcomp>«   s   þz _ensure_term.<locals>.<listcomp>r]   N)rK   ÚlistÚtupler>   r`   Úlen)Úwherer^   rP   rc   rQ   Ú_ensure_term    s    	
þrj   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)Úfrn   Útro   z;
: boolean
    drop ALL nan rows when appending to a table
Ú
dropna_docz~
: format
    default format writing format, if None, then
    put will default to 'fixed' and append will default to 'table'
Ú
format_doczio.hdfZdropna_tableF)Ú	validatorÚdefault_formatc               	   C  s8   t d kr4dd l} | a ttƒ� | jjdkaW 5 Q R X t S )Nr   Ústrict)Ú
_table_modÚtablesr   ÚAttributeErrorÚfileZ_FILE_OPEN_POLICYÚ!_table_file_open_policy_is_strict)rx   rP   rP   rQ   Ú_tablesä   s    

ÿr|   ÚaTrv   zFilePath | HDFStorerX   úDataFrame | Seriesú
int | Noneú
str | NoneÚboolúint | dict[str, int] | Noneúbool | Noneú Literal[True] | list[str] | NoneÚNone)Úpath_or_bufÚkeyÚvalueÚmodeÚ	complevelÚcomplibÚappendÚformatÚindexÚmin_itemsizeÚdropnaÚdata_columnsÚerrorsrV   Úreturnc              
     s†   |r$‡ ‡‡‡‡‡‡‡‡‡	f
dd„}n‡ ‡‡‡‡‡‡‡‡‡	f
dd„}t | ƒ} t| tƒrzt| |||d��}||ƒ W 5 Q R X n|| ƒ dS )z+store this object, close it if we opened itc                   s   | j ˆˆ	ˆˆˆˆˆˆ ˆˆd�
S )N)r�   rŽ   r�   Únan_repr�   r‘   r’   rV   )rŒ   ©Ústore©
r‘   r�   rV   r’   r�   rŽ   r‡   r�   r”   rˆ   rP   rQ   Ú<lambda>  s   özto_hdf.<locals>.<lambda>c                   s   | j ˆˆ	ˆˆˆˆˆ ˆˆˆd�
S )N)r�   rŽ   r�   r”   r‘   r’   rV   r�   ©Úputr•   r—   rP   rQ   r˜     s   ö)r‰   rŠ   r‹   N)rC   rK   rX   ÚHDFStore)r†   r‡   rˆ   r‰   rŠ   r‹   rŒ   r�   rŽ   r�   r”   r�   r‘   r’   rV   rp   r–   rP   r—   rQ   Úto_hdfú   s     
   ÿrœ   Úrzstr | list | Nonezlist[str] | None)	r†   r‰   r’   ri   ÚstartÚstopÚcolumnsÚiteratorÚ	chunksizec
                 K  sˆ  |dkrt d|› d�ƒ‚|dk	r,t|dd�}t| tƒrN| jsDtdƒ‚| }d}nvt| ƒ} t| tƒshtd	ƒ‚zt	j
 | ¡}W n tt fk
r”   d}Y nX |sªtd
| › d�ƒ‚t| f||dœ|
—Ž}d}zx|dk�r"| ¡ }t|ƒdkrìt dƒ‚|d }|dd… D ]}t||ƒ�s t dƒ‚�q |j}|j|||||||	|d�W S  t ttfk
�r‚   t| tƒ�s|ttƒ� | ¡  W 5 Q R X ‚ Y nX dS )a)	  
    Read from the store, close it if we opened it.

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

    .. warning::

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

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

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

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

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

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

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

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

    Examples
    --------
    >>> df = pd.DataFrame([[1, 1.0, 'a']], columns=['x', 'y', 'z'])  # doctest: +SKIP
    >>> df.to_hdf('./store.h5', 'data')  # doctest: +SKIP
    >>> reread = pd.read_hdf('./store.h5')  # doctest: +SKIP
    )r�   úr+r}   zmode zG is not allowed while performing a read. Allowed modes are r, r+ and a.Nr_   r]   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.)ri   rž   rŸ   r    r¡   r¢   Ú
auto_close)Ú
ValueErrorrj   rK   r›   Úis_openÚOSErrorrC   rX   ÚNotImplementedErrorÚosÚpathÚexistsÚ	TypeErrorÚFileNotFoundErrorÚgroupsrh   Ú_is_metadata_ofÚ_v_pathnameÚselectÚKeyErrorr   ry   Úclose)r†   r‡   r‰   r’   ri   rž   rŸ   r    r¡   r¢   Úkwargsr–   r¤   r«   r®   Zcandidate_only_groupZgroup_to_checkrP   rP   rQ   Úread_hdf2  sj    O
ÿ

ÿ

ÿÿø

rµ   rH   )ÚgroupÚparent_groupr“   c                 C  sF   | j |j krdS | }|j dkrB|j}||kr:|jdkr:dS |j}qdS )zDCheck if a given group is a metadata group for a given parent_group.Fr_   ÚmetaT)Z_v_depthZ	_v_parentÚ_v_name)r¶   r·   ÚcurrentÚparentrP   rP   rQ   r¯   Í  s    
r¯   c                   @  s"  e Zd ZU dZded< ded< ded< ded	< d“dddddœdd„Zddœdd„Zedd„ ƒZeddœdd„ƒZ	ddœdd„Z
dddœdd„Zdddœdd „Zdd!œd"d#„Zdddœd$d%„Zddœd&d'„Zddœd(d)„Zd dœd*d+„Zddœd,d-„Zd”dd/d0œd1d2„Zd3dœd4d5„Zd6dœd7d8„Zd9d:„ Zd•ddd;œd<d=„Zddœd>d?„Zeddœd@dA„ƒZd–dddBœdCdD„ZddœdEdF„Zd—dddGœdHdI„Zd˜ddddJœdKdL„Zd™dddddMœdNdO„ZdšddPœdQdR„Zd›ddUddVdWdddddXœ	dYdZ„Z dœdddœd[d\„Z!d�ddUddVd]dWddd^œd_d`„Z"dždaddbœdcdd„Z#dŸdddeddfœdgdh„Z$didœdjdk„Z%d ddmdnœdodp„Z&ddqdœdrds„Z'ddtdœdudv„Z(d¡dddd dxœdydz„Z)ddœd{d|„Z*d}d~„ Z+dddœd€d�„Z,d¢dƒdddtd„œd…d†„Z-d£ddUddVdddd‡œdˆd‰„Z.dŠd‹œdŒd�„Z/dddŠdŽœd�d�„Z0ddŠdœd‘d’„Z1dS )¤r›   aa	  
    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.
        As of v0.20.2 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Ú_handlerX   Ú_moder\   Ú
_complevelr�   Ú_fletcher32r}   NFr   r…   )r‰   rŠ   Ú
fletcher32r“   c                 K  s²   d|krt dƒ‚tdƒ}|d k	r@||jjkr@t d|jj› d�ƒ‚|d krX|d k	rX|jj}t|ƒ| _|d krnd}|| _d | _|r‚|nd| _	|| _
|| _d | _| jf d|i|—Ž d S )	Nr�   z-format is not a defined argument for HDFStorerx   zcomplib only supports z compression.r}   r   r‰   )r¥   r   ÚfiltersZall_complibsZdefault_complibrC   Ú_pathr½   r¼   r¾   Ú_complibr¿   Ú_filtersÚopen)Úselfrª   r‰   rŠ   r‹   rÀ   r´   rx   rP   rP   rQ   Ú__init__"  s&    
ÿ
zHDFStore.__init__©r“   c                 C  s   | j S rS   ©rÂ   ©rÆ   rP   rP   rQ   Ú
__fspath__D  s    zHDFStore.__fspath__c                 C  s   |   ¡  | jdk	st‚| jjS )zreturn the root nodeN)Ú_check_if_openr¼   ÚAssertionErrorÚrootrÊ   rP   rP   rQ   rÎ   G  s    zHDFStore.rootc                 C  s   | j S rS   rÉ   rÊ   rP   rP   rQ   ÚfilenameN  s    zHDFStore.filename©r‡   c                 C  s
   |   |¡S rS   )Úget©rÆ   r‡   rP   rP   rQ   Ú__getitem__R  s    zHDFStore.__getitem__©r‡   r“   c                 C  s   |   ||¡ d S rS   r™   )rÆ   r‡   rˆ   rP   rP   rQ   Ú__setitem__U  s    zHDFStore.__setitem__c                 C  s
   |   |¡S rS   )ÚremoverÒ   rP   rP   rQ   Ú__delitem__X  s    zHDFStore.__delitem__rY   c              	   C  sF   z|   |¡W S  ttfk
r$   Y nX tdt| ƒj› d|› d�ƒ‚dS )z$allow attribute access to get storesú'z' object has no attribute 'N)rÑ   r²   r   ry   ÚtypeÚ__name__)rÆ   rZ   rP   rP   rQ   Ú__getattr__[  s    ÿzHDFStore.__getattr__c                 C  s8   |   |¡}|dk	r4|j}||ks0|dd… |kr4dS dS )zx
        check for existence of this key
        can match the exact pathname or the pathnm w/o the leading '/'
        Nr_   TF)Úget_noder°   )rÆ   r‡   ÚnoderZ   rP   rP   rQ   Ú__contains__e  s    
zHDFStore.__contains__c                 C  s   t |  ¡ ƒS rS   )rh   r®   rÊ   rP   rP   rQ   Ú__len__q  s    zHDFStore.__len__c                 C  s   t | jƒ}t| ƒ› d|› d�S )Nú
File path: Ú
)rE   rÂ   rÙ   )rÆ   ZpstrrP   rP   rQ   Ú__repr__t  s    
zHDFStore.__repr__c                 C  s   | S rS   rP   rÊ   rP   rP   rQ   Ú	__enter__x  s    zHDFStore.__enter__c                 C  s   |   ¡  d S rS   )r³   )rÆ   Úexc_typeÚ	exc_valueÚ	tracebackrP   rP   rQ   Ú__exit__{  s    zHDFStore.__exit__Úpandasú	list[str])Úincluder“   c                 C  s^   |dkrdd„ |   ¡ D ƒS |dkrJ| jdk	s0t‚dd„ | jjddd	�D ƒS td
|› d�ƒ‚dS )a#  
        Return a list of keys corresponding to objects stored in HDFStore.

        Parameters
        ----------

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

                .. versionadded:: 1.1.0

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

        Raises
        ------
        raises ValueError if kind has an illegal value
        rè   c                 S  s   g | ]
}|j ‘qS rP   ©r°   ©ra   ÚnrP   rP   rQ   re   •  s     z!HDFStore.keys.<locals>.<listcomp>ÚnativeNc                 S  s   g | ]
}|j ‘qS rP   rë   rì   rP   rP   rQ   re   ™  s    ú/ÚTable)Ú	classnamez8`include` should be either 'pandas' or 'native' but is 'rØ   )r®   r¼   rÍ   Z
walk_nodesr¥   )rÆ   rê   rP   rP   rQ   Úkeys~  s    ÿ
ÿzHDFStore.keyszIterator[str]c                 C  s   t |  ¡ ƒS rS   )Úiterrò   rÊ   rP   rP   rQ   Ú__iter__   s    zHDFStore.__iter__zIterator[tuple[str, list]]c                 c  s   |   ¡ D ]}|j|fV  qdS )ú'
        iterate on key->group
        N)r®   r°   )rÆ   ÚgrP   rP   rQ   Úitems£  s    zHDFStore.itemsc                 c  s*   t jdttt ¡ ƒd� |  ¡ E dH  dS )rõ   zTiteritems is deprecated and will be removed in a future version. Use .items instead.©Ú
stacklevelN)ÚwarningsÚwarnÚFutureWarningr$   ÚinspectÚcurrentframer÷   rÊ   rP   rP   rQ   Ú	iteritemsª  s    
üzHDFStore.iteritems)r‰   r“   c                 K  sº   t ƒ }| j|krR| jdkr$|dkr$n(|dkrL| jrLtd| j› d| j› d�ƒ‚|| _| jr`|  ¡  | jrŠ| jdkrŠt ƒ j| j| j| j	d�| _
tr | jr d	}t|ƒ‚|j| j| jf|Ž| _d
S )a9  
        Open the file in the specified mode

        Parameters
        ----------
        mode : {'a', 'w', 'r', 'r+'}, default 'a'
            See HDFStore docstring or tables.open_file for info about modes
        **kwargs
            These parameters will be passed to the PyTables open_file method.
        )r}   Úw)r�   r£   )r   zRe-opening the file [z] with mode [z] will delete the current file!r   )rÀ   zGCannot open HDF5 file, which is already opened, even in read-only mode.N)r|   r½   r¦   r"   rÂ   r³   r¾   ÚFiltersrÃ   r¿   rÄ   r{   r¥   Ú	open_filer¼   )rÆ   r‰   r´   rx   ÚmsgrP   rP   rQ   rÅ   ¶  s.    
ÿ  ÿ
ÿzHDFStore.openc                 C  s   | j dk	r| j  ¡  d| _ dS )z0
        Close the PyTables file handle
        N)r¼   r³   rÊ   rP   rP   rQ   r³   ã  s    

zHDFStore.closec                 C  s   | j dkrdS t| j jƒS )zF
        return a boolean indicating whether the file is open
        NF)r¼   r�   ZisopenrÊ   rP   rP   rQ   r¦   ë  s    
zHDFStore.is_open)Úfsyncr“   c              	   C  s@   | j dk	r<| j  ¡  |r<ttƒ� t | j  ¡ ¡ W 5 Q R X 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  rP   rP   rQ   r  ô  s
    


zHDFStore.flushc              
   C  sJ   t ƒ �: |  |¡}|dkr*td|› d�ƒ‚|  |¡W  5 Q R £ S Q R X dS )zÑ
        Retrieve pandas object stored in file.

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

        Returns
        -------
        object
            Same type as object stored in file.
        NúNo object named ú in the file)r   rÜ   r²   Ú_read_group©rÆ   r‡   r¶   rP   rP   rQ   rÑ   
  s
    
zHDFStore.get)r‡   r¤   c	                   st   |   |¡}	|	dkr"td|› d�ƒ‚t|dd�}|  |	¡‰ˆ ¡  ‡ ‡fdd„}
t| ˆ|
|ˆj|||||d�
}| ¡ S )	aÖ  
        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.
        Nr  r  r_   r]   c                   s   ˆj | ||ˆ d�S )N)rž   rŸ   ri   r    ©Úread©Ú_startÚ_stopÚ_where©r    rO   rP   rQ   ÚfuncW  s    zHDFStore.select.<locals>.func©ri   Únrowsrž   rŸ   r¡   r¢   r¤   )rÜ   r²   rj   Ú_create_storerÚ
infer_axesÚTableIteratorr  Ú
get_result)rÆ   r‡   ri   rž   rŸ   r    r¡   r¢   r¤   r¶   r  ÚitrP   r  rQ   r±     s(    .

özHDFStore.select©r‡   rž   rŸ   c                 C  s8   t |dd�}|  |¡}t|tƒs(tdƒ‚|j|||d�S )a“  
        return the selection as an Index

        .. warning::

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

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


        Parameters
        ----------
        key : str
        where : list of Term (or convertible) objects, optional
        start : integer (defaults to None), row number to start selection
        stop  : integer (defaults to None), row number to stop selection
        r_   r]   z&can only read_coordinates with a table©ri   rž   rŸ   )rj   Ú
get_storerrK   rð   r¬   Úread_coordinates)rÆ   r‡   ri   rž   rŸ   ÚtblrP   rP   rQ   Úselect_as_coordinatesj  s
    

zHDFStore.select_as_coordinates)r‡   Úcolumnrž   rŸ   c                 C  s,   |   |¡}t|tƒstdƒ‚|j|||d�S )a~  
        return a single column from the table. This is generally only useful to
        select an indexable

        .. warning::

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

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

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

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

        z!can only read_column with a table©r   rž   rŸ   )r  rK   rð   r¬   Úread_column)rÆ   r‡   r   rž   rŸ   r  rP   rP   rQ   Úselect_columnŠ  s    #

zHDFStore.select_column)r¤   c
                   sz  t |dd�}t|ttfƒr.t|ƒdkr.|d }t|tƒrRˆj||ˆ|||||	d�S t|ttfƒshtdƒ‚t|ƒsxtdƒ‚|dkrˆ|d }‡fdd	„|D ƒ‰ˆ 	|¡}
d}t
 |
|fgtˆ|ƒ¡D ]\\}}|dkràtd
|› d�ƒ‚|jsøtd|j› d�ƒ‚|dk�r
|j}qÀ|j|krÀtdƒ‚qÀdd	„ ˆD ƒ}t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
        r_   r]   r   )r‡   ri   r    rž   rŸ   r¡   r¢   r¤   zkeys must be a list/tuplez keys must have a non-zero lengthNc                   s   g | ]}ˆ   |¡‘qS rP   )r  ©ra   ÚkrÊ   rP   rQ   re   ö  s     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 rP   )rK   rð   ©ra   ÚxrP   rP   rQ   re     s     
 c                 S  s   h | ]}|j d  d  ’qS ©r   )Únon_index_axes©ra   rq   rP   rP   rQ   Ú	<setcomp>  s     z.HDFStore.select_as_multiple.<locals>.<setcomp>c                   s*   ‡ ‡‡‡fdd„ˆD ƒ}t |ˆdd� ¡ S )Nc                   s   g | ]}|j ˆˆˆ ˆd �‘qS )©ri   r    rž   rŸ   r  r+  )r  r  r  r    rP   rQ   re     s   ÿz=HDFStore.select_as_multiple.<locals>.func.<locals>.<listcomp>F)ÚaxisÚverify_integrity)r7   Ú_consolidate)r  r  r  Zobjs)r.  r    Útblsr  rQ   r    s    þz)HDFStore.select_as_multiple.<locals>.funcr  T©Úcoordinates)rj   rK   rf   rg   rh   rX   r±   r¬   r¥   r  Ú	itertoolsÚchainÚzipr²   Úis_tableÚpathnamer  r  r  )rÆ   rò   ri   Úselectorr    rž   rŸ   r¡   r¢   r¤   rO   r  rq   r%  Z_tblsr  r  rP   )r.  r    rÆ   r1  rQ   Úselect_as_multiple²  sd    +
ø
 ÿ


özHDFStore.select_as_multipleTrv   r~   r‚   r„   )	r‡   rˆ   rŠ   r�   r‘   r’   Útrack_timesr�   r“   c                 C  sH   |dk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.

            .. versionadded:: 1.1.0
        Núio.hdf.default_formatrn   )r�   rŽ   rŒ   r‹   rŠ   r�   r”   r‘   rV   r’   r;  r�   )r   Ú_validate_formatÚ_write_to_group)rÆ   r‡   rˆ   r�   rŽ   rŒ   r‹   rŠ   r�   r”   r‘   rV   r’   r;  r�   rP   rP   rQ   rš   ,  s&    4
òzHDFStore.putc              
   C  sà   t |dd�}z|  |¡}W n„ tk
r0   ‚ Y np tk
rD   ‚ Y n\ tk
rž } z>|dk	rftdƒ|‚|  |¡}|dk	rŽ|jdd� W Y ¢dS W 5 d}~X Y nX t 	|||¡r¾|j
jdd� n|jsÌtdƒ‚|j|||d�S dS )	a:  
        Remove pandas object partially by specifying the where condition

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

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

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

        r_   r]   Nz5trying to remove a node with a non-None where clause!T©Ú	recursivez7can only remove with where on objects written as tablesr  )rj   r  r²   rÍ   Ú	Exceptionr¥   rÜ   Z	_f_removeÚcomÚall_noner¶   r7  Údelete)rÆ   r‡   ri   rž   rŸ   rO   ÚerrrÝ   rP   rP   rQ   rÖ   t  s2    ÿþ
ÿzHDFStore.removerƒ   )r‡   rˆ   rŠ   r�   r�   r‘   r’   r“   c                 C  sl   |	dk	rt dƒ‚|dkr tdƒ}|dkr4tdƒp2d}|  |¡}| j|||||||||
|||||||d� dS )a“  
        Append to Table in file.

        Node must already exist and be Table format.

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

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

        Notes
        -----
        Does *not* check if data being appended overlaps with existing
        data in the table, so be careful
        Nz>columns is not a supported keyword in append, try data_columnszio.hdf.dropna_tabler<  ro   )r�   ÚaxesrŽ   rŒ   r‹   rŠ   r�   r”   r¢   Úexpectedrowsr�   r‘   rV   r’   )r¬   r   r=  r>  )rÆ   r‡   rˆ   r�   rF  rŽ   rŒ   r‹   rŠ   r    r�   r”   r¢   rG  r�   r‘   rV   r’   rP   rP   rQ   rŒ   ­  s6    ;ÿ
ðzHDFStore.appendÚdict)Údr“   c                   s¬  |dk	rt dƒ‚t|tƒs"tdƒ‚||kr2tdƒ‚tttˆjƒƒttt	ˆƒ ƒ ƒd }d}	g }
| 
¡ D ]0\}‰ ˆ dkrŽ|	dk	rˆtdƒ‚|}	qh|
 ˆ ¡ qh|	dk	rÖˆj| }| t|
ƒ¡}t| |¡ƒ}| |¡||	< |dkræ|| }|�r*‡fdd„| ¡ D ƒ}t|ƒ}|D ]}| |¡}�qˆj| ‰| d	d¡}| 
¡ D ]h\}‰ ||k�rT|nd}ˆjˆ |d
�}|dk	�r†‡ fdd„| 
¡ D ƒnd}| j||f||dœ|—Ž �q>dS )a  
        Append to multiple tables

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

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

        Nztaxes is currently not accepted as a parameter to append_to_multiple; you can create the tables independently insteadzQappend_to_multiple must have a dictionary specified as the way to split the valuez=append_to_multiple requires a selector that is in passed dictr   z<append_to_multiple can only have one value in d that is Nonec                 3  s    | ]}ˆ | j d d�jV  qdS )Úall)ÚhowN)r�   rŽ   )ra   Úcols)rˆ   rP   rQ   Ú	<genexpr>P  s     z.HDFStore.append_to_multiple.<locals>.<genexpr>r�   ©r.  c                   s   i | ]\}}|ˆ kr||“qS rP   rP   ©ra   r‡   rˆ   )ÚvrP   rQ   Ú
<dictcomp>`  s       z/HDFStore.append_to_multiple.<locals>.<dictcomp>)r‘   r�   )r¬   rK   rH  r¥   rf   ÚsetÚrangeÚndimÚ	_AXES_MAPrÙ   r÷   ÚextendrF  Ú
differencer2   ÚsortedÚget_indexerÚtakeÚvaluesÚnextÚintersectionÚlocÚpopÚreindexrŒ   )rÆ   rI  rˆ   r9  r‘   rF  r�   r´   r.  Z
remain_keyZremain_valuesr%  ÚorderedZorddZidxsZvalid_indexrŽ   r�   ÚdcÚvalÚfilteredrP   )rP  rˆ   rQ   Úappend_to_multiple  sZ    ÿ
ÿÿ&ÿ

ÿýzHDFStore.append_to_multipler€   )r‡   ÚoptlevelÚkindr“   c                 C  sB   t ƒ  |  |¡}|dk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    rf  rg  )r|   r  rK   rð   r¬   Úcreate_index)rÆ   r‡   r    rf  rg  rO   rP   rP   rQ   Úcreate_table_indexf  s    

zHDFStore.create_table_indexrf   c                 C  s<   t ƒ  |  ¡  | jdk	st‚tdk	s(t‚dd„ | j ¡ D ƒS )zÂ
        Return a list of all the top-level nodes.

        Each node returned is not a pandas storage object.

        Returns
        -------
        list
            List of objects.
        Nc                 S  sP   g | ]H}t |tjjƒst|jd dƒsHt|ddƒsHt |tjjƒr|jdkr|‘qS )Úpandas_typeNro   )	rK   rw   ÚlinkÚLinkÚgetattrÚ_v_attrsro   rð   r¹   )ra   rö   rP   rP   rQ   re   �  s    
ùz#HDFStore.groups.<locals>.<listcomp>)r|   rÌ   r¼   rÍ   rw   Úwalk_groupsrÊ   rP   rP   rQ   r®   Ž  s    þzHDFStore.groupsrï   z*Iterator[tuple[str, list[str], list[str]]])ri   r“   c                 c  s¼   t ƒ  |  ¡  | jdk	st‚tdk	s(t‚| j |¡D ]‚}t|jddƒdk	rLq4g }g }|j 	¡ D ]B}t|jddƒ}|dkr”t
|tjjƒr | |j¡ q^| |j¡ q^|j d¡||fV  q4dS )aS  
        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`.
        Nrj  rï   )r|   rÌ   r¼   rÍ   rw   ro  rm  rn  Z_v_childrenr[  rK   r¶   ÚGrouprŒ   r¹   r°   Úrstrip)rÆ   ri   rö   r®   ÚleavesÚchildrj  rP   rP   rQ   Úwalkª  s     zHDFStore.walkzNode | Nonec                 C  s€   |   ¡  | d¡sd| }| jdk	s(t‚tdk	s4t‚z| j | j|¡}W n tjjk
rb   Y dS X t	|tj
ƒs|tt|ƒƒ‚|S )z9return the node with the key or None if it does not existrï   N)rÌ   Ú
startswithr¼   rÍ   rw   rÜ   rÎ   Ú
exceptionsZNoSuchNodeErrorrK   rH   rÙ   )rÆ   r‡   rÝ   rP   rP   rQ   rÜ   Ú  s    
zHDFStore.get_nodeúGenericFixed | Tablec                 C  s8   |   |¡}|dk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¶   rO   rP   rP   rQ   r  ê  s    

zHDFStore.get_storerr   )ÚpropindexesrŠ   rÀ   r“   c	              	   C  sÎ   t |||||d�}	|dkr&t|  ¡ ƒ}t|ttfƒs:|g}|D ]Š}
|  |
¡}|dk	r>|
|	krj|rj|	 |
¡ |  |
¡}t|tƒr¶d}|r–dd„ |j	D ƒ}|	j
|
||t|ddƒ|jd� q>|	j|
||jd� q>|	S )	a;  
        Copy the existing store to a new file, updating in place.

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

        Returns
        -------
        open file handle of the new store
        )r‰   r‹   rŠ   rÀ   NFc                 S  s   g | ]}|j r|j‘qS rP   )Ú
is_indexedrZ   ©ra   r}   rP   rP   rQ   re   $  s      z!HDFStore.copy.<locals>.<listcomp>r‘   )rŽ   r‘   rV   rU   )r›   rf   rò   rK   rg   r  rÖ   r±   rð   rF  rŒ   rm  rV   rš   )rÆ   rz   r‰   rx  rò   r‹   rŠ   rÀ   Ú	overwriteZ	new_storer%  rO   ÚdatarŽ   rP   rP   rQ   Úcopyô  s>        ÿ




ûzHDFStore.copyc           
      C  s
  t | jƒ}t| ƒ› d|› d�}| jrþt|  ¡ ƒ}t|ƒrôg }g }|D ]œ}z<|  |¡}|dk	r‚| t |j	pj|ƒ¡ | t |p|dƒ¡ W qD t
k
rš   ‚ Y qD tk
rÞ } z(| |¡ t |ƒ}	| d|	› d�¡ W 5 d}~X Y qDX qD|td||ƒ7 }n|d7 }n|d	7 }|S )
zg
        Print detailed information on the store.

        Returns
        -------
        str
        rà   rá   Nzinvalid_HDFStore nodez[invalid_HDFStore node: r&  é   ÚEmptyzFile is CLOSED)rE   rÂ   rÙ   r¦   rX  rò   rh   r  rŒ   r8  rÍ   rA  rD   )
rÆ   rª   ÚoutputZlkeysrò   r[  r%  rO   ÚdetailZdstrrP   rP   rQ   Úinfo1  s.    


&
zHDFStore.infoc                 C  s   | j st| j› d�ƒ‚d S )Nz file is not open!)r¦   r   rÂ   rÊ   rP   rP   rQ   rÌ   [  s    zHDFStore._check_if_open)r�   r“   c              
   C  sJ   zt | ¡  }W n4 tk
rD } ztd|› d�ƒ|‚W 5 d}~X Y nX |S )zvalidate / deprecate formatsz#invalid HDFStore format specified [r&  N)Ú_FORMAT_MAPÚlowerr²   r¬   )rÆ   r�   rE  rP   rP   rQ   r=  _  s
    $zHDFStore._validate_formatrJ   zDataFrame | Series | None)rˆ   rV   r’   r“   c              
     s  ˆdk	rt ˆttfƒstdƒ‚‡ ‡‡fdd„}ttˆjddƒƒ}ttˆjddƒƒ}|dkrÆˆdkr¢tƒ  tdk	stt	‚tˆddƒsŽt ˆtj
jƒr˜d}d	}qÆtd
ƒ‚n$t ˆtƒr²d}nd}ˆ dkrÆ|d7 }d|k�r&ttdœ}	z|	| }
W n. tk
�r } z|dƒ|‚W 5 d}~X Y nX |
| ˆ||d�S |dk�rÀˆdk	�rÀ|dk�r~tˆddƒ}|dk	�rÀ|jdk�rld}n|jdk�rÀd}nB|dk�rÀtˆddƒ}|dk	�rÀ|jdk�r°d}n|jdk�rÀd}ttttttdœ}z|| }
W n. tk
�r } z|dƒ|‚W 5 d}~X Y nX |
| ˆ||d�S )z"return a suitable class to operateNz(value must be None, Series, or DataFramec              	     s$   t d| › dˆ› dtˆƒ› dˆ › �ƒS )Nz(cannot properly create the storer for: [z
] [group->ú,value->z	,format->)r¬   rÙ   )rq   ©r�   r¶   rˆ   rP   rQ   Úerrorw  s    ÿz&HDFStore._create_storer.<locals>.errorrj  Ú
table_typero   Úframe_tableÚgeneric_tablezKcannot create a storer if the object is not existing nor a value are passedÚseriesÚframeÚ_table)r‹  rŒ  Ú_STORER_MAP©rV   r’   Úseries_tablerŽ   r_   Úappendable_seriesÚappendable_multiseriesÚappendable_frameÚappendable_multiframe)rŠ  r‘  r’  r“  r”  ÚwormÚ
_TABLE_MAP)rK   r5   r0   r¬   rR   rm  rn  r|   rw   rÍ   ro   rð   ÚSeriesFixedÚ
FrameFixedr²   ÚnlevelsÚGenericTableÚAppendableSeriesTableÚAppendableMultiSeriesTableÚAppendableFrameTableÚAppendableMultiFrameTableÚ	WORMTable)rÆ   r¶   r�   rˆ   rV   r’   r‡  ÚptÚttrŽ  ÚclsrE  rŽ   r–  rP   r†  rQ   r  i  st     ÿÿ








úzHDFStore._create_storer)r‡   rˆ   rŠ   r�   r’   r;  r“   c                 C  sÎ   t |dd ƒr|dks|rd S |  ||¡}| j|||||d�}|rr|jrZ|jrb|dkrb|jrbtdƒ‚|jsz| ¡  n| ¡  |jsŒ|rŒtdƒ‚|j||||||	|
||||||d� t|t	ƒrÊ|rÊ|j
|d� d S )	NÚemptyro   r�  rn   zCan only append to Tablesz0Compression not supported on Fixed format stores)ÚobjrF  rŒ   r‹   rŠ   rÀ   r�   r¢   rG  r�   r”   r‘   r;  )r    )rm  Ú_identify_groupr  r7  Ú	is_existsr¥   Úset_object_infoÚwriterK   rð   rh  )rÆ   r‡   rˆ   r�   rF  rŽ   rŒ   r‹   rŠ   rÀ   r�   r¢   rG  r�   r”   r‘   rV   r’   r;  r¶   rO   rP   rP   rQ   r>  Å  s:    

ózHDFStore._write_to_grouprH   ©r¶   c                 C  s   |   |¡}| ¡  | ¡ S rS   )r  r  r  )rÆ   r¶   rO   rP   rP   rQ   r	    s    
zHDFStore._read_group)r‡   rŒ   r“   c                 C  sN   |   |¡}| jdk	st‚|dk	r8|s8| jj|dd� d}|dkrJ|  |¡}|S )z@Identify HDF5 group based on key, delete/create group if needed.NTr?  )rÜ   r¼   rÍ   Úremove_nodeÚ_create_nodes_and_group)rÆ   r‡   rŒ   r¶   rP   rP   rQ   r¥    s    

zHDFStore._identify_groupc                 C  sv   | j dk	st‚| d¡}d}|D ]P}t|ƒs.q |}| d¡sD|d7 }||7 }|  |¡}|dkrl| j  ||¡}|}q |S )z,Create nodes from key and return group name.Nrï   )r¼   rÍ   Úsplitrh   ÚendswithrÜ   Zcreate_group)rÆ   r‡   Úpathsrª   ÚpÚnew_pathr¶   rP   rP   rQ   r«    s    


z HDFStore._create_nodes_and_group)r}   NNF)rè   )r}   )F)NNNNFNF)NNN)NN)NNNNNFNF)NTFNNNNNNrv   TF)NNN)NNTTNNNNNNNNNNrv   )NNF)NNN)rï   )r   TNNNFT)NNrJ   rv   )NTFNNNNNNFNNNrv   T)2rÚ   Ú
__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  r#  r:  rš   rÖ   rŒ   re  ri  r®   rt  rÜ   r  r}  r‚  rÌ   r=  r  r>  r	  r¥  r«  rP   rP   rP   rQ   r›   Û  s  
A    ú"

"-       ÷N   û$  û+        ö~            ñ H=               î]   ùd   û(0       ÷=*    úa               í>r›   c                   @  sj   e Zd ZU dZded< ded< ded< dddd
dd
ddœdd„Zdd„ Zddœdd„Zdd
dœdd„ZdS )r  aa  
    Define the iteration interface on a table

    Parameters
    ----------
    store : HDFStore
    s     : the referred storer
    func  : the function to execute the query
    where : the where of the query
    nrows : the rows to iterate on
    start : the passed start value (default is None)
    stop  : the passed stop value (default is None)
    iterator : bool, default False
        Whether to use the default iterator.
    chunksize : the passed chunking value (default is 100000)
    auto_close : bool, default False
        Whether to automatically close the store at the end of iteration.
    r   r¢   r›   r–   rw  rO   NFr�   r…   )r–   rO   r¡   r¢   r¤   r“   c                 C  sš   || _ || _|| _|| _| jjrN|d kr,d}|d kr8d}|d krD|}t||ƒ}|| _|| _|| _d | _	|sr|	d k	rŠ|	d kr~d}	t
|	ƒ| _nd | _|
| _d S )Nr   é † )r–   rO   r  ri   r7  Úminr  rž   rŸ   r3  r\   r¢   r¤   )rÆ   r–   rO   r  ri   r  rž   rŸ   r¡   r¢   r¤   rP   rP   rQ   rÇ   H  s,    
zTableIterator.__init__c                 c  sv   | j }| jd krtdƒ‚|| jk rjt|| j | jƒ}|  d d | j||… ¡}|}|d kst|ƒsbq|V  q|  ¡  d S )Nz*Cannot iterate until get_result is called.)	rž   r3  r¥   rŸ   r·  r¢   r  rh   r³   )rÆ   rº   rŸ   rˆ   rP   rP   rQ   rô   r  s    

zTableIterator.__iter__rÈ   c                 C  s   | j r| j ¡  d S rS   )r¤   r–   r³   rÊ   rP   rP   rQ   r³   ‚  s    zTableIterator.closer2  c                 C  sŠ   | j d k	r4t| jtƒstdƒ‚| jj| jd�| _| S |rft| jtƒsLtdƒ‚| jj| j| j| j	d�}n| j}|  
| j| j	|¡}|  ¡  |S )Nz0can only use an iterator or chunksize on a table)ri   z$can only read_coordinates on a tabler  )r¢   rK   rO   rð   r¬   r  ri   r3  rž   rŸ   r  r³   )rÆ   r3  ri   ÚresultsrP   rP   rQ   r  †  s"    
  ÿzTableIterator.get_result)NNFNF)F)	rÚ   r±  r²  r³  r´  rÇ   rô   r³   r  rP   rP   rP   rQ   r  0  s   
	     õ*r  c                   @  s²  e Zd ZU dZdZded< dZded< dddgZd	ed
< d	ed< dNd	dddœdd„Ze	ddœdd„ƒZ
e	d	dœdd„ƒZdddœdd„Zd	dœdd„Zdddœdd „Zddœd!d"„Ze	ddœd#d$„ƒZd%d	d	d&d'œd(d)„Zd*d+„ Ze	d,d-„ ƒZe	d.d/„ ƒZe	d0d1„ ƒZe	d2d3„ ƒZd4d5„ ZdOddœd6d7„Zddœd8d9„Zd:ddd;œd<d=„ZdPd>d?„Zddd@œdAdB„ZddœdCdD„ZddœdEdF„ZddœdGdH„Zd:ddIœdJdK„Z d:ddIœdLdM„Z!dS )QÚ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_namerX   rZ   ÚcnameNr€   r…   )rZ   r¿  r“   c                 C  s    t |tƒstdƒ‚|| _|| _|| _|| _|p0|| _|| _|| _	|| _
|	| _|
| _|| _|| _|| _|| _|d k	r||  |¡ t | jtƒsŒt‚t | jtƒsœt‚d S )Nz`name` must be a str.)rK   rX   r¥   r[  rg  ÚtyprZ   r¿  r.  Úposr¼  r½  r¾  ra  ro   r¸   ÚmetadataÚset_posrÍ   )rÆ   rZ   r[  rg  rÀ  r¿  r.  rÁ  r¼  r½  r¾  ra  ro   r¸   rÂ  rP   rP   rQ   rÇ   µ  s(    


zIndexCol.__init__r\   rÈ   c                 C  s   | j jS rS   )rÀ  ÚitemsizerÊ   rP   rP   rQ   rÄ  á  s    zIndexCol.itemsizec                 C  s   | j › d�S )NÚ_kindrY   rÊ   rP   rP   rQ   Ú	kind_attræ  s    zIndexCol.kind_attr)rÁ  r“   c                 C  s$   || _ |dk	r | jdk	r || j_dS )z,set the position of this column in the TableN)rÁ  rÀ  Z_v_pos)rÆ   rÁ  rP   rP   rQ   rÃ  ê  s    zIndexCol.set_posc              	   C  sF   t tt| j| j| j| j| jfƒƒ}d dd„ t	dddddg|ƒD ƒ¡S )	Nú,c                 S  s   g | ]\}}|› d |› �‘qS ©z->rP   rO  rP   rP   rQ   re   õ  s   ÿz%IndexCol.__repr__.<locals>.<listcomp>rZ   r¿  r.  rÁ  rg  )
rg   ÚmaprE   rZ   r¿  r.  rÁ  rg  Újoinr6  ©rÆ   ÚtemprP   rP   rQ   râ   ð  s    ÿþÿzIndexCol.__repr__r   ©Úotherr“   c                   s   t ‡ ‡fdd„dD ƒƒS )úcompare 2 col itemsc                 3  s&   | ]}t ˆ|d ƒt ˆ |d ƒkV  qd S rS   ©rm  rz  ©rÎ  rÆ   rP   rQ   rM  ý  s   ÿz"IndexCol.__eq__.<locals>.<genexpr>)rZ   r¿  r.  rÁ  ©rJ  ©rÆ   rÎ  rP   rÑ  rQ   Ú__eq__û  s    þzIndexCol.__eq__c                 C  s   |   |¡ S rS   )rÔ  rÓ  rP   rP   rQ   Ú__ne__  s    zIndexCol.__ne__c                 C  s"   t | jdƒsdS t| jj| jƒjS )z%return whether I am an indexed columnrL  F)Úhasattrro   rm  rL  r¿  ry  rÊ   rP   rP   rQ   ry    s    zIndexCol.is_indexedú
np.ndarrayzCtuple[np.ndarray, np.ndarray] | tuple[DatetimeIndex, DatetimeIndex]©r[  rV   r’   r“   c           
      C  sþ   t |tjƒstt|ƒƒ‚|jjdk	r.|| j }t| j	ƒ}t
||||ƒ}i }t| jƒ|d< | jdk	rpt| jƒ|d< t}t|jƒsˆt|jƒrŽt}n|jdkr¨d|kr¨dd„ }z||f|Ž}W n0 tk
rè   d|krØd|d< ||f|Ž}Y nX t|| jƒ}	|	|	fS )zV
        Convert the data from this selection to the appropriate pandas type.
        NrZ   r¼  Úi8c                 [  s   t f d| i|—ŽS )NZordinal)r4   )r(  ÚkwdsrP   rP   rQ   r˜   *  s   ÿÿz"IndexCol.convert.<locals>.<lambda>)rK   rL   ÚndarrayrÍ   rÙ   ÚdtypeÚfieldsr¿  rR   rg  Ú_maybe_convertr¾  r¼  r2   r(   r)   r1   r¥   Ú_set_tzr½  )
rÆ   r[  r”   rV   r’   Úval_kindr´   ÚfactoryZnew_pd_indexZfinal_pd_indexrP   rP   rQ   Úconvert  s,    


zIndexCol.convertc                 C  s   | j S )zreturn the values©r[  rÊ   rP   rP   rQ   Ú	take_data:  s    zIndexCol.take_datac                 C  s   | j jS rS   )ro   rn  rÊ   rP   rP   rQ   Úattrs>  s    zIndexCol.attrsc                 C  s   | j jS rS   ©ro   ÚdescriptionrÊ   rP   rP   rQ   rç  B  s    zIndexCol.descriptionc                 C  s   t | j| jdƒS )z!return my current col descriptionN)rm  rç  r¿  rÊ   rP   rP   rQ   ÚcolF  s    zIndexCol.colc                 C  s   | j S ©zreturn my cython valuesrã  rÊ   rP   rP   rQ   ÚcvaluesK  s    zIndexCol.cvaluesc                 C  s
   t | jƒS rS   )ró   r[  rÊ   rP   rP   rQ   rô   P  s    zIndexCol.__iter__c                 C  sP   t | jƒdkrLt|tƒr$| | j¡}|dk	rL| jj|k rLtƒ j	|| j
d�| _dS )zŸ
        maybe set a string col itemsize:
            min_itemsize can be an integer or a dict with this columns name
            with an integer size
        ÚstringN)rÄ  rÁ  )rR   rg  rK   rH  rÑ   rZ   rÀ  rÄ  r|   Ú	StringColrÁ  )rÆ   r�   rP   rP   rQ   Úmaybe_set_sizeS  s
    
zIndexCol.maybe_set_sizec                 C  s   d S rS   rP   rÊ   rP   rP   rQ   Úvalidate_names`  s    zIndexCol.validate_namesÚAppendableTable)ÚhandlerrŒ   r“   c                 C  s:   |j | _ |  ¡  |  |¡ |  |¡ |  |¡ |  ¡  d S rS   )ro   Úvalidate_colÚvalidate_attrÚvalidate_metadataÚwrite_metadataÚset_attr)rÆ   rð  rŒ   rP   rP   rQ   Úvalidate_and_setc  s    


zIndexCol.validate_and_setc                 C  s^   t | jƒdkrZ| j}|dk	rZ|dkr*| j}|j|k rTtd|› d| j› d|j› d�ƒ‚|jS dS )z:validate this column: return the compared against itemsizerë  Nz#Trying to store a string with len [z] in [z)] column but
this column has a limit of [zC]!
Consider using min_itemsize to preset the sizes on these columns)rR   rg  rè  rÄ  r¥   r¿  )rÆ   rÄ  ÚcrP   rP   rQ   rñ  k  s    
ÿzIndexCol.validate_col)rŒ   r“   c                 C  sB   |r>t | j| jd ƒ}|d k	r>|| jkr>td|› d| j› d�ƒ‚d S )Nzincompatible kind in col [ú - r&  )rm  rå  rÆ  rg  r¬   )rÆ   rŒ   Zexisting_kindrP   rP   rQ   rò  ~  s    ÿzIndexCol.validate_attrc                 C  sÎ   | j D ]Â}t| |dƒ}| | ji ¡}| |¡}||kr°|dk	r°||kr°|dkrŠt|||f }tj|tt	t
 ¡ ƒd� d||< t| |dƒ qÈtd| j› d|› d|› d|› d�	ƒ‚q|dk	sÀ|dk	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¾  rø   zinvalid info for [z] for [z], existing_value [z] conflicts with new value [r&  )Ú_info_fieldsrm  Ú
setdefaultrZ   rÑ   rl   rú   rû   r   r$   rý   rþ   Úsetattrr¥   )rÆ   r‚  r‡   rˆ   ÚidxZexisting_valueÚwsrP   rP   rQ   Úupdate_info‡  s&    


ýÿzIndexCol.update_infoc                 C  s$   |  | j¡}|dk	r | j |¡ dS )z!set my state from the passed infoN)rÑ   rZ   Ú__dict__Úupdate)rÆ   r‚  rü  rP   rP   rQ   Ú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Æ  rg  rÊ   rP   rP   rQ   rõ  °  s    zIndexCol.set_attr)rð  r“   c                 C  sB   | j dkr>| j}| | j¡}|dk	r>|dk	r>t||ƒs>tdƒ‚dS )z:validate that kind=category does not change the categoriesÚcategoryNzEcannot append a categorical with different categories to the existing)r¸   rÂ  Úread_metadatar¿  r/   r¥   )rÆ   rð  Znew_metadataZcur_metadatarP   rP   rQ   ró  ´  s    
ÿþýÿzIndexCol.validate_metadatac                 C  s   | j dk	r| | j| j ¡ dS )zset the meta dataN)rÂ  rô  r¿  )rÆ   rð  rP   rP   rQ   rô  Ã  s    
zIndexCol.write_metadata)NNNNNNNNNNNNN)N)N)"rÚ   r±  r²  r³  rº  r´  r»  rù  rÇ   rµ  rÄ  rÆ  rÃ  râ   rÔ  rÕ  ry  râ  rä  rå  rç  rè  rê  rô   rí  rî  rö  rñ  rò  rþ  r  rõ  ró  rô  rP   rP   rP   rQ   r¹     sf   

             ñ,-




	#r¹  c                   @  sD   e Zd ZdZeddœdd„ƒZddddd	œd
d„Zddœdd„ZdS )ÚGenericIndexColz:an index which is not represented in the data of the tabler�   rÈ   c                 C  s   dS ©NFrP   rÊ   rP   rP   rQ   ry  Ì  s    zGenericIndexCol.is_indexedr×  rX   ztuple[Int64Index, Int64Index]rØ  c                 C  s2   t |tjƒstt|ƒƒ‚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
        )rK   rL   rÛ  rÍ   rÙ   r9   Úarangerh   )rÆ   r[  r”   rV   r’   rŽ   rP   rP   rQ   râ  Ô  s    zGenericIndexCol.convertr…   c                 C  s   d S rS   rP   rÊ   rP   rP   rQ   rõ  æ  s    zGenericIndexCol.set_attrN)rÚ   r±  r²  r³  rµ  ry  râ  rõ  rP   rP   rP   rQ   r  É  s
   r  c                      s<  e Zd ZdZdZdZddgZd:dddd	œ‡ fd
d„Zeddœdd„ƒZ	eddœdd„ƒZ
ddœdd„Zdddœdd„Zdddœdd„Zdd„ Zedddœd d!„ƒZed"d#„ ƒZedd$d%œd&d'„ƒZeddd%œd(d)„ƒZed*d+„ ƒZed,d-„ ƒZed.d/„ ƒZed0d1„ ƒZddœd2d3„Zd4ddd5œd6d7„Zddœd8d9„Z‡  ZS );ÚDataCola3  
    a data holding column, by definition this is not indexable

    Parameters
    ----------
    data   : the actual data
    cname  : the column name in the table to hold the data (typically
                values)
    meta   : a string description of the metadata
    metadata : the actual metadata
    Fr½  ra  NrX   zDtypeArg | Noner…   )rZ   rÜ  r“   c                   s2   t ƒ j|||||||||	|
|d� || _|| _d S )N)rZ   r[  rg  rÀ  rÁ  r¿  r½  ra  ro   r¸   rÂ  )ÚsuperrÇ   rÜ  r|  )rÆ   rZ   r[  rg  rÀ  r¿  rÁ  r½  ra  ro   r¸   rÂ  rÜ  r|  ©Ú	__class__rP   rQ   rÇ   û  s    õzDataCol.__init__rÈ   c                 C  s   | j › d�S )NÚ_dtyperY   rÊ   rP   rP   rQ   Ú
dtype_attr	  s    zDataCol.dtype_attrc                 C  s   | j › d�S )NÚ_metarY   rÊ   rP   rP   rQ   Ú	meta_attr	  s    zDataCol.meta_attrc              	   C  sF   t tt| j| j| j| j| jfƒƒ}d dd„ t	dddddg|ƒD ƒ¡S )	NrÇ  c                 S  s   g | ]\}}|› d |› �‘qS rÈ  rP   rO  rP   rP   rQ   re   *	  s   ÿz$DataCol.__repr__.<locals>.<listcomp>rZ   r¿  rÜ  rg  Úshape)
rg   rÉ  rE   rZ   r¿  rÜ  rg  r  rÊ  r6  rË  rP   rP   rQ   râ   #	  s     ÿÿþÿzDataCol.__repr__r   r�   rÍ  c                   s   t ‡ ‡fdd„dD ƒƒS )rÏ  c                 3  s&   | ]}t ˆ|d ƒt ˆ |d ƒkV  qd S rS   rÐ  rz  rÑ  rP   rQ   rM  2	  s   ÿz!DataCol.__eq__.<locals>.<genexpr>)rZ   r¿  rÜ  rÁ  rÒ  rÓ  rP   rÑ  rQ   rÔ  0	  s    þzDataCol.__eq__r   )r|  r“   c                 C  s@   |d k	st ‚| jd kst ‚t|ƒ\}}|| _|| _t|ƒ| _d S rS   )rÍ   rÜ  Ú_get_data_and_dtype_namer|  Ú_dtype_to_kindrg  )rÆ   r|  Ú
dtype_namerP   rP   rQ   Úset_data7	  s    zDataCol.set_datac                 C  s   | j S )zreturn the data©r|  rÊ   rP   rP   rQ   rä  A	  s    zDataCol.take_datarF   )r[  r“   c                 C  sÂ   |j }|j}|j}|jdkr&d|jf}t|tƒrJ|j}| j||j j	d�}ntt
|ƒsZt|ƒrf|  |¡}nXt|ƒrz|  |¡}nDt|ƒr˜tƒ j||d d�}n&t|ƒr®|  ||¡}n| j||j	d�}|S )zW
        Get an appropriately typed and shaped pytables.Col object for values.
        r_   ©rg  r   ©rÄ  r  )rÜ  rÄ  r  rT  ÚsizerK   r:   ÚcodesÚget_atom_datarZ   r(   r)   Úget_atom_datetime64r-   Úget_atom_timedelta64r'   r|   Z
ComplexColr,   Úget_atom_string)r¢  r[  rÜ  rÄ  r  r  ÚatomrP   rP   rQ   Ú	_get_atomE	  s$    


zDataCol._get_atomc                 C  s   t ƒ j||d d�S )Nr   r  ©r|   rì  ©r¢  r  rÄ  rP   rP   rQ   r  e	  s    zDataCol.get_atom_stringz	type[Col]©rg  r“   c                 C  sR   |  d¡r$|dd… }d|› d�}n"|  d¡r4d}n| ¡ }|› d�}ttƒ |ƒS )z0return the PyTables column class for this columnÚuinté   NZUIntrF   ÚperiodÚInt64Col)ru  Ú
capitalizerm  r|   )r¢  rg  Zk4Zcol_nameZkcaprP   rP   rQ   Úget_atom_coltypei	  s    


zDataCol.get_atom_coltypec                 C  s   | j |d�|d d�S )Nr  r   ©r  ©r'  ©r¢  r  rg  rP   rP   rQ   r  x	  s    zDataCol.get_atom_datac                 C  s   t ƒ j|d d�S ©Nr   r(  ©r|   r%  ©r¢  r  rP   rP   rQ   r  |	  s    zDataCol.get_atom_datetime64c                 C  s   t ƒ j|d d�S r+  r,  r-  rP   rP   rQ   r  €	  s    zDataCol.get_atom_timedelta64c                 C  s   t | jdd ƒS )Nr  )rm  r|  rÊ   rP   rP   rQ   r  „	  s    zDataCol.shapec                 C  s   | j S ré  r  rÊ   rP   rP   rQ   rê  ˆ	  s    zDataCol.cvaluesc                 C  s`   |r\t | j| jdƒ}|dk	r2|t| jƒkr2tdƒ‚t | j| jdƒ}|dk	r\|| jkr\tdƒ‚dS )zAvalidate that we have the same order as the existing & same dtypeNz4appended items do not match existing items in table!z@appended items dtype do not match existing items dtype in table!)rm  rå  rÆ  rf   r[  r¥   r  rÜ  )rÆ   rŒ   Zexisting_fieldsZexisting_dtyperP   rP   rQ   rò  �	  s    ÿzDataCol.validate_attrr×  )r[  rV   r’   c                 C  s  t |tjƒstt|ƒƒ‚|jjdk	r.|| j }| jdk	s<t‚| jdkr\t	|ƒ\}}t
|ƒ}n|}| j}| j}t |tjƒs|t‚t| jƒ}| j}	| j}
| j}|dk	s¤t‚t|ƒ}|dkrÆt||dd�}�n(|dkràtj|dd�}�n|dk�r8ztjd	d
„ |D ƒtd�}W n. tk
�r4   tjdd
„ |D ƒtd�}Y nX n¶|dk�r¶|	}| ¡ }|dk�rhtg tjd�}n<t|ƒ}| ¡ �r¤||  }||dk  | t¡ ¡ j8  < tj|||
d�}n8z|j|dd�}W n$ t k
�rì   |jddd�}Y nX t|ƒdk�rt!||||d�}| j"|fS )aR  
        Convert the data from this selection to the appropriate pandas type.

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

        Returns
        -------
        index : listlike to become an Index
        data : ndarraylike to become a column
        NÚ
datetime64T©ÚcoerceÚtimedelta64úm8[ns]©rÜ  r   c                 S  s   g | ]}t  |¡‘qS rP   ©r   Úfromordinal©ra   rP  rP   rP   rQ   re   Ñ	  s     z#DataCol.convert.<locals>.<listcomp>c                 S  s   g | ]}t  |¡‘qS rP   ©r   Úfromtimestampr6  rP   rP   rQ   re   Õ	  s     r  éÿÿÿÿ)Ú
categoriesra  F©r}  ÚOrë  ©r”   rV   r’   )#rK   rL   rÛ  rÍ   rÙ   rÜ  rÝ  r¿  rÀ  r  r  rg  rR   r¸   rÂ  ra  r½  rß  ÚasarrayÚobjectr¥   Úravelr2   Zfloat64r8   ÚanyÚastyper\   ZcumsumÚ_valuesr:   Z
from_codesr¬   Ú_unconvert_string_arrayr[  )rÆ   r[  r”   rV   r’   Ú	convertedr  rg  r¸   rÂ  ra  r½  rÜ  r:  r  ÚmaskrP   rP   rQ   râ  š	  st    




 ÿ
 ÿ



   ÿ   ÿzDataCol.convertc                 C  sH   t | j| j| jƒ t | j| j| jƒ | jdk	s2t‚t | j| j| jƒ dS )zset the data for this columnN)	rû  rå  rÆ  r[  r  r¸   rÜ  rÍ   r  rÊ   rP   rP   rQ   rõ  ÿ	  s    zDataCol.set_attr)NNNNNNNNNNNN)rÚ   r±  r²  r³  rº  r»  rù  rÇ   rµ  r  r  râ   rÔ  r  rä  Úclassmethodr  r  r'  r  r  r  r  rê  rò  râ  rõ  Ú__classcell__rP   rP   r	  rQ   r  ê  sX               ò 





er  c                   @  sZ   e Zd ZdZdZddœdd„Zedd„ ƒZed	d
dœdd„ƒZedd„ ƒZ	edd„ ƒZ
dS )ÚDataIndexableColz+represent a data column that can be indexedTr…   rÈ   c                 C  s   t | jƒ ¡ stdƒ‚d S )Nú-cannot have non-object label DataIndexableCol)r2   r[  Z	is_objectr¥   rÊ   rP   rP   rQ   rî  
  s    zDataIndexableCol.validate_namesc                 C  s   t ƒ j|d�S )N)rÄ  r  r   rP   rP   rQ   r  
  s    z DataIndexableCol.get_atom_stringrX   rF   r!  c                 C  s   | j |d�ƒ S )Nr  r)  r*  rP   rP   rQ   r  
  s    zDataIndexableCol.get_atom_datac                 C  s
   t ƒ  ¡ S rS   r,  r-  rP   rP   rQ   r  
  s    z$DataIndexableCol.get_atom_datetime64c                 C  s
   t ƒ  ¡ S rS   r,  r-  rP   rP   rQ   r  
  s    z%DataIndexableCol.get_atom_timedelta64N)rÚ   r±  r²  r³  r»  rî  rG  r  r  r  r  rP   rP   rP   rQ   rI  
  s   

rI  c                   @  s   e Zd ZdZdS )ÚGenericDataIndexableColz(represent a generic pytables data columnN)rÚ   r±  r²  r³  rP   rP   rP   rQ   rK  "
  s   rK  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ed< ded< ded< dZded< dPddddddœdd„Zeddœdd„ƒZ	eddœdd„ƒZ
edd „ ƒZddœd!d"„Zddœd#d$„Zd dœd%d&„Zed'd(„ ƒZed)d*„ ƒZed+d,„ ƒZed-d.„ ƒZeddœd/d0„ƒZeddœd1d2„ƒZed3d4„ ƒZddœd5d6„Zddœd7d8„Zed9d:„ ƒZeddœd;d<„ƒZed=d>„ ƒZd?dœd@dA„ZdQddœdCdD„ZddœdEdF„ZdRdGdGdHœdIdJ„ZdKdL„ ZdSdGdGddMœdNdO„Z dBS )TÚ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.
    rX   Úpandas_kindrn   Úformat_typeútype[DataFrame | Series]Úobj_typer\   rT  rV   r›   r»   rH   r¶   r’   Fr�   r7  rJ   rv   r…   )r»   r¶   rV   r’   r“   c                 C  sZ   t |tƒstt|ƒƒ‚td k	s"t‚t |tjƒs:tt|ƒƒ‚|| _|| _t|ƒ| _	|| _
d S rS   )rK   r›   rÍ   rÙ   rw   rH   r»   r¶   rW   rV   r’   )rÆ   r»   r¶   rV   r’   rP   rP   rQ   rÇ   ?
  s    
zFixed.__init__rÈ   c                 C  s*   | j d dko(| j d dko(| j d dk S )Nr   r_   é
   é   )ÚversionrÊ   rP   rP   rQ   Úis_old_versionN
  s    zFixed.is_old_versionztuple[int, int, int]c                 C  sb   t t| jjddƒƒ}z0tdd„ | d¡D ƒƒ}t|ƒdkrB|d }W n tk
r\   d}Y nX |S )	zcompute and set our versionÚpandas_versionNc                 s  s   | ]}t |ƒV  qd S rS   ©r\   r'  rP   rP   rQ   rM  W
  s     z Fixed.version.<locals>.<genexpr>Ú.rR  r)  )r   r   r   )rR   rm  r¶   rn  rg   r¬  rh   ry   )rÆ   rS  rP   rP   rQ   rS  R
  s    
zFixed.versionc                 C  s   t t| jjdd ƒƒS )Nrj  )rR   rm  r¶   rn  rÊ   rP   rP   rQ   rj  ^
  s    zFixed.pandas_typec                 C  s^   |   ¡  | j}|dk	rXt|ttfƒrDd dd„ |D ƒ¡}d|› d�}| jd›d|› d	�S | jS )
ú(return a pretty representation of myselfNrÇ  c                 S  s   g | ]}t |ƒ‘qS rP   ©rE   r'  rP   rP   rQ   re   h
  s     z"Fixed.__repr__.<locals>.<listcomp>ú[r&  ú12.12z	 (shape->ú))r  r  rK   rf   rg   rÊ  rj  )rÆ   rO   ZjshaperP   rP   rQ   râ   b
  s    zFixed.__repr__c                 C  s   t | jƒ| j_t tƒ| j_dS )zset my pandas type & versionN)rX   rM  rå  rj  Ú_versionrU  rÊ   rP   rP   rQ   r§  m
  s    zFixed.set_object_infoc                 C  s   t   | ¡}|S rS   r;  )rÆ   Znew_selfrP   rP   rQ   r}  r
  s    
z
Fixed.copyc                 C  s   | j S rS   )r  rÊ   rP   rP   rQ   r  v
  s    zFixed.shapec                 C  s   | j jS rS   ©r¶   r°   rÊ   rP   rP   rQ   r8  z
  s    zFixed.pathnamec                 C  s   | j jS rS   )r»   r¼   rÊ   rP   rP   rQ   r¼   ~
  s    zFixed._handlec                 C  s   | j jS rS   )r»   rÄ   rÊ   rP   rP   rQ   rÄ   ‚
  s    zFixed._filtersc                 C  s   | j jS rS   )r»   r¾   rÊ   rP   rP   rQ   r¾   †
  s    zFixed._complevelc                 C  s   | j jS rS   )r»   r¿   rÊ   rP   rP   rQ   r¿   Š
  s    zFixed._fletcher32c                 C  s   | j jS rS   )r¶   rn  rÊ   rP   rP   rQ   rå  Ž
  s    zFixed.attrsc                 C  s   dS ©zset our object attributesNrP   rÊ   rP   rP   rQ   Ú	set_attrs’
  s    zFixed.set_attrsc                 C  s   dS )zget our object attributesNrP   rÊ   rP   rP   rQ   Ú	get_attrs–
  s    zFixed.get_attrsc                 C  s   | j S )zreturn my storabler©  rÊ   rP   rP   rQ   Ústorableš
  s    zFixed.storablec                 C  s   dS r  rP   rÊ   rP   rP   rQ   r¦  Ÿ
  s    zFixed.is_existsc                 C  s   t | jdd ƒS )Nr  )rm  rb  rÊ   rP   rP   rQ   r  £
  s    zFixed.nrowszLiteral[True] | Nonec                 C  s   |dkrdS dS )z%validate against an existing storableNTrP   rÓ  rP   rP   rQ   Úvalidate§
  s    zFixed.validateNc                 C  s   dS )ú+are we trying to operate on an old version?NrP   )rÆ   ri   rP   rP   rQ   Úvalidate_version­
  s    zFixed.validate_versionc                 C  s   | j }|dk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)rb  ra  )rÆ   rO   rP   rP   rQ   r  ±
  s
    zFixed.infer_axesr   ©rž   rŸ   c                 C  s   t dƒ‚d S )Nz>cannot read on an abstract storer: subclasses should implement©r¨   ©rÆ   ri   r    rž   rŸ   rP   rP   rQ   r  ¼
  s    ÿz
Fixed.readc                 K  s   t dƒ‚d S )Nz?cannot write on an abstract storer: subclasses should implementrg  ©rÆ   r´   rP   rP   rQ   r¨  Ç
  s    ÿzFixed.write©rž   rŸ   r“   c                 C  s0   t  |||¡r$| jj| jdd� dS tdƒ‚dS )zs
        support fully deleting the node in its entirety (only) - where
        specification must be None
        Tr?  Nz#cannot delete on an abstract storer)rB  rC  r¼   rª  r¶   r¬   )rÆ   ri   rž   rŸ   rP   rP   rQ   rD  Ì
  s    zFixed.delete)rJ   rv   )N)NNNN)NNN)!rÚ   r±  r²  r³  r´  rN  r7  rÇ   rµ  rT  rS  rj  râ   r§  r}  r  r8  r¼   rÄ   r¾   r¿   rå  r`  ra  rb  r¦  r  rc  re  r  r  r¨  rD  rP   rP   rP   rQ   rL  (
  sr   
  û







    û     ÿrL  c                   @  sF  e Zd ZU dZedediZdd„ e ¡ D ƒZg Z	de
d< dd	œd
d„Zdd„ Zdd„ Zdd	œdd„Zedd	œdd„ƒZdd	œdd„Zdd	œdd„Zdd	œdd„Zd:ddddœdd „Zd;dddd!d"œd#d$„Zdd!dd%œd&d'„Zdd(dd%œd)d*„Zd<dddd(d"œd+d,„Zd=d-ddd!d.œd/d0„Zdd1dd2œd3d4„Zd>dd5d6dd7œd8d9„ZdS )?ÚGenericFixedza generified fixed versionÚdatetimer$  c                 C  s   i | ]\}}||“qS rP   rP   )ra   r%  rP  rP   rP   rQ   rQ  Þ
  s      zGenericFixed.<dictcomp>ré   Ú
attributesrX   rÈ   c                 C  s   | j  |d¡S )NÚ )Ú_index_type_maprÑ   )rÆ   r¢  rP   rP   rQ   Ú_class_to_aliasâ
  s    zGenericFixed._class_to_aliasc                 C  s   t |tƒr|S | j |t¡S rS   )rK   rÙ   Ú_reverse_index_maprÑ   r2   )rÆ   ÚaliasrP   rP   rQ   Ú_alias_to_classå
  s    
zGenericFixed._alias_to_classc                 C  s¸   |   tt|ddƒƒ¡}|tkr.d	dd„}|}n|tkrFd
dd„}|}n|}i }d|krn|d |d< |tkrnt}d|kr°t|d tƒr˜|d  	d¡|d< n|d |d< |tks°t
‚||fS )NÚindex_classrn  c                 S  s:   t j| j|d�}tj|d d�}|d k	r6| d¡ |¡}|S )N©r¼  rY   ÚUTC)r;   Ú_simple_newr[  r1   Útz_localizeÚ
tz_convert)r[  r¼  r½  ZdtaÚresultrP   rP   rQ   rp   ô
  s
    z*GenericFixed._get_index_factory.<locals>.fc                 S  s   t j| |d�}tj|d d�S )Nru  rY   )r<   rw  r4   )r[  r¼  r½  ZparrrP   rP   rQ   rp   ÿ
  s    r¼  r½  zutf-8)NN)NN)rs  rR   rm  r1   r4   r2   r6   rK   ÚbytesrN   rÍ   )rÆ   rå  rt  rp   rá  r´   rP   rP   rQ   Ú_get_index_factoryë
  s*    ÿ

zGenericFixed._get_index_factoryr…   c                 C  s$   |dk	rt dƒ‚|dk	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    ri   rP   rP   rQ   Úvalidate_read  s    ÿÿzGenericFixed.validate_readr�   c                 C  s   dS )NTrP   rÊ   rP   rP   rQ   r¦  (  s    zGenericFixed.is_existsc                 C  s   | j | j_ | j| j_dS r_  )rV   rå  r’   rÊ   rP   rP   rQ   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 attributesrV   Nr’   rv   )rW   rm  rå  rV   rR   r’   rm  rû  )rÆ   rí   rP   rP   rQ   ra  1  s    
zGenericFixed.get_attrsc                 K  s   |   ¡  d S rS   )r`  ©rÆ   r¤  r´   rP   rP   rQ   r¨  9  s    zGenericFixed.writeNr   r  c                 C  sÐ   ddl }t| j|ƒ}|j}t|ddƒ}t||jƒrD|d ||… }nztt|ddƒƒ}	t|ddƒ}
|
dk	rxtj|
|	d�}n|||… }|	dkr¨t|d	dƒ}t	||d
d�}n|	dkr¾tj
|dd�}|rÈ|jS |S dS )z2read an array for the specified node (off of groupr   NÚ
transposedFÚ
value_typer  r3  r.  r½  Tr/  r1  r2  )rx   rm  r¶   rn  rK   ZVLArrayrR   rL   r£  rß  r>  ÚT)rÆ   r‡   rž   rŸ   rx   rÝ   rå  r€  ÚretrÜ  r  r½  rP   rP   rQ   Ú
read_array<  s&    zGenericFixed.read_arrayr2   )r‡   rž   rŸ   r“   c                 C  sh   t t| j|› d�ƒƒ}|dkr.| j|||d�S |dkrVt| j|ƒ}| j|||d�}|S td|› �ƒ‚d S )NÚ_varietyÚmultirf  Úregularzunrecognized index variety: )rR   rm  rå  Úread_multi_indexr¶   Úread_index_noder¬   )rÆ   r‡   rž   rŸ   ZvarietyrÝ   rŽ   rP   rP   rQ   Ú
read_index^  s    zGenericFixed.read_index)r‡   rŽ   r“   c                 C  sà   t |tƒr,t| j|› d�dƒ |  ||¡ n°t| j|› d�dƒ td|| j| jƒ}|  ||j	¡ t
| j|ƒ}|j|j_|j|j_t |ttfƒr |  t|ƒ¡|j_t |tttfƒrº|j|j_t |tƒrÜ|jd k	rÜt|jƒ|j_d S )Nr…  r†  r‡  rŽ   )rK   r3   rû  rå  Úwrite_multi_indexÚ_convert_indexrV   r’   Úwrite_arrayr[  rm  r¶   rg  rn  rZ   r1   r4   rp  rÙ   rt  r6   r¼  r½  Ú_get_tz)rÆ   r‡   rŽ   rE  rÝ   rP   rP   rQ   Úwrite_indexl  s    



zGenericFixed.write_indexr3   c                 C  sÎ   t | j|› d�|jƒ tt|j|j|jƒƒD ]œ\}\}}}t|ƒrJt	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™  Ú	enumerater6  Úlevelsr  Únamesr*   r¨   rŒ  rV   r’   r�  r[  rm  r¶   rg  rn  rZ   )rÆ   r‡   rŽ   ÚiÚlevÚlevel_codesrZ   Ú	level_keyZ
conv_levelrÝ   Ú	label_keyrP   rP   rQ   r‹  ƒ  s"    ÿÿ
zGenericFixed.write_multi_indexc                 C  s¤   t | j|› d�ƒ}g }g }g }t|ƒD ]l}|› d|› �}	t | j|	ƒ}
| j|
||d�}| |¡ | |j¡ |› d|› �}| j|||d�}| |¡ q&t|||dd�S )Nr�  r‘  rf  r“  T)r•  r  r–  r/  )	rm  rå  rS  r¶   r‰  rŒ   rZ   r„  r3   )rÆ   r‡   rž   rŸ   r™  r•  r  r–  r—  rš  rÝ   r˜  r›  r™  rP   rP   rQ   rˆ  œ  s&    
   ÿzGenericFixed.read_multi_indexrH   )rÝ   rž   rŸ   r“   c                 C  sÔ   |||… }d|j kr>t |j j¡dkr>tj|j j|j jd�}t|j jƒ}d }d|j krlt|j j	ƒ}t|ƒ}|j }|  
|¡\}}	|dkr®|t||| j| jd�fdti|	—Ž}
n|t||| j| jd�f|	Ž}
||
_	|
S )Nr  r   r3  rZ   r   r�  rÜ  )rn  rL   Úprodr  r£  r�  rR   rg  r[   rZ   r|  Ú_unconvert_indexrV   r’   r?  )rÆ   rÝ   rž   rŸ   r|  rg  rZ   rå  rá  r´   rŽ   rP   rP   rQ   r‰  ³  sF    
   ÿÿüû   ÿÿüzGenericFixed.read_index_noder   )r‡   rˆ   r“   c                 C  sJ   t  d|j ¡}| j | j||¡ t| j|ƒ}t|jƒ|j	_
|j|j	_dS )zwrite a 0-len array©r_   N)rL   r£  rT  r¼   Úcreate_arrayr¶   rm  rX   rÜ  rn  r�  r  )rÆ   r‡   rˆ   ZarrrÝ   rP   rP   rQ   Úwrite_array_emptyÙ  s
    zGenericFixed.write_array_emptyr   zIndex | None)r‡   r¤  r÷   r“   c              	   C  s:  t |dd�}|| jkr&| j | j|¡ |jdk}d}t|jƒrFtdƒ‚|s^t|dƒr^|j	}d}d }| j
d k	r�ttƒ� tƒ j |j¡}W 5 Q R X |d k	rÖ|sÆ| jj| j|||j| j
d�}||d d …< n|  ||¡ �nP|jjtjk�rPtj|dd�}	|rún2|	d	k�rn&t|	||f }
tj|
ttt ¡ ƒd
� | j | j|tƒ   ¡ ¡}| !|¡ nÖt"|jƒ�r†| j #| j|| $d¡¡ dt%| j|ƒj&_'n t(|jƒ�rÊ| j #| j||j)¡ t%| j|ƒ}t*|j+ƒ|j&_+d|j&_'n\t,|jƒ�r | j #| j|| $d¡¡ dt%| j|ƒj&_'n&|�r|  ||¡ 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.  r1  ).r?   r¶   r¼   rª  r  r&   rÜ  r¨   rÖ  r‚  rÄ   r   r¥   r|   ZAtomZ
from_dtypeZcreate_carrayr  r   rÙ   rL   Zobject_r   Úinfer_dtyperm   rú   rû   r!   r$   rý   rþ   Zcreate_vlarrayÚ
ObjectAtomrŒ   r(   rŸ  Úviewrm  rn  r�  r)   Úasi8rŽ  r½  r-   r€  )rÆ   r‡   r¤  r÷   rˆ   Zempty_arrayr€  r  ÚcaÚinferred_typerý  ZvlarrrÝ   rP   rP   rQ   r�  â  sz    


ÿ


    ÿ

ý  ÿ
zGenericFixed.write_array)NN)NN)NN)NN)N)rÚ   r±  r²  r³  r1   r4   ro  r÷   rq  rm  r´  rp  rs  r|  r}  rµ  r¦  r`  ra  r¨  r„  rŠ  r�  r‹  rˆ  r‰  r   r�  rP   rP   rP   rQ   rk  Ú
  s8   
.#   ÿ   ÿ   ÿ&
 ÿrk  c                      sV   e Zd ZU dZdgZded< edd„ ƒZddddd	œd
d„Zddœ‡ fdd„Z	‡  Z
S )r—  r‹  rZ   r   c              	   C  s0   zt | jjƒfW S  ttfk
r*   Y d S X d S rS   )rh   r¶   r[  r¬   ry   rÊ   rP   rP   rQ   r  G  s    zSeriesFixed.shapeNr   r5   rj  c                 C  s<   |   ||¡ | jd||d�}| jd||d�}t||| jd�S )NrŽ   rf  r[  )rŽ   rZ   )r}  rŠ  r„  r5   rZ   )rÆ   ri   r    rž   rŸ   rŽ   r[  rP   rP   rQ   r  N  s    zSeriesFixed.readr…   rÈ   c                   s8   t ƒ j|f|Ž |  d|j¡ |  d|¡ |j| j_d S )NrŽ   r[  )r  r¨  r�  rŽ   r�  rZ   rå  r  r	  rP   rQ   r¨  [  s    zSeriesFixed.write)NNNN)rÚ   r±  r²  rM  rm  r´  rµ  r  r  r¨  rH  rP   rP   r	  rQ   r—  A  s   

    ûr—  c                      sZ   e Zd ZU ddgZded< eddœdd„ƒZdd	d	d
dœdd„Zddœ‡ fdd„Z‡  Z	S )ÚBlockManagerFixedrT  Únblocksr\   zShape | NonerÈ   c                 C  s°   z”| j }d}t| jƒD ]8}t| jd|› d�ƒ}t|dd ƒ}|d k	r||d 7 }q| jj}t|dd ƒ}|d k	r‚t|d|d … ƒ}ng }| |¡ |W S  tk
rª   Y d S X d S )Nr   ÚblockÚ_itemsr  r_   )	rT  rS  r©  rm  r¶   Zblock0_valuesrf   rŒ   ry   )rÆ   rT  r÷   r—  rÝ   r  rP   rP   rQ   r  g  s"    
zBlockManagerFixed.shapeNr   r0   rj  c                 C  s  |   ||¡ |  ¡  d¡}g }t| jƒD ]<}||kr<||fnd\}}	| jd|› �||	d�}
| |
¡ q(|d }g }t| jƒD ]Z}|  d|› d�¡}| jd|› d�||	d�}|| 	|¡ }t
|j||d d	�}| |¡ q|t|ƒdk�rt|dd
�}|j|dd�}|S t
|d |d d	�S )Nr   )NNr.  rf  rª  r«  rC  r_   ©r    rŽ   rN  F)r    r}  )r}  rP  Z_get_block_manager_axisrS  rT  rŠ  rŒ   r©  r„  rY  r0   r‚  rh   r7   r`  )rÆ   ri   r    rž   rŸ   Zselect_axisrF  r—  r  r  Úaxr÷   ÚdfsÚ	blk_itemsr[  ÚdfÚoutrP   rP   rQ   r  ‚  s(    zBlockManagerFixed.readr…   c                   sä   t ƒ j|f|Ž t|jtƒr&| d¡}|j}| ¡ s<| ¡ }|j| j	_t
|jƒD ]0\}}|dkrn|jsntdƒ‚|  d|› �|¡ qPt|jƒ| j	_t
|jƒD ]D\}}|j |j¡}| jd|› d�|j|d� |  d|› d�|¡ qšd S )Nrª  r   z/Columns index has to be unique for fixed formatr.  rC  )r÷   r«  )r  r¨  rK   Ú_mgrrA   Ú_as_managerZis_consolidatedZconsolidaterT  rå  r”  rF  Z	is_uniquer¥   r�  rh   Úblocksr©  r÷   rZ  Úmgr_locsr�  r[  )rÆ   r¤  r´   r|  r—  r­  Úblkr¯  r	  rP   rQ   r¨  ¨  s     

zBlockManagerFixed.write)NNNN)
rÚ   r±  r²  rm  r´  rµ  r  r  r¨  rH  rP   rP   r	  rQ   r¨  b  s   
    û&r¨  c                   @  s   e Zd ZdZeZdS )r˜  rŒ  N)rÚ   r±  r²  rM  r0   rP  rP   rP   rP   rQ   r˜  Â  s   r˜  c                      sÈ  e Zd ZU dZdZdZded< ded< dZded	< d
Zded< ded< ded< ded< ded< ded< d„dddddœ‡ fdd„Z	e
ddœdd „ƒZddœd!d"„Zdd#œd$d%„Zddœd&d'„Ze
d(dœd)d*„ƒZd+d,d-œd.d/„Ze
d0dœd1d2„ƒZe
d(dœd3d4„ƒZe
d5d6„ ƒZe
d7d8„ ƒZe
d9d:„ ƒZe
d;d<„ ƒZe
d=d>„ ƒZe
d0dœd?d@„ƒZe
d(dœdAdB„ƒZe
dCdœdDdE„ƒZdFdœdGdH„ZdIdJ„ ZdKdœdLdM„ZdddNœdOdP„ZddQddRœdSdT„ZddUœdVdW„Z ddœdXdY„Z!ddœdZd[„Z"d…ddœd\d]„Z#ddœd^d_„Z$e%d`da„ ƒZ&d†dbddcœddde„Z'd‡dfdfdgdhœdidj„Z(e)d(dkœdldm„ƒZ*dndo„ Z+dˆdpd(dqœdrds„Z,e-dpd(dtœdudv„ƒZ.d‰dwdpdxœdydz„Z/dfd(dfdFd{œd|d}„Z0dŠdfdfd~œdd€„Z1d‹ddfdfd�œd‚dƒ„Z2‡  Z3S )Œrð   aa  
    represent a table:
        facilitate read/write of various types of tables

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

    index_axes    : a list of tuples of the (original indexing axis and
        index column)
    non_index_axes: a list of tuples of the (original index axis and
        columns on a non-indexing axis)
    values_axes   : a list of the columns which comprise the data of this
        table
    data_columns  : a list of the columns that we are allowing indexing
        (these become single columns in values_axes)
    nan_rep       : the string to use for nan representations for string
        objects
    levels        : the names of levels
    metadata      : the names of the metadata columns
    Z
wide_tablero   rX   rN  rˆ  r_   zint | list[Hashable]r•  Tzlist[IndexCol]Ú
index_axeszlist[tuple[int, Any]]r*  zlist[DataCol]Úvalues_axesrf   r‘   rÂ  rH  r‚  Nrv   r›   rH   r…   )r»   r¶   r’   r“   c                   sP   t ƒ j||||d� |pg | _|p$g | _|p.g | _|p8g | _|	pBi | _|
| _d S )Nr�  )r  rÇ   r·  r*  r¸  r‘   r‚  r”   )rÆ   r»   r¶   rV   r’   r·  r*  r¸  r‘   r‚  r”   r	  rP   rQ   rÇ   ì  s    




zTable.__init__rÈ   c                 C  s   | j  d¡d S )NÚ_r   )rˆ  r¬  rÊ   rP   rP   rQ   Útable_type_short  s    zTable.table_type_shortc                 C  s¦   |   ¡  t| jƒrd | j¡nd}d|› d�}d}| jrZd dd„ | jD ƒ¡}d|› d�}d d	d„ | jD ƒ¡}| jd
›|› d| j› d| j	› d| j
› d|› d|› d�S )rX  rÇ  rn  z,dc->[r&  rW  c                 S  s   g | ]}t |ƒ‘qS rP   ©rX   r'  rP   rP   rQ   re     s     z"Table.__repr__.<locals>.<listcomp>rZ  c                 S  s   g | ]
}|j ‘qS rP   rY   rz  rP   rP   rQ   re     s     r[  z (typ->z,nrows->z,ncols->z,indexers->[r\  )r  rh   r‘   rÊ  rT  rS  r·  rj  rº  r  Úncols)rÆ   Zjdcrb  ÚverZjverZjindex_axesrP   rP   rQ   râ     s    4ÿzTable.__repr__)r÷  c                 C  s"   | j D ]}||jkr|  S qdS )zreturn the axis for cN)rF  rZ   )rÆ   r÷  r}   rP   rP   rQ   rÓ     s    


zTable.__getitem__c              
   C  sº   |dkrdS |j | j kr2td|j › d| j › d�ƒ‚dD ]~}t| |dƒ}t||dƒ}||kr6t|ƒD ]4\}}|| }||krbtd|› d|› d|› d�ƒ‚qbtd|› d|› d|› d�ƒ‚q6dS )	z"validate against an existing tableNz'incompatible table_type with existing [rø  r&  )r·  r*  r¸  zinvalid combination of [z] on appending data [z] vs current table [)rˆ  r¬   rm  r”  r¥   rA  )rÆ   rÎ  r÷  ÚsvÚovr—  ÚsaxZoaxrP   rP   rQ   rc    s&    ÿÿÿzTable.validater�   c                 C  s   t | jtƒS )z@the levels attribute is 1 or a list in the case of a multi-index)rK   r•  rf   rÊ   rP   rP   rQ   Úis_multi_index@  s    zTable.is_multi_indexr~   z tuple[DataFrame, list[Hashable]])r¤  r“   c              
   C  s^   t  |jj¡}z| ¡ }W n, tk
rF } ztdƒ|‚W 5 d}~X Y nX t|tƒsVt‚||fS )ze
        validate that we can store the multi-index; reset and return the
        new object
        zBduplicate names/columns in the multi-index when storing as a tableN)	rB  Zfill_missing_namesrŽ   r–  Zreset_indexr¥   rK   r0   rÍ   )rÆ   r¤  r•  Z	reset_objrE  rP   rP   rQ   Úvalidate_multiindexE  s    ÿþzTable.validate_multiindexr\   c                 C  s   t  dd„ | jD ƒ¡S )z-based on our axes, compute the expected nrowsc                 S  s   g | ]}|j jd  ‘qS r)  )rê  r  ©ra   r—  rP   rP   rQ   re   Y  s     z(Table.nrows_expected.<locals>.<listcomp>)rL   rœ  r·  rÊ   rP   rP   rQ   Únrows_expectedV  s    zTable.nrows_expectedc                 C  s
   d| j kS )zhas this table been createdro   r©  rÊ   rP   rP   rQ   r¦  [  s    zTable.is_existsc                 C  s   t | jdd ƒS ©Nro   ©rm  r¶   rÊ   rP   rP   rQ   rb  `  s    zTable.storablec                 C  s   | j S )z,return the table group (this is my storable))rb  rÊ   rP   rP   rQ   ro   d  s    zTable.tablec                 C  s   | j jS rS   )ro   rÜ  rÊ   rP   rP   rQ   rÜ  i  s    zTable.dtypec                 C  s   | j jS rS   ræ  rÊ   rP   rP   rQ   rç  m  s    zTable.descriptionc                 C  s   t  | j| j¡S rS   )r4  r5  r·  r¸  rÊ   rP   rP   rQ   rF  q  s    z
Table.axesc                 C  s   t dd„ | jD ƒƒS )z.the number of total columns in the values axesc                 s  s   | ]}t |jƒV  qd S rS   )rh   r[  rz  rP   rP   rQ   rM  x  s     zTable.ncols.<locals>.<genexpr>)Úsumr¸  rÊ   rP   rP   rQ   r¼  u  s    zTable.ncolsc                 C  s   dS r  rP   rÊ   rP   rP   rQ   Úis_transposedz  s    zTable.is_transposedztuple[int, ...]c                 C  s(   t t dd„ | jD ƒdd„ | jD ƒ¡ƒS )z@return a tuple of my permutated axes, non_indexable at the frontc                 S  s   g | ]}t |d  ƒ‘qS r)  rV  rz  rP   rP   rQ   re   ƒ  s     z*Table.data_orientation.<locals>.<listcomp>c                 S  s   g | ]}t |jƒ‘qS rP   )r\   r.  rz  rP   rP   rQ   re   „  s     )rg   r4  r5  r*  r·  rÊ   rP   rP   rQ   Údata_orientation~  s    þÿzTable.data_orientationzdict[str, Any]c                   sR   dddœ‰ dd„ ˆj D ƒ}‡ fdd„ˆjD ƒ}‡fdd„ˆjD ƒ}t|| | ƒS )z<return a dict of the kinds allowable columns for this objectrŽ   r    ©r   r_   c                 S  s   g | ]}|j |f‘qS rP   ©r¿  rz  rP   rP   rQ   re   Ž  s     z$Table.queryables.<locals>.<listcomp>c                   s   g | ]\}}ˆ | d f‘qS rS   rP   )ra   r.  r[  )Ú
axis_namesrP   rQ   re   �  s     c                   s&   g | ]}|j tˆ jƒkr|j|f‘qS rP   )rZ   rR  r‘   r¿  r6  rÊ   rP   rQ   re   �  s     )r·  r*  r¸  rH  )rÆ   Zd1Zd2Zd3rP   )rÌ  rÆ   rQ   Ú
queryablesˆ  s    

ÿzTable.queryablesc                 C  s   dd„ | j D ƒS )zreturn a list of my index colsc                 S  s   g | ]}|j |jf‘qS rP   )r.  r¿  rÃ  rP   rP   rQ   re   ›  s     z$Table.index_cols.<locals>.<listcomp>©r·  rÊ   rP   rP   rQ   Ú
index_cols˜  s    zTable.index_colsré   c                 C  s   dd„ | j D ƒS )zreturn a list of my values colsc                 S  s   g | ]
}|j ‘qS rP   rË  rÃ  rP   rP   rQ   re   Ÿ  s     z%Table.values_cols.<locals>.<listcomp>)r¸  rÊ   rP   rP   rQ   Úvalues_cols�  s    zTable.values_colsrÔ   c                 C  s   | j j}|› d|› d�S )z)return the metadata pathname for this keyz/meta/z/metar^  r
  rP   rP   rQ   Ú_get_metadata_path¡  s    zTable._get_metadata_pathr×  )r‡   r[  r“   c                 C  s,   | j j|  |¡t|ƒ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
        ro   )r�   rV   r’   r”   N)r»   rš   rÑ  r5   rV   r’   r”   )rÆ   r‡   r[  rP   rP   rQ   rô  ¦  s    	úzTable.write_metadatarÐ   c                 C  s0   t t | jddƒ|dƒdk	r,| j |  |¡¡S dS )z'return the meta data array for this keyr¸   N)rm  r¶   r»   r±   rÑ  rÒ   rP   rP   rQ   r  ¸  s    zTable.read_metadatac                 C  sp   t | jƒ| j_|  ¡ | j_|  ¡ | j_| j| j_| j| j_| j| j_| j| j_| j	| j_	| j
| j_
| j| j_dS )zset our table type & indexablesN)rX   rˆ  rå  rÏ  rÐ  r*  r‘   r”   rV   r’   r•  r‚  rÊ   rP   rP   rQ   r`  ¾  s    





zTable.set_attrsc                 C  s°   t | jddƒpg | _t | jddƒp$g | _t | jddƒp8i | _t | jddƒ| _tt | jddƒƒ| _tt | jddƒƒ| _	t | jd	dƒp„g | _
d
d„ | jD ƒ| _dd„ | jD ƒ| _dS )r~  r*  Nr‘   r‚  r”   rV   r’   rv   r•  c                 S  s   g | ]}|j r|‘qS rP   ©rº  rz  rP   rP   rQ   re   Ô  s      z#Table.get_attrs.<locals>.<listcomp>c                 S  s   g | ]}|j s|‘qS rP   rÒ  rz  rP   rP   rQ   re   Õ  s      )rm  rå  r*  r‘   r‚  r”   rW   rV   rR   r’   r•  Ú
indexablesr·  r¸  rÊ   rP   rP   rQ   ra  Ë  s    zTable.get_attrsc                 C  sD   |dk	r@| j r@td dd„ | jD ƒ¡ }tj|ttt 	¡ ƒd� dS )rd  NrW  c                 S  s   g | ]}t |ƒ‘qS rP   r»  r'  rP   rP   rQ   re   Û  s     z*Table.validate_version.<locals>.<listcomp>rø   )
rT  rk   rÊ  rS  rú   rû   r    r$   rý   rþ   )rÆ   ri   rý  rP   rP   rQ   re  ×  s    
ýzTable.validate_versionc                 C  sR   |dkrdS t |tƒsdS |  ¡ }|D ]&}|dkr4q&||kr&td|› d�ƒ‚q&dS )zˆ
        validate the min_itemsize doesn't contain items that are not in the
        axes this needs data_columns to be defined
        Nr[  zmin_itemsize has the key [z%] which is not an axis or data_column)rK   rH  rÍ  r¥   )rÆ   r�   Úqr%  rP   rP   rQ   Úvalidate_min_itemsizeâ  s    

ÿzTable.validate_min_itemsizec                   sÔ   g }ˆj ‰ˆjj‰tˆjjƒD ]j\}\}}tˆ|ƒ}ˆ |¡}|dk	rJdnd}|› d�}tˆ|dƒ}	t||||	|ˆj||d�}
| |
¡ qt	ˆj
ƒ‰t|ƒ‰ ‡ ‡‡‡‡fdd„‰| ‡fdd„tˆjjƒD ƒ¡ |S )	z/create/cache the indexables if they don't existNr  rÅ  )rZ   r.  rÁ  rg  rÀ  ro   r¸   rÂ  c                   s¢   t |tƒst‚t}|ˆkrt}tˆ|ƒ}t|ˆjƒ}tˆ|› d�d ƒ}tˆ|› d�d ƒ}t|ƒ}ˆ 	|¡}tˆ|› d�d ƒ}	|||||ˆ |  |ˆj
|	||d�
}
|
S )NrÅ  r  r  )
rZ   r¿  r[  rg  rÁ  rÀ  ro   r¸   rÂ  rÜ  )rK   rX   rÍ   r  rI  rm  Ú_maybe_adjust_namerS  r  r  ro   )r—  r÷  Úklassr  Úadj_namer[  rÜ  rg  Úmdr¸   r¤  )Úbase_posrb  ÚdescrÆ   Útable_attrsrP   rQ   rp     s0    

özTable.indexables.<locals>.fc                   s   g | ]\}}ˆ ||ƒ‘qS rP   rP   )ra   r—  r÷  )rp   rP   rQ   re   @  s     z$Table.indexables.<locals>.<listcomp>)rç  ro   rå  r”  rÏ  rm  r  r¹  rŒ   rR  r‘   rh   rV  rÐ  )rÆ   Ú_indexablesr—  r.  rZ   r  rÙ  r¸   rÆ  rg  Ú	index_colrP   )rÚ  rb  rÛ  rp   rÆ   rÜ  rQ   rÓ  ø  s2    


ø

% zTable.indexablesr€   r!  c              	   C  sR  |   ¡ sdS |dkrdS |dks(|dkr8dd„ | jD ƒ}t|ttfƒsL|g}i }|dk	r`||d< |dk	rp||d< | j}|D ]Ò}t|j|dƒ}|dk	�r|jrò|j	}|j
}	|j}
|dk	rÈ|
|krÈ| ¡  n|
|d< |dk	rê|	|krê| ¡  n|	|d< |j�sL|j d¡�rtd	ƒ‚|jf |Ž qz|| jd
 d krztd|› d|› d|› d�ƒ‚qzdS )aZ  
        Create a pytables index on the specified columns.

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

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

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

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

        Notes
        -----
        Cannot index Time64Col or ComplexCol.
        Pytables must be >= 3.0.
        NFTc                 S  s   g | ]}|j r|j‘qS rP   )r»  r¿  rz  rP   rP   rQ   re   i  s      z&Table.create_index.<locals>.<listcomp>rf  rg  ÚcomplexzíColumns 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   r_   zcolumn z/ is not a data_column.
In order to read column z: you must reload the dataframe 
into HDFStore and include z  with the data_columns argument.)r  rF  rK   rg   rf   ro   rm  rL  ry  rŽ   rf  rg  Zremove_indexrÙ   ru  r¬   rh  r*  ry   )rÆ   r    rf  rg  Úkwro   r÷  rP  rŽ   Zcur_optlevelZcur_kindrP   rP   rQ   rh  D  sJ    


ÿÿzTable.create_indexr   z!list[tuple[ArrayLike, ArrayLike]]rj  c           	      C  sZ   t | |||d�}| ¡ }g }| jD ]2}| | j¡ |j|| j| j| jd�}| 	|¡ q"|S )a  
        Create the axes sniffed from the table.

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

        Returns
        -------
        List[Tuple[index_values, column_values]]
        r  r=  )
Ú	Selectionr±   rF  r  r‚  râ  r”   rV   r’   rŒ   )	rÆ   ri   rž   rŸ   Ú	selectionr[  r¸  r}   ÚresrP   rP   rQ   Ú
_read_axesš  s    
üzTable._read_axes©r€  c                 C  s   |S )zreturn the data for this objrP   ©r¢  r¤  r€  rP   rP   rQ   Ú
get_object¼  s    zTable.get_objectc                   s²   t |ƒsg S |d \}‰ | j |i ¡}| d¡dkrL|rLtd|› d|› �ƒ‚|dkr^tˆ ƒ}n|dkrjg }t|tƒr t|ƒ‰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Ù   r3   z"cannot use a multi-index on axis [z] with data_columns TNc                   s    g | ]}|d kr|ˆ kr|‘qS rã  rP   r$  )Úexisting_data_columnsrP   rQ   re   Ý  s    þz/Table.validate_data_columns.<locals>.<listcomp>c                   s   g | ]}|ˆ kr|‘qS rP   rP   )ra   r÷  )Úaxis_labelsrP   rQ   re   å  s      )
rh   r‚  rÑ   r¥   rf   rK   rH  rR  rV  rò   )rÆ   r‘   r�   r*  r.  r‚  rP   )ré  rè  rQ   Úvalidate_data_columnsÁ  s*    ÿ


þÿ	zTable.validate_data_columnsr0   )r¤  rc  c           /        sŽ  t ˆtƒs,| jj}td|› dtˆƒ› d�ƒ‚ˆ dkr:dg‰ ‡fdd„ˆ D ƒ‰ |  ¡ rzd}d	d„ | jD ƒ‰ t| j	ƒ}| j
}nd
}| j}	| jdks’t‚tˆ ƒ| jd kr¬tdƒ‚g }
|dkr¼d}‡ fdd„dD ƒd }ˆj| }t|ƒ}|�r<t|
ƒ}| j| d }tt |¡t |¡ƒ�s<tt t|ƒ¡t t|ƒ¡ƒ�r<|}|	 |i ¡}t|jƒ|d< t|ƒj|d< |
 ||f¡ ˆ d }ˆj| }ˆ |¡}t||| j| jƒ}||_| d¡ |  |	¡ | !|¡ |g}t|ƒ}|dk�sàt‚t|
ƒdk�sòt‚|
D ]}t"ˆ|d |d ƒ‰�qö|jdk}|  #|||
¡}|  $ˆ|¡ %¡ }|  &|||
| j'|¡\}}g }t(t)||ƒƒD �]¸\}\}}t*}d}|�rÆt|ƒdk�rÆ|d |k�rÆt+}|d }|dk�sÆt |t,ƒ�sÆtdƒ‚|�r&|�r&z| j'| }W nB t-t.fk
�r" }  ztd|› d| j'› d�ƒ| ‚W 5 d} ~ X Y nX nd}|�p8d|› �}!t/|!|j0|||| j| j|d�}"t1|!| j2ƒ}#| 3|"¡}$t4|"j5j6ƒ}%d}&t7|"ddƒdk	�ršt8|"j9ƒ}&d }' }(})t:|"j5ƒ�rÐ|"j;})d}'tj|"j<d
d� =¡ }(t>|"ƒ\}*}+||#|!t|ƒ|$||%|&|)|'|(|+|*d�},|,  |	¡ | |,¡ |d7 }�qddd„ |D ƒ}-t| ƒ| j?| j| j| j||
||-|	|d�
}.t@| dƒ�rj| jA|._A|. B|¡ |�rŠ|�rŠ|. C| ¡ |.S )a0  
        Create and return the axes.

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

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

        min_itemsize: Dict[str, int] or None, default None
            The min itemsize for a column in bytes.
        z/cannot properly create the storer for: [group->r…  r&  Nr   c                   s   g | ]}ˆ   |¡‘qS rP   )Ú_get_axis_numberrz  )r¤  rP   rQ   re     s     z&Table._create_axes.<locals>.<listcomp>Tc                 S  s   g | ]
}|j ‘qS rP   rN  rz  rP   rP   rQ   re     s     FrR  r_   z<currently only support ndim-1 indexers in an AppendableTableÚnanc                   s   g | ]}|ˆ kr|‘qS rP   rP   r'  )rF  rP   rQ   re   0  s      rÊ  r–  rÙ   rJ  zIncompatible appended table [z]with existing table [Zvalues_block_)Úexisting_colr�   r”   rV   r’   r    r½  r  r;  )rZ   r¿  r[  rÀ  rÁ  rg  r½  ra  r¸   rÂ  rÜ  r|  c                 S  s   g | ]}|j r|j‘qS rP   )r»  rZ   )ra   rè  rP   rP   rQ   re   ¸  s      )
r»   r¶   rV   r’   r·  r*  r¸  r‘   r‚  r”   r•  )DrK   r0   r¶   r¹   r¬   rÙ   r  r·  rf   r‘   r”   r‚  rT  rÍ   rh   r¥   rF  r*  r/   rL   ÚarrayrX  rú  r–  rÚ   rŒ   Z_get_axis_namerŒ  rV   r’   r.  rÃ  rþ  rí  Ú_reindex_axisrê  rç  r0  Ú_get_blocks_and_itemsr¸  r”  r6  r  rI  rX   Ú
IndexErrorr²   Ú_maybe_convert_for_string_atomr[  rÖ  rS  r  r  rÜ  rZ   rm  rŽ  r½  r&   ra  r:  r@  r  r»   rÖ  r•  rÕ  rc  )/rÆ   rF  r¤  rc  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×  rZ   rí  rE  Únew_nameÚdata_convertedrØ  rÀ  rg  r½  r¸   rÂ  ra  r|  r  rè  ZdcsZ	new_tablerP   )rF  r¤  rQ   Ú_create_axesç  s"    
ÿ
ÿ
 ÿ





  ÿ    ÿ"ÿýø


ô

ö

zTable._create_axes)rŒ  ró  c                 C  sz  t | jtƒr|  d¡} dd„ }| j}tt|ƒ}t|jƒ}||ƒ}t|ƒr¾|d \}	}
t	|
ƒ 
t	|ƒ¡}| j||	d�j}t|jƒ}||ƒ}|D ]0}| j|g|	d�j}| |j¡ | ||ƒ¡ qŒ|�rrdd„ t||ƒD ƒ}g }g }|D ]„}t|jƒ}z&| |¡\}}| |¡ | |¡ W qä ttfk
�rf } z*d d	d
„ |D ƒ¡}td|› d�ƒ|‚W 5 d }~X Y qäX qä|}|}||fS )Nrª  c                   s   ‡ fdd„ˆ j D ƒS )Nc                   s   g | ]}ˆ j  |j¡‘qS rP   )r÷   rZ  rµ  )ra   r¶  ©ÚmgrrP   rQ   re   à  s     zFTable._get_blocks_and_items.<locals>.get_blk_items.<locals>.<listcomp>)r´  rû  rP   rû  rQ   Úget_blk_itemsß  s    z2Table._get_blocks_and_items.<locals>.get_blk_itemsr   rN  c                 S  s"   i | ]\}}t | ¡ ƒ||f“qS rP   )rg   Útolist)ra   Úbr÷  rP   rP   rQ   rQ  ù  s   ÿ
 z/Table._get_blocks_and_items.<locals>.<dictcomp>rÇ  c                 S  s   g | ]}t |ƒ‘qS rP   rY  )ra   ÚitemrP   rP   rQ   re     s     z/Table._get_blocks_and_items.<locals>.<listcomp>z+cannot match existing table structure for [z] on appending data)rK   r²  rA   r³  r   rB   rf   r´  rh   r2   rW  r`  rV  r6  rg   r[  r_  rŒ   rñ  r²   rÊ  r¥   )rŒ  ró  rô  r¸  r‘   rý  rü  r´  r¯  r.  ré  Z
new_labelsr÷  Zby_itemsZ
new_blocksZnew_blk_itemsZear÷   rÿ  r÷  rE  ZjitemsrP   rP   rQ   rð  Ñ  sN    



þ


ÿýzTable._get_blocks_and_itemsrá  )râ  r“   c           
        sª   |dk	rt |ƒ}|dk	rNˆjrNtˆjt ƒs.t‚ˆjD ]}||kr4| d|¡ q4ˆjD ]\}}tˆ |||ƒ‰ qT|jdk	r¦|j 	¡ D ]$\}‰}‡ ‡‡fdd„}	|	||ƒ‰ q€ˆ S )zprocess axes filtersNr   c                   sÌ   ˆ j D ]°}ˆ  |¡}ˆ  |¡}|d k	s*t‚| |krfˆjrH| tˆjƒ¡}ˆ||ƒ}ˆ j|d�|   S | |krt	t
ˆ | ƒjƒ}t	|ƒ}tˆ tƒr˜d| }ˆ||ƒ}ˆ j|d�|   S qtd| › d�ƒ‚d S )NrN  r_   zcannot find the field [z] for filtering!)Z_AXIS_ORDERSrë  Ú	_get_axisrÍ   rÁ  Úunionr2   r•  r^  r@   rm  r[  rK   r0   r¥   )ÚfieldÚfiltrõ  Zaxis_numberZaxis_valuesZtakersr[  ©r¤  ÚoprÆ   rP   rQ   Úprocess_filter%  s"    





z*Table.process_axes.<locals>.process_filter)
rf   rÁ  rK   r•  rÍ   Úinsertr*  rï  Úfilterr�   )
rÆ   r¤  râ  r    rí   r.  Úlabelsr  r  r  rP   r  rQ   Úprocess_axes  s    

!zTable.process_axes)rŠ   rÀ   rG  r“   c                 C  s‚   |dkrt | jdƒ}d|dœ}dd„ | jD ƒ|d< |rj|dkrH| jpFd}tƒ j|||pZ| jd	�}||d
< n| jdk	r~| j|d
< |S )z:create the description of the table from the axes & valuesNi'  ro   )rZ   rG  c                 S  s   i | ]}|j |j“qS rP   )r¿  rÀ  rz  rP   rP   rQ   rQ  Y  s      z,Table.create_description.<locals>.<dictcomp>rç  é	   )rŠ   r‹   rÀ   rÁ   )ÚmaxrÄ  rF  r¾   r|   r  r¿   rÄ   )rÆ   r‹   rŠ   rÀ   rG  rI  rÁ   rP   rP   rQ   Úcreate_descriptionJ  s     	

ý


zTable.create_descriptionrf  c           
      C  s�   |   |¡ |  ¡ sdS t| |||d�}| ¡ }|jdk	rˆ|j ¡ D ]D\}}}| j|| ¡ | ¡ d d�}	|||	j	|| ¡   |ƒj
 }qBt|ƒS )zf
        select coordinates (row numbers) from a table; return the
        coordinates object
        Fr  Nr_   rf  )re  r  rá  Úselect_coordsr	  r�   r"  r·  r  Úilocr[  r2   )
rÆ   ri   rž   rŸ   râ  Zcoordsr  r  r  r|  rP   rP   rQ   r  i  s    

  
ÿ zTable.read_coordinatesr!  c                 C  sº   |   ¡  |  ¡ sdS |dk	r$tdƒ‚| jD ]z}||jkr*|jsNtd|› d�ƒ‚t| jj	|ƒ}| 
| j¡ |j|||… | j| j| jd�}tt|d |jƒ|d�  S q*td|› d	�ƒ‚dS )
zj
        return a single column from the table, generally only indexables
        are interesting
        FNz4read_column does not currently accept a where clausezcolumn [z=] can not be extracted individually; it is not data indexabler=  r_   rY   z] not found in the table)re  r  r¬   rF  rZ   r»  r¥   rm  ro   rL  r  r‚  râ  r”   rV   r’   r5   rß  r½  r²   )rÆ   r   ri   rž   rŸ   r}   r÷  Z
col_valuesrP   rP   rQ   r"  ƒ  s*    


ÿ
üzTable.read_column)Nrv   NNNNNN)N)NNN)NN)TNNN)N)NNN)NNN)4rÚ   r±  r²  r³  rM  rN  r´  r•  r7  rÇ   rµ  rº  râ   rÓ   rc  rÁ  rÂ  rÄ  r¦  rb  ro   rÜ  rç  rF  r¼  rÈ  rÉ  rÍ  rÏ  rÐ  rÑ  rô  r  r`  ra  re  rÕ  r#   rÓ  rh  rä  rG  rç  rê  rú  Ústaticmethodrð  r  r  r  r"  rH  rP   rP   r	  rQ   rð   Ç  s²   
        õ"




	
L     ÿW   ÿ"*    ù k>:      ÿ   ûrð   c                   @  s4   e Zd ZdZdZddddœdd„Zdd	œd
d„ZdS )rŸ  zË
    a write-once read-many table: this format DOES NOT ALLOW appending to a
    table. writing is a one-time operation the data are stored in a format
    that allows for searching the data on disk
    r•  Nr   rf  c                 C  s   t dƒ‚dS )z[
        read the indices and the indexing array, calculate offset rows and return
        z!WORMTable needs to implement readNrg  rh  rP   rP   rQ   r  ¸  s    
zWORMTable.readr…   rÈ   c                 K  s   t dƒ‚dS )zÞ
        write in a format that we can search later on (but cannot append
        to): write out the indices and the values using _write_array
        (e.g. a CArray) create an indexing table so that we can search
        z"WORMTable needs to implement writeNrg  ri  rP   rP   rQ   r¨  Ä  s    zWORMTable.write)NNNN)rÚ   r±  r²  r³  rˆ  r  r¨  rP   rP   rP   rQ   rŸ  ¯  s       ûrŸ  c                   @  sd   e Zd ZdZdZdddddœd	d
„Zdddddœdd„Zddddddœdd„Zddddœdd„ZdS )rï  ú(support the new appendable table formatsZ
appendableNFTr�   r…   )rŒ   r�   r“   c                 C  s²   |s| j r| j | jd¡ | j||||||d�}|jD ]}| ¡  q6|j s~|j||||	d�}| ¡  ||d< |jj	|jf|Ž |j
|j_
|jD ]}| ||¡ qŽ|j||
d� d S )Nro   )rF  r¤  rc  r�   r”   r‘   )r‹   rŠ   rÀ   rG  r;  )r�   )r¦  r¼   rª  r¶   rú  rF  rî  r  r`  Zcreate_tabler‚  rå  rö  Ú
write_data)rÆ   r¤  rF  rŒ   r‹   rŠ   rÀ   r�   r¢   rG  r�   r”   r‘   r;  ro   r}   ÚoptionsrP   rP   rQ   r¨  Ó  s4    
ú	

ü

zAppendableTable.writer   )r¢   r�   r“   c                   sÌ  | j j}| j}g }|rT| jD ]6}t|jƒjdd�}t|tj	ƒr| 
|jddd�¡ qt|ƒrˆ|d }|dd… D ]}||@ }qp| ¡ }nd}dd	„ | jD ƒ}	t|	ƒ}
|
dks´t|
ƒ‚d
d	„ | jD ƒ}dd	„ |D ƒ}g }t|ƒD ]6\}}|f| j ||
|   j }| 
||  |¡¡ qÞ|dk�r$d}tjt||ƒ| j d�}|| d }t|ƒD ]x}|| ‰t|d | |ƒ‰ ˆˆ k�r| �qÈ| j|‡ ‡fdd	„|	D ƒ|dk	�rª|ˆˆ … nd‡ ‡fdd	„|D ƒd� �qNdS )z`
        we form the data into a 2-d including indexes,values,mask write chunk-by-chunk
        r   rN  Úu1Fr;  r_   Nc                 S  s   g | ]
}|j ‘qS rP   )rê  rz  rP   rP   rQ   re   *  s     z.AppendableTable.write_data.<locals>.<listcomp>c                 S  s   g | ]}|  ¡ ‘qS rP   )rä  rz  rP   rP   rQ   re   0  s     c              	   S  s,   g | ]$}|  t t |j¡|jd  ¡¡‘qS rž  )Z	transposerL   Zrollr  rT  r6  rP   rP   rQ   re   1  s     r¶  r3  c                   s   g | ]}|ˆˆ … ‘qS rP   rP   rz  ©Zend_iZstart_irP   rQ   re   E  s     c                   s   g | ]}|ˆˆ … ‘qS rP   rP   r6  r  rP   rQ   re   G  s     )ÚindexesrF  r[  )rÜ  r–  rÄ  r¸  r8   r|  rJ  rK   rL   rÛ  rŒ   rB  rh   r@  r·  rÍ   r”  r  Úreshaper£  r·  rS  Úwrite_data_chunk)rÆ   r¢   r�   r–  r  Zmasksr}   rF  Úmr  Únindexesr[  Úbvaluesr—  rP  Z	new_shapeÚrowsÚchunksrP   r  rQ   r    sL    




üzAppendableTable.write_datar×  zlist[np.ndarray]znpt.NDArray[np.bool_] | None)r  r  rF  r[  r“   c                 C  sä   |D ]}t  |j¡s dS q|d jd }|t|ƒkrFt j|| jd�}| jj}t|ƒ}t|ƒD ]\}	}
|
|||	 < q^t|ƒD ]\}	}||||	|  < q||dk	rÂ| ¡ j	t
dd� }| ¡ sÂ|| }t|ƒrà| j |¡ | j ¡  dS )zê
        Parameters
        ----------
        rows : an empty memory space where we are putting the chunk
        indexes : an array of the indexes
        mask : an array of the masks
        values : an array of the values
        Nr   r3  Fr;  )rL   rœ  r  rh   r£  rÜ  r–  r”  r@  rB  r�   rJ  ro   rŒ   r  )rÆ   r  r  rF  r[  rP  r  r–  r  r—  rü  r  rP   rP   rQ   r  J  s&    z AppendableTable.write_data_chunkrf  c                 C  sb  |d kst |ƒsf|d kr:|d kr:| j}| jj| jdd� n(|d krH| j}| jj||d�}| j ¡  |S |  ¡ srd S | j}t	| |||d�}| 
¡ }t|ƒ ¡ }t |ƒ}	|	�r^| ¡ }
t|
|
dk jƒ}t |ƒsÒdg}|d |	krè| |	¡ |d dk�r| dd¡ | ¡ }t|ƒD ]@}| t||ƒ¡}|j||jd  ||jd  d d� |}�q| j ¡  |	S )NTr?  rf  r_   r   r9  )rh   r  r¼   rª  r¶   ro   Zremove_rowsr  r  rá  r  r5   Zsort_valuesÚdiffrf   rŽ   rŒ   r  r_  ÚreversedrZ  rS  )rÆ   ri   rž   rŸ   r  ro   râ  r[  Zsorted_seriesÚlnr  r®   Zpgrö   r  rP   rP   rQ   rD  v  sF    

 ÿ
zAppendableTable.delete)NFNNNNNNFNNT)F)NNN)	rÚ   r±  r²  r³  rˆ  r¨  r  r  rD  rP   rP   rP   rQ   rï  Í  s$               ò<;,rï  c                   @  s`   e Zd ZU dZdZdZdZeZde	d< e
ddœd	d
„ƒZeddœdd„ƒZddddœdd„ZdS )r�  r  r‰  r“  rR  rO  rP  r�   rÈ   c                 C  s   | j d jdkS )Nr   r_   )r·  r.  rÊ   rP   rP   rQ   rÈ  »  s    z"AppendableFrameTable.is_transposedrå  c                 C  s   |r
|j }|S )zthese are written transposed)r‚  ræ  rP   rP   rQ   rç  ¿  s    zAppendableFrameTable.get_objectNr   rf  c                   s0  ˆ   |¡ ˆ  ¡ sd S ˆ j|||d�}tˆ jƒrHˆ j ˆ jd d i ¡ni }‡ fdd„tˆ jƒD ƒ}t|ƒdkstt	‚|d }|| d }	g }
tˆ jƒD �]N\}}|ˆ j
kr¬q–|| \}}| d¡dkrÐt|ƒ}n
t |¡}| d¡}|d k	rú|j|d	d
� ˆ j�r |}|}t|	t|	dd ƒd�}n|j}t|	t|	dd ƒd�}|}|jdk�rlt|tjƒ�rl| d|jd f¡}t|tjƒ�rŒt|j||d�}n.t|tƒ�r¨t|||d�}ntj|g||d�}|j|jk ¡ �sÜt	|j|jfƒ‚|
 |¡ q–t|
ƒdk�r |
d }nt|
dd�}tˆ |||d�}ˆ j |||d�}|S )Nr  r   c                   s"   g | ]\}}|ˆ j d  kr|‘qS r)  rÎ  )ra   r—  r­  rÊ   rP   rQ   re   Ý  s      z-AppendableFrameTable.read.<locals>.<listcomp>r_   rÙ   r3   r–  T©ZinplacerZ   rY   r¬  rN  )râ  r    )!re  r  rä  rh   r*  r‚  rÑ   r”  rF  rÍ   r¸  r2   r3   Úfrom_tuplesÚ	set_namesrÈ  rm  r‚  rT  rK   rL   rÛ  r  r  r0   Z_from_arraysZdtypesrÜ  rJ  rŒ   r7   rá  r  )rÆ   ri   r    rž   rŸ   rz  r‚  ZindsÚindrŽ   Úframesr—  r}   Z
index_valsrê  rL  r–  r[  Zindex_Zcols_r°  râ  rP   rÊ   rQ   r  Æ  sZ    	
ÿý



"
zAppendableFrameTable.read)NNNN)rÚ   r±  r²  r³  rM  rˆ  rT  r0   rP  r´  rµ  rÈ  rG  rç  r  rP   rP   rP   rQ   r�  ³  s   
    ûr�  c                      sn   e Zd ZdZdZdZdZeZe	ddœdd„ƒZ
edd	œd
d„ƒZd‡ fdd„	Zdddddœ‡ fdd„Z‡  ZS )r›  r  r�  r‘  rR  r�   rÈ   c                 C  s   dS r  rP   rÊ   rP   rP   rQ   rÈ    s    z#AppendableSeriesTable.is_transposedrå  c                 C  s   |S rS   rP   ræ  rP   rP   rQ   rç  #  s    z AppendableSeriesTable.get_objectNc                   s<   t |tƒs|jpd}| |¡}tƒ jf ||j ¡ dœ|—ŽS )ú+we are going to write this as a frame tabler[  ©r¤  r‘   )rK   r0   rZ   Zto_framer  r¨  r    rþ  )rÆ   r¤  r‘   r´   rZ   r	  rP   rQ   r¨  '  s    


zAppendableSeriesTable.writer   r5   rj  c                   s�   | j }|d k	rB|rBt| jtƒs"t‚| jD ]}||kr(| d|¡ q(tƒ j||||d�}|rj|j| jdd� |j	d d …df }|j
dkrŒd |_
|S )Nr   r-  Tr"  r[  )rÁ  rK   r•  rf   rÍ   r  r  r  Ú	set_indexr  rZ   )rÆ   ri   r    rž   rŸ   rÁ  rí   rO   r	  rP   rQ   r  .  s    

zAppendableSeriesTable.read)N)NNNN)rÚ   r±  r²  r³  rM  rˆ  rT  r5   rP  rµ  rÈ  rG  rç  r¨  r  rH  rP   rP   r	  rQ   r›    s   	    ûr›  c                      s(   e Zd ZdZdZdZ‡ fdd„Z‡  ZS )rœ  r  r�  r’  c                   s^   |j pd}|  |¡\}| _t| jtƒs*t‚t| jƒ}| |¡ t|ƒ|_t	ƒ j
f d|i|—ŽS )r'  r[  r¤  )rZ   rÂ  r•  rK   rf   rÍ   rŒ   r2   r    r  r¨  )rÆ   r¤  r´   rZ   ZnewobjrL  r	  rP   rQ   r¨  N  s    



z AppendableMultiSeriesTable.write)rÚ   r±  r²  r³  rM  rˆ  r¨  rH  rP   rP   r	  rQ   rœ  H  s   rœ  c                   @  sj   e Zd ZU dZdZdZdZeZde	d< e
ddœd	d
„ƒZe
dd„ ƒZddœdd„Zedd„ ƒZdd„ ZdS )rš  z:a table that read/writes the generic pytables table formatr‰  rŠ  rR  zlist[Hashable]r•  rX   rÈ   c                 C  s   | j S rS   )rM  rÊ   rP   rP   rQ   rj  b  s    zGenericTable.pandas_typec                 C  s   t | jdd ƒp| jS rÅ  rÆ  rÊ   rP   rP   rQ   rb  f  s    zGenericTable.storabler…   c                 C  sL   g | _ d| _g | _dd„ | jD ƒ| _dd„ | jD ƒ| _dd„ | jD ƒ| _dS )r~  Nc                 S  s   g | ]}|j r|‘qS rP   rÒ  rz  rP   rP   rQ   re   p  s      z*GenericTable.get_attrs.<locals>.<listcomp>c                 S  s   g | ]}|j s|‘qS rP   rÒ  rz  rP   rP   rQ   re   q  s      c                 S  s   g | ]
}|j ‘qS rP   rY   rz  rP   rP   rQ   re   r  s     )r*  r”   r•  rÓ  r·  r¸  r‘   rÊ   rP   rP   rQ   ra  j  s    zGenericTable.get_attrsc           
   
   C  s¨   | j }|  d¡}|dk	rdnd}tdd| j||d�}|g}t|jƒD ]^\}}t|tƒsZt‚t	||ƒ}|  |¡}|dk	rzdnd}t
|||g|| j||d�}	| |	¡ qD|S )z0create the indexables from the table descriptionrŽ   Nr  r   )rZ   r.  ro   r¸   rÂ  )rZ   rÁ  r[  rÀ  ro   r¸   rÂ  )rç  r  r  ro   r”  Z_v_namesrK   rX   rÍ   rm  rK  rŒ   )
rÆ   rI  rÙ  r¸   rÞ  rÝ  r—  rí   r  rb  rP   rP   rQ   rÓ  t  s6    
    ÿ

ù	zGenericTable.indexablesc                 K  s   t dƒ‚d S )Nz cannot write on an generic tablerg  ri  rP   rP   rQ   r¨  —  s    zGenericTable.writeN)rÚ   r±  r²  r³  rM  rˆ  rT  r0   rP  r´  rµ  rj  rb  ra  r#   rÓ  r¨  rP   rP   rP   rQ   rš  Y  s   



"rš  c                      s`   e Zd ZdZdZeZdZe 	d¡Z
eddœdd„ƒZd‡ fd
d„	Zddddœ‡ fdd„Z‡  ZS )rž  za frame with a multi-indexr”  rR  z^level_\d+$rX   rÈ   c                 C  s   dS )NZappendable_multirP   rÊ   rP   rP   rQ   rº  £  s    z*AppendableMultiFrameTable.table_type_shortNc                   sx   |d krg }n|dkr |j  ¡ }|  |¡\}| _t| jtƒs@t‚| jD ]}||krF| d|¡ qFtƒ j	f ||dœ|—ŽS )NTr   r(  )
r    rþ  rÂ  r•  rK   rf   rÍ   r  r  r¨  )rÆ   r¤  r‘   r´   rí   r	  rP   rQ   r¨  §  s    

zAppendableMultiFrameTable.writer   rf  c                   sD   t ƒ j||||d�}| ˆ j¡}|j ‡ fdd„|jjD ƒ¡|_|S )Nr-  c                   s    g | ]}ˆ j  |¡rd n|‘qS rS   )Ú
_re_levelsÚsearch)ra   rZ   rÊ   rP   rQ   re   À  s     z2AppendableMultiFrameTable.read.<locals>.<listcomp>)r  r  r)  r•  rŽ   r$  r–  )rÆ   ri   r    rž   rŸ   r°  r	  rÊ   rQ   r  ³  s    ÿzAppendableMultiFrameTable.read)N)NNNN)rÚ   r±  r²  r³  rˆ  r0   rP  rT  ÚreÚcompiler*  rµ  rº  r¨  r  rH  rP   rP   r	  rQ   rž  ›  s   
    ûrž  r0   r2   )r¤  r.  r
  r“   c                 C  s¢   |   |¡}t|ƒ}|d k	r"t|ƒ}|d ks4| |¡rB| |¡rB| S t| ¡ ƒ}|d k	rlt| ¡ ƒj|dd�}| |¡sžtd d ƒg| j }|||< | jt|ƒ } | S )NF)Úsort)	r  r@   ÚequalsÚuniquer]  ÚslicerT  r^  rg   )r¤  r.  r
  rÎ  r­  ZslicerrP   rP   rQ   rï  Æ  s    

rï  r   zstr | tzinfo)r½  r“   c                 C  s   t  | ¡}|S )z+for a tz-aware type, return an encoded zone)r   Zget_timezone)r½  ÚzonerP   rP   rQ   rŽ  Þ  s    
rŽ  znp.ndarray | Indexr1   )r[  r½  r0  r“   c                 C  s   d S rS   rP   ©r[  r½  r0  rP   rP   rQ   rß  ä  s    rß  r×  c                 C  s   d S rS   rP   r3  rP   rP   rQ   rß  ë  s    zstr | tzinfo | Noneznp.ndarray | DatetimeIndexc                 C  sŠ   t | tƒr"| jdks"| j|ks"t‚|dk	rtt | tƒrB| j}| j} nd}|  ¡ } t|ƒ}t| |d�} |  d¡ 	|¡} n|r†t
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
    NrY   rv  úM8[ns]r3  )rK   r1   r½  rÍ   rZ   r¥  r@  rR   rx  ry  rL   r>  )r[  r½  r0  rZ   rP   rP   rQ   rß  ð  s    

)rZ   rŽ   rV   r’   r“   c              
   C  st  t | tƒst‚|j}t|ƒ\}}t|ƒ}t |¡}t |tƒsFt	|j
ƒrlt| |||t|dd ƒt|dd ƒ|d�S t |tƒr~tdƒ‚tj|dd�}	t |¡}
|	dkrÐtjdd	„ |
D ƒtjd
�}t| |dtƒ  ¡ |d�S |	dk�rt|
||ƒ}|j
j}t| |dtƒ  |¡|d�S |	dk�r$t| ||||d�S t |tjƒ�r>|j
tk�sBt‚|dk�sTt|ƒ‚tƒ  ¡ }t| ||||d�S d S )Nr¼  r½  )r[  rg  rÀ  r¼  r½  r¾  zMultiIndex not supported here!Fr¡  r   c                 S  s   g | ]}|  ¡ ‘qS rP   )Ú	toordinalr6  rP   rP   rQ   re   8  s     z"_convert_index.<locals>.<listcomp>r3  )r¾  rë  )ÚintegerZfloating)r[  rg  rÀ  r¾  r?  )rK   rX   rÍ   rZ   r  r  rI  r  r9   r.   rÜ  r¹  rm  r3   r¬   r   r¢  rL   r>  Zint32r|   Z	Time32ColÚ_convert_string_arrayrÄ  rì  rÛ  r?  r£  )rZ   rŽ   rV   r’   r¾  rE  r  rg  r  r§  r[  rÄ  rP   rP   rQ   rŒ    sd    


ù


    ÿ

û
    ÿ
rŒ  )rg  rV   r’   r“   c                 C  sÐ   |dkrt | ƒ}nº|dkr$t| ƒ}n¨|dkrxztjdd„ | D ƒtd�}W qÌ tk
rt   tjdd„ | D ƒtd�}Y qÌX nT|dkrŒt | ¡}n@|d	kr¦t| d ||d
�}n&|dkr¾t | d ¡}ntd|› �ƒ‚|S )Nr.  r1  r   c                 S  s   g | ]}t  |¡‘qS rP   r4  r6  rP   rP   rQ   re   \  s     z$_unconvert_index.<locals>.<listcomp>r3  c                 S  s   g | ]}t  |¡‘qS rP   r7  r6  rP   rP   rQ   re   ^  s     )r6  Úfloatrë  r=  r?  r   zunrecognized index type )r1   r6   rL   r>  r?  r¥   rD  )r|  rg  rV   r’   rŽ   rP   rP   rQ   r�  S  s,    

    ÿr�  r   ré   )rZ   r  r    c                 C  s–  |j tkr|S ttj|ƒ}|j j}tj|dd�}	|	dkrBtdƒ‚n&|	dkrTtdƒ‚n|	dksh|dksh|S t	|ƒ}
| 
¡ }|||
< tj|dd�}	|	dkrüt|jd	 ƒD ]V}|| }tj|dd�}	|	dkr¤t|ƒ|krÚ|| nd
|› �}td|› d|	› d�ƒ‚q¤t|||ƒ |j¡}|j}t|tƒ�rBt| | ¡�p>| d¡�p>d	ƒ}t|�pLd	|ƒ}|d k	�r~| |¡}|d k	�r~||k�r~|}|jd|› �dd�}|S )NFr¡  r   z+[date] is not implemented as a table columnrl  z>too many timezones in this block, create separate data columnsrë  r?  r   zNo.zCannot serialize the column [z2]
because its data contents are not [string] but [z] object dtyper[  z|Sr;  )rÜ  r?  r   rL   rÛ  rZ   r   r¢  r¬   r8   r}  rS  r  rh   r7  r  rÄ  rK   rH  r\   rÑ   r  rñ  rB  )rZ   r  rí  r�   r”   rV   r’   r    r  r§  rF  r|  r—  rè  Zerror_column_labelrù  rÄ  ZecirP   rP   rQ   rò  l  sJ    

ÿÿ 

rò  )r|  rV   r’   r“   c                 C  s\   t | ƒr(t|  ¡ ƒ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]
    r_   ÚSr3  )rh   r5   r@  rX   ÚencoderC  r  r  r%   r  Ú
libwritersÚmax_len_string_arrayrL   r>  )r|  rV   r’   ÚensuredrÄ  rP   rP   rQ   r7  ·  s     ÿþÿr7  c                 C  s˜   | j }tj|  ¡ td�} t| ƒrvt t| ƒ¡}d|› �}t	| d t
ƒr^t| ƒjj||d�j} n| j|dd�jtdd�} |dkr‚d}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.
    r3  ÚUr   )r’   Fr;  Nrì  )r  rL   r>  r@  r?  rh   r;  r<  r%   rK   r{  r5   rX   rN   rC  rB  Z!string_array_replace_from_nan_repr  )r|  r”   rV   r’   r  rÄ  rÜ  rP   rP   rQ   rD  Ö  s    
rD  )r[  rà  rV   r’   c                 C  s6   t |tƒstt|ƒƒ‚t|ƒr2t|||ƒ}|| ƒ} | S rS   )rK   rX   rÍ   rÙ   Ú_need_convertÚ_get_converter)r[  rà  rV   r’   ÚconvrP   rP   rQ   rÞ  ý  s
    rÞ  ©rg  rV   r’   c                   s8   | dkrdd„ S | dkr&‡ ‡fdd„S t d| › �ƒ‚d S )Nr.  c                 S  s   t j| dd�S )Nr4  r3  )rL   r>  ©r(  rP   rP   rQ   r˜     ó    z _get_converter.<locals>.<lambda>rë  c                   s   t | d ˆ ˆd�S )Nr=  )rD  rC  r�  rP   rQ   r˜   	  s
      ÿzinvalid kind )r¥   rB  rP   r�  rQ   r@    s
    r@  r!  c                 C  s   | dkrdS dS )N)r.  rë  TFrP   r  rP   rP   rQ   r?    s    r?  zSequence[int])rZ   rS  r“   c                 C  sl   t |tƒst|ƒdk rtdƒ‚|d dkrh|d dkrh|d dkrht d| ¡}|rh| ¡ d }d|› �} | S )	zö
    Prior to 0.10.1, we named values blocks like: values_block_0 an the
    name values_0, adjust the given name if necessary.

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

    Returns
    -------
    str
    é   z6Version is incorrect, expected sequence of 3 integers.r   r_   rQ  rR  zvalues_block_(\d+)Zvalues_)rK   rX   rh   r¥   r,  r+  r®   )rZ   rS  r  ÚgrprP   rP   rQ   rÖ    s    $
rÖ  )Ú	dtype_strr“   c                 C  sÎ   t | ƒ} |  d¡s|  d¡r"d}n¨|  d¡r2d}n˜|  d¡rBd}nˆ|  d¡sV|  d¡r\d}nn|  d¡rld}n^|  d	¡r|d
}nN|  d¡rŒd}n>|  d¡rœd}n.|  d¡r¬d}n| dkrºd}ntd| › d�ƒ‚|S )zA
    Find the "kind" string describing the given dtype name.
    rë  r{  r8  rß  r\   r"  r6  r.  Ú	timedeltar1  r�   r  r$  r?  zcannot interpret dtype of [r&  )rR   ru  r¥   )rG  rg  rP   rP   rQ   r  /  s.    






r  r  c                 C  sb   t | tƒr| j} | jj d¡d }| jjdkr@t |  	d¡¡} nt | t
ƒrP| j} t | ¡} | |fS )zJ
    Convert the passed data into a storable form and a dtype string.
    rZ  r   )r  ÚMrÙ  )rK   r:   r  rÜ  rZ   r¬  rg  rL   r>  r¤  r4   r¥  )r|  r  rP   rP   rQ   r  P  s    


r  c                   @  s>   e Zd ZdZddddddœdd„Zd	d
„ Zdd„ Zdd„ ZdS )rá  zæ
    Carries out a selection operation on a tables.Table object.

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

    Nrð   r   r…   )ro   rž   rŸ   r“   c              	   C  sR  || _ || _|| _|| _d | _d | _d | _d | _t|ƒ�rt	t
ƒ�Ð tj|dd�}|dksd|dk�rt |¡}|jtjkr¸| j| j }}|d kr”d}|d kr¤| j j}t ||¡| | _nVt|jjtjƒ�r| jd k	rä|| jk  ¡ �s | jd k	�r|| jk ¡ �rt
dƒ‚|| _W 5 Q R X | jd k�rN|  |¡| _| jd k	�rN| j ¡ \| _| _d S )NFr¡  r6  Úbooleanr   z3where must have index locations >= start and < stop)ro   ri   rž   rŸ   Ú	conditionr	  Ztermsr3  r+   r   r¥   r   r¢  rL   r>  rÜ  Zbool_r  r  Ú
issubclassrÙ   r6  rA  ÚgenerateÚevaluate)rÆ   ro   ri   rž   rŸ   ÚinferredrP   rP   rQ   rÇ   r  sD    


ÿÿÿzSelection.__init__c              
   C  s€   |dkrdS | j  ¡ }zt||| j jd�W S  tk
rz } z2d | ¡ ¡}td|› d|› d�ƒ}t|ƒ|‚W 5 d}~X Y nX dS )z'where can be a : dict,list,tuple,stringN)rÍ  rV   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
                )	ro   rÍ  r=   rV   Ú	NameErrorrÊ  rò   r   r¥   )rÆ   ri   rÔ  rE  Zqkeysr  rP   rP   rQ   rM  ¡  s    
ÿûÿ	zSelection.generatec                 C  sX   | j dk	r(| jjj| j  ¡ | j| jd�S | jdk	rB| jj | j¡S | jjj| j| jd�S )ú(
        generate the selection
        Nrf  )	rK  ro   Z
read_wherer�   rž   rŸ   r3  r  r  rÊ   rP   rP   rQ   r±   ¸  s    
  ÿ
zSelection.selectc                 C  s”   | j | j }}| jj}|dkr$d}n|dk r4||7 }|dkrB|}n|dk rR||7 }| jdk	rx| jjj| j ¡ ||dd�S | jdk	rˆ| jS t 	||¡S )rQ  Nr   T)rž   rŸ   r.  )
rž   rŸ   ro   r  rK  Zget_where_listr�   r3  rL   r  )rÆ   rž   rŸ   r  rP   rP   rQ   r  Ä  s(    
   ÿ
zSelection.select_coords)NNN)rÚ   r±  r²  r³  rÇ   rM  r±   r  rP   rP   rP   rQ   rá  f  s      û/rá  )r}   NNFNTNNNNrv   rJ   )	Nr�   rv   NNNNFN)N)F)F)F)¬r³  Ú
__future__r   Ú
contextlibr   r}  rl  r   r   rý   r4  r©   r,  Útextwrapr   Útypingr   r   r	   r
   r   r   r   r   r   r   rú   ÚnumpyrL   Zpandas._configr   r   Zpandas._libsr   r   r;  Zpandas._libs.tslibsr   Zpandas._typingr   r   r   r   r   r   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*   r+   r,   r-   r.   Zpandas.core.dtypes.missingr/   rè   r0   r1   r2   r3   r4   r5   r6   r7   r8   Zpandas.core.apir9   Zpandas.core.arraysr:   r;   r<   Zpandas.core.commonÚcoreÚcommonrB  Z pandas.core.computation.pytablesr=   r>   Zpandas.core.constructionr?   Zpandas.core.indexes.apir@   Zpandas.core.internalsrA   rB   Zpandas.io.commonrC   Zpandas.io.formats.printingrD   rE   rx   rF   rG   rH   rI   r]  rT   rR   rW   r[   r`   rj   rk   r´  rl   rm   rƒ  rU  rr   rs   Zconfig_prefixZregister_optionZis_boolZis_one_of_factoryrw   r{   r|   rœ   rµ   r¯   r›   r  r¹  r  r  rI  rK  rL  rk  r—  r¨  r˜  rð   rŸ  rï  r�  r›  rœ  rš  rž  rï  rŽ  rß  rŒ  r�  rò  r7  rD  rÞ  r@  r?  rÖ  r  r  rá  rP   rP   rP   rQ   Ú<module>   s0  0 0,
ü            ñ,:         ö            _p  +!   3  i!`       o gd1B+ ÿ ÿ&=K'!