a
    oÝEb–– ã                   @  sÞ  d Z ddlmZ ddlmZ ddlZddlmZmZ ddl	Z	ddl
Z
ddlZddlmZ ddlmZmZmZmZmZmZmZ ddlZddlZddlmZmZ dd	lmZmZ dd
l m!Z! ddl"m#Z#m$Z$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: ddl;m<Z< ddl=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF ddlGmHZH ddlImJZJmKZKmLZL ddlMmN  mOZP ddlQmRZRmSZS ddlTmUZU ddlVmWZW ddlXmYZYmZZZ ddl[m\Z\ ddl]m^Z^m_Z_ e�rddl`maZambZbmcZc ddlXmdZd dZedZfd d!„ Zgd"d#„ Zhd$d%„ ZieRZjd&d'œd(d)„ZkG d*d+„ d+elƒZmG d,d-„ d-elƒZnG d.d/„ d/eoƒZpd0ZqG d1d2„ d2eoƒZrd3ZsG d4d5„ d5eoƒZtd6Zud7Zvd8d8d9d9d:œZwe>dgiZxd;Zyd<Zze {d=¡�@ ej|d>d?eyej}d@� ej|dAdeze ~g dB¢¡d@� W d  ƒ n1 �s 0    Y  dad?a€dCdD„ Z�dºdHdIdHdJdKdLdKdLdMdNdOdHdHdPdQœdRdS„Z‚d»dHdHdJdJdJdUœdVdW„ZƒdXdXdLdYœdZd[„Z„G d\d]„ d]ƒZ…G d^d_„ d_ƒZ†G d`da„ daƒZ‡G dbdc„ dce‡ƒZˆG ddde„ dee‡ƒZ‰G dfdg„ dge‰ƒZŠG dhdi„ dieŠƒZ‹G djdk„ dkƒZŒG dldm„ dmeŒƒZ�G dndo„ doe�ƒZŽG dpdq„ dqe�ƒZ�G drds„ dse�ƒZ�G dtdu„ dueŒƒZ‘G dvdw„ dwe‘ƒZ’G dxdy„ dye‘ƒZ“G dzd{„ d{e“ƒZ”G d|d}„ d}e”ƒ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šd½dŽd�dLd�d‘œd’d“„Z›dHd…dHdHdad”œd•d–„ZœdHdHdHdŽd—œd˜d™„Z�dHdšd›dœœd�dž„ZždŸdHdHdŸd œd¡d¢„ZŸdŸdHdHdŸd œd£d¤„Z dŸdHdHdHd¥œd¦d§„Z¡dHdHdHd¨œd©dª„Z¢dHdLd«œd¬d­„Z£dHd®dHd¯œd°d±„Z¤dHdHd²œ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ÚHashableÚLiteralÚSequenceÚcast)ÚconfigÚ
get_option)ÚlibÚwriters)Ú	timezones)Ú	ArrayLikeÚDtypeArgÚShape)Úimport_optional_dependency)Úpatch_pickle)ÚPerformanceWarning)Ú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 unicoder@   )Ú
isinstanceÚnpÚbytes_Údecode)Ús© rF   úR/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/pandas/io/pytables.pyÚ_ensure_decodedu   s    
rH   c                 C  s   | d u rt } | S ©N)Ú_default_encoding©ÚencodingrF   rF   rG   Ú_ensure_encoding|   s    rM   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
    )rA   Ústr©ÚnamerF   rF   rG   Ú_ensure_str„   s    
rQ   Úint©Úscope_levelc                   sV   |d ‰ t | ttfƒr*‡ fdd„| D ƒ} nt| ƒr>t| ˆ d�} | du sNt| ƒrR| S dS )zÔ
    Ensure that the where is a Term or a list of Term.

    This makes sure that we are capturing the scope of variables that are
    passed create the terms here with a frame_level=2 (we are 2 levels down)
    é   c                   s0   g | ](}|d urt |ƒr(t|ˆ d d�n|‘qS )NrU   rS   )r4   ÚTerm)Ú.0Úterm©ÚlevelrF   rG   Ú
<listcomp>ž   s   þz _ensure_term.<locals>.<listcomp>rS   N)rA   ÚlistÚtupler4   rV   Úlen)ÚwhererT   rF   rY   rG   Ú_ensure_term“   s    	
þr`   c                   @  s   e Zd ZdS )ÚPossibleDataLossErrorN©Ú__name__Ú
__module__Ú__qualname__rF   rF   rF   rG   ra   ¨   s   ra   c                   @  s   e Zd ZdS )ÚClosedFileErrorNrb   rF   rF   rF   rG   rf   ¬   s   rf   c                   @  s   e Zd ZdS )ÚIncompatibilityWarningNrb   rF   rF   rF   rG   rg   °   s   rg   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)
c                   @  s   e Zd ZdS )ÚAttributeConflictWarningNrb   rF   rF   rF   rG   rh   »   s   rh   zu
the [%s] attribute of the existing index is [%s] which conflicts with the new
[%s], resetting the attribute to None
c                   @  s   e Zd ZdS )ÚDuplicateWarningNrb   rF   rF   rF   rG   ri   Å   s   ri   z;
duplicate entries in table, taking most recently appended
z‘
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]
ÚfixedÚtable)Úfrj   Útrk   z;
: boolean
    drop ALL nan rows when appending to a table
z~
: format
    default format writing format, if None, then
    put will default to 'fixed' and append will default to 'table'
zio.hdfZdropna_tableF)Z	validatorÚdefault_format)rj   rk   Nc                  C  sL   t d u rHdd l} | a ttƒ� | jjdkaW d   ƒ n1 s>0    Y  t S )Nr   Ústrict)Ú
_table_modÚtablesr   ÚAttributeErrorÚfileZ_FILE_OPEN_POLICYÚ!_table_file_open_policy_is_strict)rq   rF   rF   rG   Ú_tablesñ   s    

ÿ ru   ÚaTro   rN   úDataFrame | Seriesú
int | Noneú
str | NoneÚboolúint | dict[str, int] | Noneúbool | Noneú Literal[True] | list[str] | NoneÚNone)ÚkeyÚvalueÚmodeÚ	complevelÚcomplibÚappendÚformatÚindexÚmin_itemsizeÚdropnaÚdata_columnsÚerrorsrL   Úreturnc              
     sš   |r$‡ ‡‡‡‡‡‡‡‡‡	f
dd„}n‡ ‡‡‡‡‡‡‡‡‡	f
dd„}t | ƒ} t| tƒrŽt| |||d��}||ƒ W d  ƒ q–1 s‚0    Y  n|| ƒ dS )z+store this object, close it if we opened itc                   s   | j ˆˆ	ˆˆˆˆˆˆ ˆˆd�
S )N)r…   r†   r‡   Únan_reprˆ   r‰   rŠ   rL   ©r„   ©Ústore©
r‰   rˆ   rL   rŠ   r…   r†   r   r‡   rŒ   r€   rF   rG   Ú<lambda>  s   özto_hdf.<locals>.<lambda>c                   s   | j ˆˆ	ˆˆˆˆˆ ˆˆˆd�
S )N)r…   r†   r‡   rŒ   r‰   rŠ   rL   rˆ   ©ÚputrŽ   r�   rF   rG   r‘   (  s   ö)r�   r‚   rƒ   N)r9   rA   rN   ÚHDFStore)Úpath_or_bufr   r€   r�   r‚   rƒ   r„   r…   r†   r‡   rŒ   rˆ   r‰   rŠ   rL   rl   r�   rF   r�   rG   Úto_hdf  s     
ÿ(r–   Úr)r�   rŠ   ÚstartÚstopÚ	chunksizec
                 K  s–  |dvrt d|› d�ƒ‚|dur,t|dd�}t| tƒrN| jsDtdƒ‚| }d}ntt| ƒ} t| tƒshtd	ƒ‚zt	j
 | ¡}W n tt fy’   d}Y n0 |s¨td
| › d�ƒ‚t| f||dœ|
¤Ž}d}zt|du �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�y�   t| tƒ�sŠttƒ� | ¡  W d  ƒ n1 �s€0    Y  ‚ Y n0 dS )a)	  
    Read from the store, close it if we opened it.

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

    .. warning::

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

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

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

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

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

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

    Returns
    -------
    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+rv   zmode zG is not allowed while performing a read. Allowed modes are r, r+ and a.NrU   rS   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.)r_   r˜   r™   ÚcolumnsÚiteratorrš   Ú
auto_close)Ú
ValueErrorr`   rA   r”   Úis_openÚOSErrorr9   rN   ÚNotImplementedErrorÚosÚpathÚexistsÚ	TypeErrorÚFileNotFoundErrorÚgroupsr^   Ú_is_metadata_ofÚ_v_pathnameÚselectÚKeyErrorr   rr   Úclose)r•   r   r�   rŠ   r_   r˜   r™   rœ   r�   rš   Úkwargsr�   rž   r¥   r¨   Zcandidate_only_groupZgroup_to_checkrF   rF   rG   Úread_hdf?  sj    O
ÿ

ÿ

ÿ
ÿø

(r¯   r>   )Ú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.FrU   ÚmetaT)Z_v_depthZ	_v_parentÚ_v_name)r°   r±   ÚcurrentÚparentrF   rF   rG   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„Zdd„ Zedd„ ƒZe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!œd"d#„Zdd$œd%d&„Zdd$œd'd(„Zd)d*„ Zd+d,„ Zd�dd.d/œd0d1„Zd2d3„ Zd4d5„ ZeZdŽdd6œd7d8„Zd9d:„ Zedd$œd;d<„ƒZd�dd=œd>d?„Zddœd@dA„Zd�dddBœdCdD„Zd‘ddddEœdFdG„Zd’dddddHœdIdJ„Zd“ddKœdLdM„Zd”ddPddQdRddddSœdTdU„Z d•ddœdVdW„Z!d–ddPddQdXdRddYœdZd[„Z"d—d\d]œd^d_„Z#d˜ddd`daœdbdc„Z$ddde„ Z%d™dgdh„Z&ddid!œdjdk„Z'ddld!œdmdn„Z(dšddddpœdqdr„Z)dd$œdsdt„Z*dudv„ Z+dddwœdxdy„Z,d›d{dddld|œd}d~„Z-dœddPddQd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Ú_handlerN   Ú_moderR   Ú
_complevelrz   Ú_fletcher32rv   NFrx   )r�   r‚   Ú
fletcher32c                 K  s²   d|v rt dƒ‚tdƒ}|d ur@||jjvr@t d|jj› d�ƒ‚|d u rX|d urX|jj}t|ƒ| _|d u rnd}|| _d | _|r‚|nd| _	|| _
|| _d | _| jf d|i|¤Ž d S )	Nr…   z-format is not a defined argument for HDFStorerq   zcomplib only supports z compression.rv   r   r�   )rŸ   r   ÚfiltersZall_complibsZdefault_complibr9   Ú_pathr·   r¶   r¸   Ú_complibr¹   Ú_filtersÚopen)Úselfr¤   r�   r‚   rƒ   rº   r®   rq   rF   rF   rG   Ú__init__/  s&    
ÿ
zHDFStore.__init__c                 C  s   | j S rI   ©r¼   ©rÀ   rF   rF   rG   Ú
__fspath__Q  s    zHDFStore.__fspath__c                 C  s   |   ¡  | jdusJ ‚| jjS )zreturn the root nodeN)Ú_check_if_openr¶   ÚrootrÃ   rF   rF   rG   rÆ   T  s    zHDFStore.rootc                 C  s   | j S rI   rÂ   rÃ   rF   rF   rG   Úfilename[  s    zHDFStore.filename©r   c                 C  s
   |   |¡S rI   )Úget©rÀ   r   rF   rF   rG   Ú__getitem___  s    zHDFStore.__getitem__c                 C  s   |   ||¡ d S rI   r’   )rÀ   r   r€   rF   rF   rG   Ú__setitem__b  s    zHDFStore.__setitem__c                 C  s
   |   |¡S rI   )ÚremoverÊ   rF   rF   rG   Ú__delitem__e  s    zHDFStore.__delitem__rO   c              	   C  sD   z|   |¡W S  ttfy"   Y n0 tdt| ƒj› d|› d�ƒ‚dS )z$allow attribute access to get storesú'z' object has no attribute 'N)rÉ   r¬   rf   rr   Útyperc   )rÀ   rP   rF   rF   rG   Ú__getattr__h  s    ÿzHDFStore.__getattr__©r   r‹   c                 C  s8   |   |¡}|du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 '/'
        NrU   TF)Úget_noderª   )rÀ   r   ÚnoderP   rF   rF   rG   Ú__contains__r  s    
zHDFStore.__contains__©r‹   c                 C  s   t |  ¡ ƒS rI   )r^   r¨   rÃ   rF   rF   rG   Ú__len__~  s    zHDFStore.__len__c                 C  s   t | jƒ}t| ƒ› d|› d�S )Nú
File path: Ú
)r;   r¼   rÐ   )rÀ   ÚpstrrF   rF   rG   Ú__repr__�  s    
zHDFStore.__repr__c                 C  s   | S rI   rF   rÃ   rF   rF   rG   Ú	__enter__…  s    zHDFStore.__enter__c                 C  s   |   ¡  d S rI   )r­   )rÀ   Úexc_typeÚ	exc_valueÚ	tracebackrF   rF   rG   Ú__exit__ˆ  s    zHDFStore.__exit__Úpandasú	list[str])Úincluder‹   c                 C  s^   |dkrdd„ |   ¡ D ƒS |dkrJ| jdus0J ‚dd„ | jjddd	�D ƒS td
|› d�ƒ‚dS )a#  
        Return a list of keys corresponding to objects stored in HDFStore.

        Parameters
        ----------

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

                .. 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 rF   ©rª   ©rW   ÚnrF   rF   rG   r[   ¢  ó    z!HDFStore.keys.<locals>.<listcomp>ÚnativeNc                 S  s   g | ]
}|j ‘qS rF   rä   rå   rF   rF   rG   r[   ¦  s   ú/ÚTable)Ú	classnamez8`include` should be either 'pandas' or 'native' but is 'rÏ   )r¨   r¶   Z
walk_nodesrŸ   )rÀ   rã   rF   rF   rG   Úkeys‹  s    ÿ
ÿzHDFStore.keysc                 C  s   t |  ¡ ƒS rI   )Úiterrì   rÃ   rF   rF   rG   Ú__iter__­  s    zHDFStore.__iter__c                 c  s   |   ¡ D ]}|j|fV  qdS )z'
        iterate on key->group
        N)r¨   rª   )rÀ   ÚgrF   rF   rG   Úitems°  s    zHDFStore.items)r�   c                 K  s¾   t ƒ }| j|krR| jdv r$|dv r$n(|dv rL| jrLtd| j› d| j› d�ƒ‚|| _| jr`|  ¡  | jrŠ| jdkrŠt ƒ j| j| j| j	d�| _
tr | jr d	}t|ƒ‚|j| j| jfi |¤Ž| _d
S )a9  
        Open the file in the specified mode

        Parameters
        ----------
        mode : {'a', 'w', 'r', 'r+'}, default 'a'
            See HDFStore docstring or tables.open_file for info about modes
        **kwargs
            These parameters will be passed to the PyTables open_file method.
        )rv   Ú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)ru   r·   r    ra   r¼   r­   r¸   ÚFiltersr½   r¹   r¾   rt   rŸ   Ú	open_filer¶   )rÀ   r�   r®   rq   ÚmsgrF   rF   rG   r¿   ¹  s*    
ÿÿ
ÿzHDFStore.openc                 C  s   | j dur| j  ¡  d| _ dS )z0
        Close the PyTables file handle
        N)r¶   r­   rÃ   rF   rF   rG   r­   æ  s    

zHDFStore.closec                 C  s   | j du rdS t| j jƒS )zF
        return a boolean indicating whether the file is open
        NF)r¶   rz   ZisopenrÃ   rF   rF   rG   r    î  s    
zHDFStore.is_open)Úfsyncc                 C  sT   | j durP| j  ¡  |rPttƒ�  t | j  ¡ ¡ W d  ƒ n1 sF0    Y  dS )aó  
        Force all buffered modifications to be written to disk.

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

        Notes
        -----
        Without ``fsync=True``, flushing may not guarantee that the OS writes
        to disk. With fsync, the operation will block until the OS claims the
        file has been written; however, other caching layers may still
        interfere.
        N)r¶   Úflushr   r¡   r£   rõ   Úfileno)rÀ   rõ   rF   rF   rG   rö   ÷  s
    


zHDFStore.flushc                 C  sV   t ƒ �< |  |¡}|du r*td|› d�ƒ‚|  |¡W  d  ƒ S 1 sH0    Y  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°   rF   rF   rG   rÉ     s
    
zHDFStore.get)r   rž   c	                   st   |   |¡}	|	du 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ù   rU   rS   c                   s   ˆj | ||ˆ d�S )N)r˜   r™   r_   rœ   ©Úread©Ú_startÚ_stopÚ_where©rœ   rE   rF   rG   ÚfuncZ  s    zHDFStore.select.<locals>.func©r_   Únrowsr˜   r™   r�   rš   rž   )rÓ   r¬   r`   Ú_create_storerÚ
infer_axesÚTableIteratorr  Ú
get_result)rÀ   r   r_   r˜   r™   rœ   r�   rš   rž   r°   r  ÚitrF   r  rG   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
        rU   rS   z&can only read_coordinates with a table©r_   r˜   r™   )r`   Ú
get_storerrA   rê   r¦   Úread_coordinates)rÀ   r   r_   r˜   r™   ÚtblrF   rF   rG   Úselect_as_coordinatesm  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  rA   rê   r¦   Úread_column)rÀ   r   r  r˜   r™   r  rF   rF   rG   Ú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u rˆ|d }‡fdd	„|D ƒ‰ˆ 	|¡}
d}t
 |
|fgtˆ|ƒ¡D ]\\}}|du ràtd
|› d�ƒ‚|jsøtd|j› d�ƒ‚|du �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
        rU   rS   r   )r   r_   rœ   r˜   r™   r�   rš   rž   zkeys must be a list/tuplez keys must have a non-zero lengthNc                   s   g | ]}ˆ   |¡‘qS rF   )r  ©rW   ÚkrÃ   rF   rG   r[   ù  rç   z/HDFStore.select_as_multiple.<locals>.<listcomp>zInvalid table [ú]zobject [z>] is not a table, and cannot be used in all select as multiplez,all tables must have exactly the same nrows!c                 S  s   g | ]}t |tƒr|‘qS rF   )rA   rê   ©rW   ÚxrF   rF   rG   r[     rç   c                 S  s   h | ]}|j d  d  ’qS ©r   )Únon_index_axes©rW   rm   rF   rF   rG   Ú	<setcomp>  rç   z.HDFStore.select_as_multiple.<locals>.<setcomp>c                   s*   ‡ ‡‡‡fdd„ˆD ƒ}t |ˆdd� ¡ S )Nc                   s   g | ]}|j ˆˆˆ ˆd �‘qS )©r_   rœ   r˜   r™   rü   r  )rÿ   r   r  rœ   rF   rG   r[     s   ÿz=HDFStore.select_as_multiple.<locals>.func.<locals>.<listcomp>F)ÚaxisÚverify_integrity)r-   Ú_consolidate)rÿ   r   r  Úobjs)r  rœ   Útblsrþ   rG   r    s    þz)HDFStore.select_as_multiple.<locals>.funcr  T©Úcoordinates)r`   rA   r\   r]   r^   rN   r«   r¦   rŸ   r  Ú	itertoolsÚchainÚzipr¬   Úis_tableÚpathnamer  r  r	  )rÀ   rì   r_   Úselectorrœ   r˜   r™   r�   rš   rž   rE   r  rm   r  Z_tblsr  r
  rF   )r  rœ   rÀ   r#  rG   Úselect_as_multipleµ  sd    +
ø
 ÿ


özHDFStore.select_as_multipleTro   rw   r{   r}   )r   r€   r‚   r‡   r‰   rŠ   Útrack_timesrˆ   c                 C  sH   |du rt dƒpd}|  |¡}| j|||||||||	|
||||d� dS )aO  
        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.
        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.

            .. versionadded:: 1.1.0
        Núio.hdf.default_formatrj   )r…   r†   r„   rƒ   r‚   r‡   rŒ   r‰   rL   rŠ   r-  rˆ   )r   Ú_validate_formatÚ_write_to_group)rÀ   r   r€   r…   r†   r„   rƒ   r‚   r‡   rŒ   r‰   rL   rŠ   r-  rˆ   rF   rF   rG   r“   /  s&    0
òzHDFStore.putc              
   C  sâ   t |dd�}z|  |¡}W n† ty.   ‚ Y nt ty@   ‚ Y nb ty  } zJ|dur`tdƒ|‚|  |¡}|durŒ|jdd� W Y d}~dS W Y d}~n
d}~0 0 t 	|||¡rÀ|j
jdd� n|j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

        rU   rS   Nz5trying to remove a node with a non-None where clause!T©Ú	recursivez7can only remove with where on objects written as tablesr  )r`   r  r¬   ÚAssertionErrorÚ	ExceptionrŸ   rÓ   Z	_f_removeÚcomÚall_noner°   r)  Údelete)rÀ   r   r_   r˜   r™   rE   ÚerrrÔ   rF   rF   rG   rÍ   s  s2    ÿþ
$ÿzHDFStore.remover|   )r   r€   r‚   r‡   rˆ   r‰   rŠ   c                 C  sl   |	durt dƒ‚|du r tdƒ}|du r4tdƒp2d}|  |¡}| j|||||||||
|||||||d� dS )a6  
        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.
        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
            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.  rk   )r…   Úaxesr†   r„   rƒ   r‚   r‡   rŒ   rš   Úexpectedrowsrˆ   r‰   rL   rŠ   )r¦   r   r/  r0  )rÀ   r   r€   r…   r9  r†   r„   rƒ   r‚   rœ   r‡   rŒ   rš   r:  rˆ   r‰   rL   rŠ   rF   rF   rG   r„   ¬  s6    8ÿ
ðzHDFStore.appendÚdict)Údc                   s¬  |durt dƒ‚t|tƒs"tdƒ‚||vr2tdƒ‚tttˆjƒƒttt	ˆƒ ƒ ƒd }d}	g }
| 
¡ D ]0\}‰ ˆ du rŽ|	durˆtdƒ‚|}	qh|
 ˆ ¡ qh|	durÖˆj| }| t|
ƒ¡}t| |¡ƒ}| |¡||	< |du ræ|| }|�r*‡fdd„| ¡ D ƒ}t|ƒ}|D ]}| |¡}�qˆj| ‰| d	d¡}| 
¡ D ]h\}‰ ||k�rT|nd}ˆjˆ |d
�}|du�r†‡ fdd„| 
¡ D ƒnd}| j||f||dœ|¤Ž �q>dS )a  
        Append to multiple tables

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

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

        Nztaxes is currently not accepted as a parameter to append_to_multiple; you can create the tables independently insteadzQappend_to_multiple must have a dictionary specified as the way to split the valuez=append_to_multiple requires a selector that is in passed 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†   )rW   Úcols)r€   rF   rG   Ú	<genexpr>L  rç   z.HDFStore.append_to_multiple.<locals>.<genexpr>r‡   ©r  c                   s   i | ]\}}|ˆ v r||“qS rF   rF   ©rW   r   r€   )ÚvrF   rG   Ú
<dictcomp>\  rç   z/HDFStore.append_to_multiple.<locals>.<dictcomp>)r‰   r‡   )r¦   rA   r;  rŸ   r\   ÚsetÚrangeÚndimÚ	_AXES_MAPrÐ   rð   Úextendr9  Ú
differencer(   ÚsortedÚget_indexerÚtakeÚvaluesÚnextÚintersectionÚlocÚpopÚreindexr„   )rÀ   r<  r€   r+  r‰   r9  rˆ   r®   r  Z
remain_keyZremain_valuesr  ÚorderedZorddZidxsZvalid_indexr†   r‡   ÚdcÚvalÚfilteredrF   )rC  r€   rG   Úappend_to_multiple  sZ    ÿ
ÿÿ&ÿ

ÿýzHDFStore.append_to_multiplery   )r   ÚoptlevelÚkindc                 C  sB   t ƒ  |  |¡}|du rdS t|tƒs.tdƒ‚|j|||d� dS )aà  
        Create a pytables index on the table.

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

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

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

        Raises
        ------
        TypeError: raises if the node is not a table
        Nz1cannot create table index on a Fixed format store)rœ   rY  rZ  )ru   r  rA   rê   r¦   Úcreate_index)rÀ   r   rœ   rY  rZ  rE   rF   rF   rG   Úcreate_table_indexb  s    

zHDFStore.create_table_indexc                 C  s<   t ƒ  |  ¡  | jdusJ ‚tdus(J ‚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_typeNrk   )	rA   rp   ÚlinkÚLinkÚgetattrÚ_v_attrsrk   rê   r³   )rW   rï   rF   rF   rG   r[   ™  s   ùz#HDFStore.groups.<locals>.<listcomp>)ru   rÅ   r¶   rp   Úwalk_groupsrÃ   rF   rF   rG   r¨   Š  s    þzHDFStore.groupsré   c                 c  s¼   t ƒ  |  ¡  | jdusJ ‚tdus(J ‚| j |¡D ]‚}t|jddƒdurLq4g }g }|j ¡ D ]B}t|jddƒ}|du 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`.
        Nr]  ré   )ru   rÅ   r¶   rp   rb  r`  ra  Z_v_childrenrN  rA   r°   ÚGroupr„   r³   rª   Úrstrip)rÀ   r_   rï   r¨   ÚleavesÚchildr]  rF   rF   rG   Úwalk¦  s     zHDFStore.walkzNode | Nonec                 C  s~   |   ¡  | d¡sd| }| jdus(J ‚tdus4J ‚z| j | j|¡}W n tjjy`   Y dS 0 t|tj	ƒszJ t
|ƒƒ‚|S )z9return the node with the key or None if it does not existré   N)rÅ   Ú
startswithr¶   rp   rÓ   rÆ   Ú
exceptionsZNoSuchNodeErrorrA   r>   rÐ   )rÀ   r   rÔ   rF   rF   rG   rÓ   Ö  s    
zHDFStore.get_nodeúGenericFixed | Tablec                 C  s8   |   |¡}|du r"td|› d�ƒ‚|  |¡}| ¡  |S )z<return the storer object for a key, raise if not in the fileNrø   rù   )rÓ   r¬   r  r  )rÀ   r   r°   rE   rF   rF   rG   r  æ  s    

zHDFStore.get_storerrñ   )Úpropindexesr‚   rº   c	              	   C  sÎ   t |||||d�}	|du r&t|  ¡ ƒ}t|ttfƒs:|g}|D ]Š}
|  |
¡}|dur>|
|	v 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 rF   )Ú
is_indexedrP   ©rW   rv   rF   rF   rG   r[      rç   z!HDFStore.copy.<locals>.<listcomp>r‰   )r†   r‰   rL   rK   )r”   r\   rì   rA   r]   r  rÍ   r«   rê   r9  r„   r`  rL   r“   )rÀ   rs   r�   rk  rì   rƒ   r‚   rº   Ú	overwriteZ	new_storer  rE   Údatar†   rF   rF   rG   Úcopyð  s6    
ÿ




ûzHDFStore.copyc           
      C  s
  t | jƒ}t| ƒ› d|› d�}| jrþt|  ¡ ƒ}t|ƒrôg }g }|D ]œ}z<|  |¡}|dur‚| t |j	pj|ƒ¡ | t |p|dƒ¡ W qD t
y˜   ‚ Y qD tyÞ } z0| |¡ t |ƒ}	| d|	› d�¡ W Y d}~qDd}~0 0 qD|td||ƒ7 }n|d7 }n|d	7 }|S )
zg
        Print detailed information on the store.

        Returns
        -------
        str
        rØ   rÙ   Nzinvalid_HDFStore nodez[invalid_HDFStore node: r  é   ÚEmptyzFile is CLOSED)r;   r¼   rÐ   r    rK  rì   r^   r  r„   r*  r3  r4  r:   )
rÀ   r¤   ÚoutputZlkeysrì   rN  r  rE   ZdetailZdstrrF   rF   rG   Úinfo-  s.    


*
zHDFStore.infoc                 C  s   | j st| j› d�ƒ‚d S )Nz file is not open!)r    rf   r¼   rÃ   rF   rF   rG   rÅ   W  s    zHDFStore._check_if_open)r…   r‹   c              
   C  sL   zt | ¡  }W n6 tyF } ztd|› d�ƒ|‚W Y d}~n
d}~0 0 |S )zvalidate / deprecate formatsz#invalid HDFStore format specified [r  N)Ú_FORMAT_MAPÚlowerr¬   r¦   )rÀ   r…   r8  rF   rF   rG   r/  [  s
    (zHDFStore._validate_formatr@   zDataFrame | Series | None)r€   rL   rŠ   r‹   c              
     s"  ˆdurt ˆttfƒstdƒ‚‡ ‡‡fdd„}ttˆjddƒƒ}ttˆjddƒƒ}|du rÆˆdu r¢tƒ  tdustJ ‚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|v�r(ttdœ}	z|	| }
W n0 t�y } z|dƒ|‚W Y d}~n
d}~0 0 |
| ˆ||d�S |du �rÂˆdu�rÂ|dk�r€tˆddƒ}|du�rÂ|jdk�rnd}n|jdk�rÂd}nB|dk�rÂtˆddƒ}|du�rÂ|jdk�r²d}n|jdk�rÂd}ttttttdœ}z|| }
W n0 t�y } z|dƒ|‚W Y d}~n
d}~0 0 |
| ˆ||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Ð   )rm   ©r…   r°   r€   rF   rG   Úerrors  s    ÿÿÿÿz&HDFStore._create_storer.<locals>.errorr]  Ú
table_typerk   Ú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©rL   rŠ   Úseries_tabler†   rU   Úappendable_seriesÚappendable_multiseriesÚappendable_frameÚappendable_multiframe)r|  rƒ  r„  r…  r†  ÚwormÚ
_TABLE_MAP)rA   r+   r&   r¦   rH   r`  ra  ru   rp   rk   rê   ÚSeriesFixedÚ
FrameFixedr¬   ÚnlevelsÚGenericTableÚAppendableSeriesTableÚAppendableMultiSeriesTableÚAppendableFrameTableÚAppendableMultiFrameTableÚ	WORMTable)rÀ   r°   r…   r€   rL   rŠ   ry  ÚptÚttr€  Úclsr8  r†   rˆ  rF   rx  rG   r  e  sr    ÿÿ


 





ú zHDFStore._create_storerr~   )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Úemptyrk   r�  rj   zCan only append to Tablesz0Compression not supported on Fixed format stores)Úobjr9  r„   rƒ   r‚   rº   r‡   rš   r:  rˆ   rŒ   r‰   r-  )rœ   )r`  Ú_identify_groupr  r)  Ú	is_existsrŸ   Úset_object_infoÚwriterA   rê   r[  )rÀ   r   r€   r…   r9  r†   r„   rƒ   r‚   rº   r‡   rš   r:  rˆ   rŒ   r‰   rL   rŠ   r-  r°   rE   rF   rF   rG   r0  Á  s:    

ózHDFStore._write_to_groupr>   ©r°   c                 C  s   |   |¡}| ¡  | ¡ S rI   )r  r  rý   )rÀ   r°   rE   rF   rF   rG   rú   ÿ  s    
zHDFStore._read_group)r   r„   r‹   c                 C  sN   |   |¡}| jdusJ ‚|dur8|s8| jj|dd� d}|du rJ|  |¡}|S )z@Identify HDF5 group based on key, delete/create group if needed.NTr1  )rÓ   r¶   Úremove_nodeÚ_create_nodes_and_group)rÀ   r   r„   r°   rF   rF   rG   r—    s    

zHDFStore._identify_groupc                 C  sv   | j dusJ ‚| d¡}d}|D ]P}t|ƒs.q |}| d¡sD|d7 }||7 }|  |¡}|du rl| j  ||¡}|}q |S )z,Create nodes from key and return group name.Nré   )r¶   Úsplitr^   ÚendswithrÓ   Zcreate_group)rÀ   r   Úpathsr¤   ÚpÚnew_pathr°   rF   rF   rG   r�    s    


z HDFStore._create_nodes_and_group)rv   NNF)rá   )rv   )F)NNNNFNF)NNN)NN)NNNNNFNF)NTFNNNNNNro   TF)NNN)NNTTNNNNNNNNNNro   )NNF)NNN)ré   )rñ   TNNNFT)NNr@   ro   )NTFNNNNNNFNNNro   T)2rc   rd   re   Ú__doc__Ú__annotations__rÁ   rÄ   ÚpropertyrÆ   rÇ   rË   rÌ   rÎ   rÑ   rÕ   r×   rÛ   rÜ   rà   rì   rî   rð   Ú	iteritemsr¿   r­   r    rö   rÉ   r«   r  r  r,  r“   rÍ   r„   rX  r\  r¨   rg  rÓ   r  rp  rt  rÅ   r/  r  r0  rú   r—  r�  rF   rF   rF   rG   r”   è  s  
A    ú"


"-       ÷N   û$  û+        ö~            ñD=               îZ   ùd   û(
0       ÷=*    úa               í>r”   c                   @  sb   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„Zdd„ Z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.
    rx   rš   r”   r�   rj  rE   NFrz   )r�   rE   r�   rš   rž   c                 C  sš   || _ || _|| _|| _| jjrN|d u r,d}|d u r8d}|d u rD|}t||ƒ}|| _|| _|| _d | _	|sr|	d urŠ|	d u r~d}	t
|	ƒ| _nd | _|
| _d S )Nr   é † )r�   rE   r  r_   r)  Úminr  r˜   r™   r%  rR   rš   rž   )rÀ   r�   rE   r  r_   r  r˜   r™   r�   rš   rž   rF   rF   rG   rÁ   D  s,    
zTableIterator.__init__c                 c  sv   | j }| jd u rtdƒ‚|| jk rjt|| j | jƒ}|  d d | j||… ¡}|}|d u st|ƒsbq|V  q|  ¡  d S )Nz*Cannot iterate until get_result is called.)	r˜   r%  rŸ   r™   r¨  rš   r  r^   r­   )rÀ   r´   r™   r€   rF   rF   rG   rî   n  s    

zTableIterator.__iter__c                 C  s   | j r| j ¡  d S rI   )rž   r�   r­   rÃ   rF   rF   rG   r­   ~  s    zTableIterator.closer$  c                 C  sŠ   | j d ur4t| jtƒstdƒ‚| jj| jd�| _| S |rft| jtƒsLtdƒ‚| jj| j| j| j	d�}n| j}|  
| j| j	|¡}|  ¡  |S )Nz0can only use an iterator or chunksize on a table)r_   z$can only read_coordinates on a tabler  )rš   rA   rE   rê   r¦   r  r_   r%  r˜   r™   r  r­   )rÀ   r%  r_   ÚresultsrF   rF   rG   r	  ‚  s    
ÿzTableIterator.get_result)NNFNF)F)	rc   rd   re   r£  r¤  rÁ   rî   r­   r	  rF   rF   rF   rG   r  ,  s   
	     õ*r  c                   @  st  e Zd ZU dZdZdZg d¢Zded< ded< dHddd	œd
d„Ze	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d„Zddœdd„Ze	ddœdd„ƒZd ddd!œd"d#„Zd$d%„ Ze	d&d'„ ƒZe	d(d)„ ƒZe	d*d+„ ƒZe	d,d-„ ƒZd.d/„ ZdId0d1„Zd2d3„ Zd4dd5œd6d7„ZdJd8d9„Zdd:œd;d<„Zd=d>„ Zd?d@„ ZdAdB„ Zd4dCœdDdE„Z d4dCœdFdG„Z!dS )KÚ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

    T)ÚfreqÚtzÚ
index_namerN   rP   ÚcnameNry   )rP   r®  c                 C  s    t |tƒstdƒ‚|| _|| _|| _|| _|p0|| _|| _|| _	|| _
|	| _|
| _|| _|| _|| _|| _|d ur||  |¡ t | jtƒsŒJ ‚t | jtƒsœJ ‚d S )Nz`name` must be a str.)rA   rN   rŸ   rN  rZ  ÚtyprP   r®  r  Úposr«  r¬  r­  rT  rk   r²   ÚmetadataÚset_pos)rÀ   rP   rN  rZ  r¯  r®  r  r°  r«  r¬  r­  rT  rk   r²   r±  rF   rF   rG   rÁ   ±  s(    


zIndexCol.__init__rR   rÖ   c                 C  s   | j jS rI   )r¯  ÚitemsizerÃ   rF   rF   rG   r³  Ý  s    zIndexCol.itemsizec                 C  s   | j › d�S )NÚ_kindrO   rÃ   rF   rF   rG   Ú	kind_attrâ  s    zIndexCol.kind_attr)r°  c                 C  s$   || _ |dur | jdur || j_dS )z,set the position of this column in the TableN)r°  r¯  Z_v_pos)rÀ   r°  rF   rF   rG   r²  æ  s    zIndexCol.set_posc                 C  s@   t tt| j| j| j| j| jfƒƒ}d dd„ t	g d¢|ƒD ƒ¡S )Nú,c                 S  s   g | ]\}}|› d |› �‘qS ©z->rF   rB  rF   rF   rG   r[   ñ  s   ÿz%IndexCol.__repr__.<locals>.<listcomp>)rP   r®  r  r°  rZ  )
r]   Úmapr;   rP   r®  r  r°  rZ  Újoinr(  ©rÀ   ÚtemprF   rF   rG   rÛ   ì  s    ÿþÿzIndexCol.__repr__r   rz   ©Ú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 rI   ©r`  rm  ©r½  rÀ   rF   rG   r@  ù  s   ÿz"IndexCol.__eq__.<locals>.<genexpr>)rP   r®  r  r°  ©r=  ©rÀ   r½  rF   rÀ  rG   Ú__eq__÷  s    þzIndexCol.__eq__c                 C  s   |   |¡ S rI   )rÃ  rÂ  rF   rF   rG   Ú__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 columnr?  F)Úhasattrrk   r`  r?  r®  rl  rÃ   rF   rF   rG   rl    s    zIndexCol.is_indexedú
np.ndarray©rN  rL   rŠ   c           
      C  s  t |tjƒsJ t|ƒƒ‚|jjdur.|| j }t| jƒ}t	||||ƒ}i }t| j
ƒ|d< | jdurpt| jƒ|d< t}t|jƒsˆt|jƒrŽt}n|jdkr¨d|v r¨dd„ }z||fi |¤Ž}W n2 tyî   d|v rÚd|d< ||fi |¤Ž}Y n0 t|| jƒ}	|	|	fS )zV
        Convert the data from this selection to the appropriate pandas type.
        NrP   r«  Úi8c                 [  s   t f d| i|¤ŽS )NZordinal)r*   )r  ÚkwdsrF   rF   rG   r‘   $  s   ÿÿz"IndexCol.convert.<locals>.<lambda>)rA   rB   ÚndarrayrÐ   ÚdtypeÚfieldsr®  rH   rZ  Ú_maybe_convertr­  r«  r(   r   r   r'   rŸ   Ú_set_tzr¬  )
rÀ   rN  rŒ   rL   rŠ   Úval_kindr®   ÚfactoryZnew_pd_indexZfinal_pd_indexrF   rF   rG   Úconvert	  s,    


zIndexCol.convertc                 C  s   | j S )zreturn the values©rN  rÃ   rF   rF   rG   Ú	take_data4  s    zIndexCol.take_datac                 C  s   | j jS rI   )rk   ra  rÃ   rF   rF   rG   Úattrs8  s    zIndexCol.attrsc                 C  s   | j jS rI   ©rk   ÚdescriptionrÃ   rF   rF   rG   rÖ  <  s    zIndexCol.descriptionc                 C  s   t | j| jdƒS )z!return my current col descriptionN)r`  rÖ  r®  rÃ   rF   rF   rG   Úcol@  s    zIndexCol.colc                 C  s   | j S ©zreturn my cython valuesrÒ  rÃ   rF   rF   rG   ÚcvaluesE  s    zIndexCol.cvaluesc                 C  s
   t | jƒS rI   )rí   rN  rÃ   rF   rF   rG   rî   J  s    zIndexCol.__iter__c                 C  sP   t | jƒdkrLt|tƒr$| | j¡}|durL| jj|k rLtƒ j	|| j
d�| _dS )zŸ
        maybe set a string col itemsize:
            min_itemsize can be an integer or a dict with this columns name
            with an integer size
        ÚstringN)r³  r°  )rH   rZ  rA   r;  rÉ   rP   r¯  r³  ru   Ú	StringColr°  )rÀ   r‡   rF   rF   rG   Úmaybe_set_sizeM  s
    
zIndexCol.maybe_set_sizec                 C  s   d S rI   rF   rÃ   rF   rF   rG   Úvalidate_namesZ  s    zIndexCol.validate_namesÚAppendableTable)Úhandlerr„   c                 C  s:   |j | _ |  ¡  |  |¡ |  |¡ |  |¡ |  ¡  d S rI   )rk   Úvalidate_colÚvalidate_attrÚvalidate_metadataÚwrite_metadataÚset_attr)rÀ   rß  r„   rF   rF   rG   Úvalidate_and_set]  s    


zIndexCol.validate_and_setc                 C  s^   t | jƒdkrZ| j}|durZ|du r*| j}|j|k rTtd|› d| j› d|j› d�ƒ‚|jS dS )z:validate this column: return the compared against itemsizerÚ  Nz#Trying to store a string with len [z] in [z)] column but
this column has a limit of [zC]!
Consider using min_itemsize to preset the sizes on these columns)rH   rZ  r×  r³  rŸ   r®  )rÀ   r³  ÚcrF   rF   rG   rà  e  s    
ÿþÿzIndexCol.validate_colr�   c                 C  sB   |r>t | j| jd ƒ}|d ur>|| jkr>td|› d| j› d�ƒ‚d S )Nzincompatible kind in col [ú - r  )r`  rÔ  rµ  rZ  r¦   )rÀ   r„   Zexisting_kindrF   rF   rG   rá  x  s    ÿzIndexCol.validate_attrc                 C  sÈ   | j D ]¼}t| |dƒ}| | ji ¡}| |¡}||v rª|durª||krª|dv r„t|||f }tj|tt	ƒ d� d||< t
| |dƒ qÂtd| j› d|› d|› d|› d�	ƒ‚q|dusº|dur|||< qdS )	z
        set/update the info for this indexable with the key/value
        if there is a conflict raise/warn as needed
        N)r«  r­  ©Ú
stacklevelzinvalid info for [z] for [z], existing_value [z] conflicts with new value [r  )Ú_info_fieldsr`  Ú
setdefaultrP   rÉ   Úattribute_conflict_docÚwarningsÚwarnrh   r   ÚsetattrrŸ   )rÀ   rt  r   r€   ÚidxZexisting_valueÚwsrF   rF   rG   Úupdate_info�  s*    

ÿÿþÿzIndexCol.update_infoc                 C  s$   |  | j¡}|dur | j |¡ dS )z!set my state from the passed infoN)rÉ   rP   Ú__dict__Úupdate)rÀ   rt  rð  rF   rF   rG   Ú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µ  rZ  rÃ   rF   rF   rG   rä  ¨  s    zIndexCol.set_attr)rß  c                 C  sB   | j dkr>| j}| | j¡}|dur>|du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_metadatarF   rF   rG   râ  ¬  s    
ÿþýÿzIndexCol.validate_metadatac                 C  s   | j dur| | j| j ¡ dS )zset the meta dataN)r±  rã  r®  )rÀ   rß  rF   rF   rG   rã  »  s    
zIndexCol.write_metadata)NNNNNNNNNNNNN)N)N)"rc   rd   re   r£  Úis_an_indexableÚis_data_indexablerê  r¤  rÁ   r¥  r³  rµ  r²  rÛ   rÃ  rÄ  rl  rÑ  rÓ  rÔ  rÖ  r×  rÙ  rî   rÜ  rÝ  rå  rà  rá  rò  rõ  rä  râ  rã  rF   rF   rF   rG   rª  œ  sf   
             ñ,+





	!rª  c                   @  s<   e Zd ZdZeddœdd„ƒZddddœd	d
„Zdd„ ZdS )ÚGenericIndexColz:an index which is not represented in the data of the tablerz   rÖ   c                 C  s   dS ©NFrF   rÃ   rF   rF   rG   rl  Ä  s    zGenericIndexCol.is_indexedrÆ  rN   rÇ  c                 C  s2   t |tjƒsJ 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
        )rA   rB   rÊ  rÐ   r/   Úaranger^   )rÀ   rN  rŒ   rL   rŠ   rF   rF   rG   rÑ  È  s    zGenericIndexCol.convertc                 C  s   d S rI   rF   rÃ   rF   rF   rG   rä  Ú  s    zGenericIndexCol.set_attrN)rc   rd   re   r£  r¥  rl  rÑ  rä  rF   rF   rF   rG   rú  Á  s
   rú  c                      s,  e Zd ZdZdZdZddgZd9d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„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d/d0„ ƒZd1d2„ Zd3ddd4œd5d6„Zd7d8„ 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¬  rT  NrN   zDtypeArg | None)rP   rË  c                   s2   t ƒ j|||||||||	|
|d� || _|| _d S )N)rP   rN  rZ  r¯  r°  r®  r¬  rT  rk   r²   r±  )ÚsuperrÁ   rË  ro  )rÀ   rP   rN  rZ  r¯  r®  r°  r¬  rT  rk   r²   r±  rË  ro  ©Ú	__class__rF   rG   rÁ   ï  s    õzDataCol.__init__rÖ   c                 C  s   | j › d�S )NÚ_dtyperO   rÃ   rF   rF   rG   Ú
dtype_attr	  s    zDataCol.dtype_attrc                 C  s   | j › d�S )NÚ_metarO   rÃ   rF   rF   rG   Ú	meta_attr	  s    zDataCol.meta_attrc                 C  s@   t tt| j| j| j| j| jfƒƒ}d dd„ t	g d¢|ƒD ƒ¡S )Nr¶  c                 S  s   g | ]\}}|› d |› �‘qS r·  rF   rB  rF   rF   rG   r[   	  s   ÿz$DataCol.__repr__.<locals>.<listcomp>)rP   r®  rË  rZ  Úshape)
r]   r¸  r;   rP   r®  rË  rZ  r  r¹  r(  rº  rF   rF   rG   rÛ   	  s    ÿÿþÿzDataCol.__repr__r   rz   r¼  c                   s   t ‡ ‡fdd„dD ƒƒS )r¾  c                 3  s&   | ]}t ˆ|d ƒt ˆ |d ƒkV  qd S rI   r¿  rm  rÀ  rF   rG   r@  &	  s   ÿz!DataCol.__eq__.<locals>.<genexpr>)rP   r®  rË  r°  rÁ  rÂ  rF   rÀ  rG   rÃ  $	  s    þzDataCol.__eq__r   ©ro  c                 C  s@   |d usJ ‚| j d u sJ ‚t|ƒ\}}|| _|| _ t|ƒ| _d S rI   )rË  Ú_get_data_and_dtype_namero  Ú_dtype_to_kindrZ  )rÀ   ro  Ú
dtype_namerF   rF   rG   Úset_data+	  s    zDataCol.set_datac                 C  s   | j S )zreturn the datar  rÃ   rF   rF   rG   rÓ  5	  s    zDataCol.take_datar<   )rN  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.
        rU   ©rZ  r   ©r³  r  )rË  r³  r  rG  ÚsizerA   r0   ÚcodesÚget_atom_datarP   r   r   Úget_atom_datetime64r#   Úget_atom_timedelta64r   ru   Z
ComplexColr"   Úget_atom_string)r”  rN  rË  r³  r  r  ÚatomrF   rF   rG   Ú	_get_atom9	  s$    


zDataCol._get_atomc                 C  s   t ƒ j||d d�S )Nr   r  ©ru   rÛ  ©r”  r  r³  rF   rF   rG   r  Y	  s    zDataCol.get_atom_stringz	type[Col]©rZ  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UIntr<   ÚperiodÚInt64Col)rh  Ú
capitalizer`  ru   )r”  rZ  Zk4Zcol_nameZkcaprF   rF   rG   Úget_atom_coltype]	  s    


zDataCol.get_atom_coltypec                 C  s   | j |d�|d d�S )Nr  r   ©r  ©r  ©r”  r  rZ  rF   rF   rG   r  l	  s    zDataCol.get_atom_datac                 C  s   t ƒ j|d d�S ©Nr   r  ©ru   r  ©r”  r  rF   rF   rG   r  p	  s    zDataCol.get_atom_datetime64c                 C  s   t ƒ j|d d�S r!  r"  r#  rF   rF   rG   r  t	  s    zDataCol.get_atom_timedelta64c                 C  s   t | jdd ƒS )Nr  )r`  ro  rÃ   rF   rF   rG   r  x	  s    zDataCol.shapec                 C  s   | j S rØ  r  rÃ   rF   rF   rG   rÙ  |	  s    zDataCol.cvaluesc                 C  s`   |r\t | j| jdƒ}|dur2|t| jƒkr2tdƒ‚t | j| jdƒ}|dur\|| jkr\tdƒ‚dS )zAvalidate that we have the same order as the existing & same dtypeNz4appended items do not match existing items in table!z@appended items dtype do not match existing items dtype in table!)r`  rÔ  rµ  r\   rN  rŸ   r  rË  )rÀ   r„   Zexisting_fieldsZexisting_dtyperF   rF   rG   rá  �	  s    ÿzDataCol.validate_attrrÆ  rÇ  c                 C  s  t |tjƒsJ t|ƒƒ‚|jjdur.|| j }| jdus<J ‚| jdu r\t|ƒ\}}t	|ƒ}n|}| j}| j
}t |tjƒs|J ‚t| jƒ}| j}	| j}
| j}|dus¤J ‚t|ƒ}|dkrÆt||dd�}�n$|dkràtj|dd�}�n
|dk�r6ztjd	d
„ |D ƒtd�}W n, t�y2   tjdd
„ |D ƒtd�}Y n0 n´|dk�r´|	}| ¡ }|du �rftg tjd�}n<t|ƒ}| ¡ �r¢||  }||dk  | t¡ ¡ j8  < tj|||
d�}n6z|j|dd�}W n" t�yè   |jddd�}Y n0 t|ƒdk�rt ||||d�}| j!|fS )aR  
        Convert the data from this selection to the appropriate pandas type.

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

        Returns
        -------
        index : listlike to become an Index
        data : ndarraylike to become a column
        NÚ
datetime64T©ÚcoerceÚtimedelta64úm8[ns]©rË  r   c                 S  s   g | ]}t  |¡‘qS rF   ©r   Úfromordinal©rW   rC  rF   rF   rG   r[   Å	  rç   z#DataCol.convert.<locals>.<listcomp>c                 S  s   g | ]}t  |¡‘qS rF   ©r   Úfromtimestampr,  rF   rF   rG   r[   É	  rç   rö  éÿÿÿÿ)Ú
categoriesrT  F©rp  ÚOrÚ  ©rŒ   rL   rŠ   )"rA   rB   rÊ  rÐ   rË  rÌ  r®  r¯  r  r  rZ  rH   r²   r±  rT  r¬  rÎ  ÚasarrayÚobjectrŸ   Úravelr(   Zfloat64r.   ÚanyÚastyperR   ZcumsumÚ_valuesr0   Z
from_codesr¦   Ú_unconvert_string_arrayrN  )rÀ   rN  rŒ   rL   rŠ   Ú	convertedr	  rZ  r²   r±  rT  r¬  rË  r0  r  ÚmaskrF   rF   rG   rÑ  Ž	  sf    




ÿ
ÿ



 ÿÿzDataCol.convertc                 C  sH   t | j| j| jƒ t | j| j| jƒ | jdus2J ‚t | j| j| jƒ dS )zset the data for this columnN)rï  rÔ  rµ  rN  r  r²   rË  r  rÃ   rF   rF   rG   rä  ó	  s    zDataCol.set_attr)NNNNNNNNNNNN)rc   rd   re   r£  rø  rù  rê  rÁ   r¥  r  r  rÛ   rÃ  r
  rÓ  Úclassmethodr  r  r  r  r  r  r  rÙ  rá  rÑ  rä  Ú__classcell__rF   rF   rÿ  rG   rý  Þ  sX               ò 





erý  c                   @  sT   e Zd ZdZdZ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 indexedTc                 C  s   t | jƒ ¡ stdƒ‚d S )Nú-cannot have non-object label DataIndexableCol)r(   rN  Z	is_objectrŸ   rÃ   rF   rF   rG   rÝ   
  s    zDataIndexableCol.validate_namesc                 C  s   t ƒ j|d�S )N)r³  r  r  rF   rF   rG   r  
  s    z DataIndexableCol.get_atom_stringrN   r<   r  c                 C  s   | j |d�ƒ S )Nr  r  r   rF   rF   rG   r  	
  s    zDataIndexableCol.get_atom_datac                 C  s
   t ƒ  ¡ S rI   r"  r#  rF   rF   rG   r  
  s    z$DataIndexableCol.get_atom_datetime64c                 C  s
   t ƒ  ¡ S rI   r"  r#  rF   rF   rG   r  
  s    z%DataIndexableCol.get_atom_timedelta64N)rc   rd   re   r£  rù  rÝ  r=  r  r  r  r  rF   rF   rF   rG   r?  û	  s   

r?  c                   @  s   e Zd ZdZdS )ÚGenericDataIndexableColz(represent a generic pytables data columnN)rc   rd   re   r£  rF   rF   rF   rG   rA  
  s   rA  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dLd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"„ Zd#d$„ Zed%d&„ ƒZed'd(„ ƒZed)d*„ ƒZed+d,„ ƒZeddœd-d.„ƒZeddœd/d0„ƒZed1d2„ ƒZd3d4„ Zd5d6„ Zed7d8„ ƒZeddœd9d:„ƒZed;d<„ ƒZd=d>„ ZdMd@dA„ZdBdC„ ZdNdDdDdEœdFdG„ZdHdI„ ZdOdDdDdEœdJdK„Z d?S )PÚ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.
    rN   Úpandas_kindrj   Úformat_typeútype[DataFrame | Series]Úobj_typerR   rG  rL   r”   rµ   r>   r°   rŠ   Fr@   ro   )rµ   r°   rL   rŠ   c                 C  sZ   t |tƒsJ t|ƒƒ‚td us"J ‚t |tjƒs:J t|ƒƒ‚|| _|| _t|ƒ| _|| _	d S rI   )
rA   r”   rÐ   rp   r>   rµ   r°   rM   rL   rŠ   )rÀ   rµ   r°   rL   rŠ   rF   rF   rG   rÁ   3
  s    
zFixed.__init__rz   rÖ   c                 C  s*   | j d dko(| j d dko(| j d dk S )Nr   rU   é
   é   )ÚversionrÃ   rF   rF   rG   Úis_old_versionB
  s    zFixed.is_old_versionztuple[int, int, int]c                 C  s`   t t| jjddƒƒ}z0tdd„ | d¡D ƒƒ}t|ƒdkrB|d }W n tyZ   d}Y n0 |S )	zcompute and set our versionÚpandas_versionNc                 s  s   | ]}t |ƒV  qd S rI   ©rR   r  rF   rF   rG   r@  K
  rç   z Fixed.version.<locals>.<genexpr>Ú.rH  r  )r   r   r   )rH   r`  r°   ra  r]   rž  r^   rr   )rÀ   rI  rF   rF   rG   rI  F
  s    
zFixed.versionc                 C  s   t t| jjdd ƒƒS )Nr]  )rH   r`  r°   ra  rÃ   rF   rF   rG   r]  R
  s    zFixed.pandas_typec                 C  s^   |   ¡  | j}|durXt|ttfƒrDd dd„ |D ƒ¡}d|› d�}| jd›d|› d	�S | jS )
ú(return a pretty representation of myselfNr¶  c                 S  s   g | ]}t |ƒ‘qS rF   ©r;   r  rF   rF   rG   r[   \
  rç   z"Fixed.__repr__.<locals>.<listcomp>ú[r  ú12.12z	 (shape->ú))r  r  rA   r\   r]   r¹  r]  )rÀ   rE   ZjshaperF   rF   rG   rÛ   V
  s    zFixed.__repr__c                 C  s   t | jƒ| j_t tƒ| j_dS )zset my pandas type & versionN)rN   rC  rÔ  r]  Ú_versionrK  rÃ   rF   rF   rG   r™  a
  s    zFixed.set_object_infoc                 C  s   t   | ¡}|S rI   r1  )rÀ   Znew_selfrF   rF   rG   rp  f
  s    
z
Fixed.copyc                 C  s   | j S rI   )r  rÃ   rF   rF   rG   r  j
  s    zFixed.shapec                 C  s   | j jS rI   ©r°   rª   rÃ   rF   rF   rG   r*  n
  s    zFixed.pathnamec                 C  s   | j jS rI   )rµ   r¶   rÃ   rF   rF   rG   r¶   r
  s    zFixed._handlec                 C  s   | j jS rI   )rµ   r¾   rÃ   rF   rF   rG   r¾   v
  s    zFixed._filtersc                 C  s   | j jS rI   )rµ   r¸   rÃ   rF   rF   rG   r¸   z
  s    zFixed._complevelc                 C  s   | j jS rI   )rµ   r¹   rÃ   rF   rF   rG   r¹   ~
  s    zFixed._fletcher32c                 C  s   | j jS rI   )r°   ra  rÃ   rF   rF   rG   rÔ  ‚
  s    zFixed.attrsc                 C  s   dS ©zset our object attributesNrF   rÃ   rF   rF   rG   Ú	set_attrs†
  s    zFixed.set_attrsc                 C  s   dS )zget our object attributesNrF   rÃ   rF   rF   rG   Ú	get_attrsŠ
  s    zFixed.get_attrsc                 C  s   | j S )zreturn my storabler›  rÃ   rF   rF   rG   ÚstorableŽ
  s    zFixed.storablec                 C  s   dS rû  rF   rÃ   rF   rF   rG   r˜  “
  s    zFixed.is_existsc                 C  s   t | jdd ƒS )Nr  )r`  rX  rÃ   rF   rF   rG   r  —
  s    zFixed.nrowsc                 C  s   |du rdS dS )z%validate against an existing storableNTrF   rÂ  rF   rF   rG   Úvalidate›
  s    zFixed.validateNc                 C  s   dS )ú+are we trying to operate on an old version?TrF   )rÀ   r_   rF   rF   rG   Úvalidate_version¡
  s    zFixed.validate_versionc                 C  s   | j }|du rdS |  ¡  dS )zr
        infer the axes of my storer
        return a boolean indicating if we have a valid storer or not
        NFT)rX  rW  )rÀ   rE   rF   rF   rG   r  ¥
  s
    zFixed.infer_axesrx   ©r˜   r™   c                 C  s   t dƒ‚d S )Nz>cannot read on an abstract storer: subclasses should implement©r¢   ©rÀ   r_   rœ   r˜   r™   rF   rF   rG   rý   °
  s    ÿz
Fixed.readc                 K  s   t dƒ‚d S )Nz?cannot write on an abstract storer: subclasses should implementr]  ©rÀ   r®   rF   rF   rG   rš  »
  s    ÿzFixed.writec                 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
        Tr1  Nz#cannot delete on an abstract storer)r5  r6  r¶   rœ  r°   r¦   )rÀ   r_   r˜   r™   rF   rF   rG   r7  À
  s    zFixed.delete)r@   ro   )N)NNNN)NNN)!rc   rd   re   r£  r¤  rD  r)  rÁ   r¥  rJ  rI  r]  rÛ   r™  rp  r  r*  r¶   r¾   r¸   r¹   rÔ  rV  rW  rX  r˜  r  rY  r[  r  rý   rš  r7  rF   rF   rF   rG   rB  
  sl   
  û








    ûrB  c                   @  s(  e Zd ZU dZedediZdd„ e ¡ D ƒZg Z	de
d< dd	œd
d„Zdd„ Zdd„ Zdd„ Zedd	œdd„ƒZdd„ Zdd„ Z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&„Zdd'd$œd(d)„Zd<dddd'd!œd*d+„Zd=d,ddd d-œd.d/„Zdd0d1œd2d3„Zd>dd4d5d6d7œd8d9„ZdS )?ÚGenericFixedza generified fixed versionÚdatetimer  c                 C  s   i | ]\}}||“qS rF   rF   )rW   r  rC  rF   rF   rG   rD  Ð
  rç   zGenericFixed.<dictcomp>râ   Ú
attributesrN   rÖ   c                 C  s   | j  |d¡S )NÚ )Ú_index_type_maprÉ   )rÀ   r”  rF   rF   rG   Ú_class_to_aliasÔ
  s    zGenericFixed._class_to_aliasc                 C  s   t |tƒr|S | j |t¡S rI   )rA   rÐ   Ú_reverse_index_maprÉ   r(   )rÀ   ÚaliasrF   rF   rG   Ú_alias_to_class×
  s    
zGenericFixed._alias_to_classc                 C  s¸   |   tt|ddƒƒ¡}|tkr.d	dd„}|}n|tkrFd
dd„}|}n|}i }d|v rn|d |d< |tu rnt}d|v r°t|d tƒr˜|d  	d¡|d< n|d |d< |tu s°J ‚||fS )NÚindex_classrc  c                 S  s:   t j| j|d�}tj|d d�}|d ur6| d¡ |¡}|S )N©r«  rO   ÚUTC)r1   Ú_simple_newrN  r'   Útz_localizeÚ
tz_convert)rN  r«  r¬  ZdtaÚresultrF   rF   rG   rl   æ
  s
    z*GenericFixed._get_index_factory.<locals>.fc                 S  s   t j| |d�}tj|d d�S )Nrj  rO   )r2   rl  r*   )rN  r«  r¬  ZparrrF   rF   rG   rl   ñ
  s    r«  r¬  zutf-8)NN)NN)
rh  rH   r`  r'   r*   r(   r,   rA   ÚbytesrD   )rÀ   rÔ  ri  rl   rÐ  r®   rF   rF   rG   Ú_get_index_factoryÝ
  s*    ÿ

zGenericFixed._get_index_factoryc                 C  s$   |durt dƒ‚|dur t dƒ‚dS )zE
        raise if any keywords are passed which are not-None
        Nzqcannot pass a column specification when reading a Fixed format store. this store must be selected in its entiretyzucannot pass a where specification when reading from a Fixed format store. this store must be selected in its entirety)r¦   )rÀ   rœ   r_   rF   rF   rG   Úvalidate_read  s    ÿÿzGenericFixed.validate_readrz   c                 C  s   dS )NTrF   rÃ   rF   rF   rG   r˜    s    zGenericFixed.is_existsc                 C  s   | j | j_ | j| j_dS rU  )rL   rÔ  rŠ   rÃ   rF   rF   rG   rV    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 attributesrL   NrŠ   ro   )rM   r`  rÔ  rL   rH   rŠ   rb  rï  )rÀ   ræ   rF   rF   rG   rW  #  s    
zGenericFixed.get_attrsc                 K  s   |   ¡  d S rI   )rV  ©rÀ   r–  r®   rF   rF   rG   rš  *  s    zGenericFixed.writeNrx   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u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  r)  r$  r¬  Tr%  r'  r(  )rq   r`  r°   ra  rA   ZVLArrayrH   rB   r•  rÎ  r4  ÚT)rÀ   r   r˜   r™   rq   rÔ   rÔ  ru  ÚretrË  r  r¬  rF   rF   rG   Ú
read_array-  s&    zGenericFixed.read_arrayr(   )r   r˜   r™   r‹   c                 C  sh   t t| j|› d�ƒƒ}|dkr.| j|||d�S |dkrVt| j|ƒ}| j|||d�}|S td|› �ƒ‚d S )NÚ_varietyÚmultir\  Úregularzunrecognized index variety: )rH   r`  rÔ  Úread_multi_indexr°   Úread_index_noder¦   )rÀ   r   r˜   r™   ZvarietyrÔ   r†   rF   rF   rG   Ú
read_indexO  s    zGenericFixed.read_index)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 urÜt|jƒ|j_d S )Nrz  r{  r|  r†   )rA   r)   rï  rÔ  Úwrite_multi_indexÚ_convert_indexrL   rŠ   Úwrite_arrayrN  r`  r°   rZ  ra  rP   r'   r*   re  rÐ   ri  r,   r«  r¬  Ú_get_tz)rÀ   r   r†   r;  rÔ   rF   rF   rG   Úwrite_index]  s    



zGenericFixed.write_indexr)   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‹  Ú	enumerater(  Úlevelsr  Únamesr    r¢   r�  rL   rŠ   r‚  rN  r`  r°   rZ  ra  rP   )rÀ   r   r†   ÚiÚlevÚlevel_codesrP   Ú	level_keyZ
conv_levelrÔ   Ú	label_keyrF   rF   rG   r€  t  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†  r\  rˆ  T)rŠ  r  r‹  r   )	r`  rÔ  rF  r°   r~  r„   rP   ry  r)   )rÀ   r   r˜   r™   r‹  rŠ  r  r‹  rŒ  r�  rÔ   r�  r�  rŽ  rF   rF   rG   r}  �  s     
ÿzGenericFixed.read_multi_indexr>   )rÔ   r˜   r™   r‹   c                 C  sØ   |||… }d|j v r>t |j j¡dkr>tj|j j|j jd�}t|j jƒ}d }d|j v rlt|j j	ƒ}t|ƒ}|j }|  
|¡\}}	|dkr®|t||| j| jd�fdti|	¤Ž}
n |t||| j| jd�fi |	¤Ž}
||
_	|
S )Nr  r   r)  rP   r   r�  rË  )ra  rB   Úprodr  r•  rv  rH   rZ  rQ   rP   rq  Ú_unconvert_indexrL   rŠ   r5  )rÀ   rÔ   r˜   r™   ro  rZ  rP   rÔ  rÐ  r®   r†   rF   rF   rG   r~  ¤  s:    
ÿÿüûÿÿüzGenericFixed.read_index_noder   )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©rU   N)rB   r•  rG  r¶   Úcreate_arrayr°   r`  rN   rË  ra  rv  r  )rÀ   r   r€   ZarrrÔ   rF   rF   rG   Úwrite_array_emptyÊ  s
    zGenericFixed.write_array_emptyrw   zIndex | Noner~   )r   r–  rð   r‹   c                 C  sJ  t |dd�}|| jv r&| j | j|¡ |jdk}d}t|jƒrFtdƒ‚|s^t|dƒr^|j	}d}d }| j
d ur¤ttƒ�  tƒ j |j¡}W d   ƒ n1 sš0    Y  |d urê|sÚ| jj| j|||j| j
d�}||d d …< n|  ||¡ �nL|jjtjk�r`tj|dd�}	|�rn,|	d	k�rn t|	||f }
tj|
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".rw  )r»   ©ZskipnarÚ  rè  rÈ  r$  r'  ),r5   r°   r¶   rœ  r  r   rË  r¢   rÅ  rw  r¾   r   rŸ   ru   ZAtomZ
from_dtypeZcreate_carrayr  r•  rÐ   rB   Zobject_r   Úinfer_dtypeÚperformance_docrí  rî  r   r   Zcreate_vlarrayÚ
ObjectAtomr„   r   r”  Úviewr`  ra  rv  r   Úasi8rƒ  r¬  r#   ru  )rÀ   r   r–  rð   r€   Zempty_arrayru  r  ÚcaÚinferred_typerñ  ZvlarrrÔ   rF   rF   rG   r‚  Ó  sf    


ÿ


.ÿ

ÿ
zGenericFixed.write_array)NN)NN)NN)NN)N)rc   rd   re   r£  r'   r*   rd  rð   rf  rb  r¤  re  rh  rq  rr  r¥  r˜  rV  rW  rš  ry  r  r„  r€  r}  r~  r•  r‚  rF   rF   rF   rG   r`  Ì
  s2   
.# ÿ ÿ ÿ&
 ÿr`  c                      sN   e Zd ZU dZdgZded< edd„ ƒZddddœd	d
„Z‡ fdd„Z	‡  Z
S )r‰  r}  rP   r
   c              	   C  s.   zt | jjƒfW S  ttfy(   Y d S 0 d S rI   )r^   r°   rN  r¦   rr   rÃ   rF   rF   rG   r  4  s    zSeriesFixed.shapeNrx   r\  c                 C  s<   |   ||¡ | jd||d�}| jd||d�}t||| jd�S )Nr†   r\  rN  )r†   rP   )rr  r  ry  r+   rP   )rÀ   r_   rœ   r˜   r™   r†   rN  rF   rF   rG   rý   ;  s    zSeriesFixed.readc                   s<   t ƒ j|fi |¤Ž |  d|j¡ |  d|¡ |j| j_d S )Nr†   rN  )rþ  rš  r„  r†   r‚  rP   rÔ  rt  rÿ  rF   rG   rš  G  s    zSeriesFixed.write)NNNN)rc   rd   re   rC  rb  r¤  r¥  r  rý   rš  r>  rF   rF   rÿ  rG   r‰  .  s   

    ûr‰  c                      sR   e Zd ZU ddgZded< eddœdd„ƒZdd	d	d
œdd„Z‡ fdd„Z‡  Z	S )ÚBlockManagerFixedrG  ÚnblocksrR   zShape | NonerÖ   c                 C  s®   z”| j }d}t| jƒD ]8}t| jd|› d�ƒ}t|dd ƒ}|d ur||d 7 }q| jj}t|dd ƒ}|d ur‚t|d|d … ƒ}ng }| |¡ |W S  ty¨   Y d S 0 d S )Nr   ÚblockÚ_itemsr  rU   )	rG  rF  rŸ  r`  r°   Zblock0_valuesr\   r„   rr   )rÀ   rG  rð   rŒ  rÔ   r  rF   rF   rG   r  S  s"    
zBlockManagerFixed.shapeNrx   r\  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  r\  r   r¡  r9  rU   ©rœ   r†   rA  F)rœ   rp  )rr  rF  Z_get_block_manager_axisrF  rG  r  r„   rŸ  ry  rL  r&   rw  r^   r-   rS  )rÀ   r_   rœ   r˜   r™   Zselect_axisr9  rŒ  rÿ   r   Úaxrð   ÚdfsÚ	blk_itemsrN  ÚdfÚoutrF   rF   rG   rý   n  s(    zBlockManagerFixed.readc                   sè   t ƒ j|fi |¤Ž t|jtƒr*| d¡}|j}| ¡ s@| ¡ }|j| j	_t
|jƒD ]0\}}|dkrr|jsrtdƒ‚|  d|› �|¡ qTt|jƒ| j	_t
|jƒD ]D\}}|j |j¡}| jd|› d�|j|d� |  d|› d�|¡ qžd S )Nr   r   z/Columns index has to be unique for fixed formatr  r9  )rð   r¡  )rþ  rš  rA   Ú_mgrr7   Ú_as_managerZis_consolidatedZconsolidaterG  rÔ  r‰  r9  Z	is_uniquerŸ   r„  r^   ÚblocksrŸ  rð   rM  Úmgr_locsr‚  rN  )rÀ   r–  r®   ro  rŒ  r£  Úblkr¥  rÿ  rF   rG   rš  “  s     

zBlockManagerFixed.write)NNNN)
rc   rd   re   rb  r¤  r¥  r  rý   rš  r>  rF   rF   rÿ  rG   rž  N  s   
    û%rž  c                   @  s   e Zd ZdZeZdS )rŠ  r~  N)rc   rd   re   rC  r&   rF  rF   rF   rF   rG   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œ‡ fdd„Z	e
ddœdd„ƒZddœd d!„Zdd"œd#d$„Zd%d&„ Ze
d'dœd(d)„ƒZd*d+d,œd-d.„Ze
d/dœd0d1„ƒZe
d'dœd2d3„ƒZe
d4d5„ ƒZe
d6d7„ ƒZe
d8d9„ ƒZe
d:d;„ ƒZe
d<d=„ ƒZe
d/dœd>d?„ƒZe
d'dœd@dA„ƒZe
dBdC„ ƒZdDdœdEdF„ZdGdH„ ZdIdœdJdK„ZdddLœdMdN„ZddOdPœdQdR„ZddSœdTdU„Z dVdW„ Z!dXdY„ Z"dƒdZd[„Z#d\d]„ Z$e%d^d_„ ƒZ&d„d`daœdbdc„Z'd…dddddedfœdgdh„Z(e)d'diœdjdk„ƒZ*dldm„ Z+d†dnd'doœdpdq„Z,e-dnd'drœdsdt„ƒZ.d‡dudvœdwdx„Z/ddd'dddDdyœdzd{„Z0dˆddddd|œd}d~„Z1d‰ddddddœ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_tablerk   rN   rD  rz  rU   zint | list[Hashable]rŠ  Tzlist[IndexCol]Ú
index_axeszlist[tuple[int, Any]]r  zlist[DataCol]Úvalues_axesr\   r‰   r±  r;  rt  Nro   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‰   rt  rŒ   )rÀ   rµ   r°   rL   rŠ   r­  r  r®  r‰   rt  rŒ   rÿ  rF   rG   rÁ   ×  s    




zTable.__init__rÖ   c                 C  s   | j  d¡d S )NÚ_r   )rz  rž  rÃ   rF   rF   rG   Ú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 )rN  r¶  rc  z,dc->[r  rM  c                 S  s   g | ]}t |ƒ‘qS rF   ©rN   r  rF   rF   rG   r[   ø  rç   z"Table.__repr__.<locals>.<listcomp>rP  c                 S  s   g | ]
}|j ‘qS rF   rO   rm  rF   rF   rG   r[   û  rç   rQ  z (typ->z,nrows->z,ncols->z,indexers->[rR  )r  r^   r‰   r¹  rJ  rI  r­  r]  r°  r  Úncols)rÀ   ZjdcrU  ÚverZjverZjindex_axesrF   rF   rG   rÛ   ð  s(    ÿÿþþþÿzTable.__repr__)ræ  c                 C  s"   | j D ]}||jkr|  S qdS )zreturn the axis for cN)r9  rP   )rÀ   ræ  rv   rF   rF   rG   rË     s    


zTable.__getitem__c              
   C  sº   |du rdS |j | j kr2td|j › d| j › d�ƒ‚dD ]~}t| |dƒ}t||dƒ}||kr6t|ƒD ]4\}}|| }||krbtd|› d|› d|› d�ƒ‚qbtd|› d|› d|› d�ƒ‚q6dS )	z"validate against an existing tableNz'incompatible table_type with existing [rç  r  )r­  r  r®  zinvalid combination of [z] on appending data [z] vs current table [)rz  r¦   r`  r‰  rŸ   r4  )rÀ   r½  ræ  ÚsvÚovrŒ  ÚsaxZoaxrF   rF   rG   rY  	  s:    ÿÿÿÿÿÿÿÿzTable.validaterz   c                 C  s   t | jtƒS )z@the levels attribute is 1 or a list in the case of a multi-index)rA   rŠ  r\   rÃ   rF   rF   rG   Úis_multi_index+  s    zTable.is_multi_indexrw   z tuple[DataFrame, list[Hashable]])r–  r‹   c              
   C  s`   t  |jj¡}z| ¡ }W n. tyH } ztdƒ|‚W Y d}~n
d}~0 0 t|tƒsXJ ‚||fS )ze
        validate that we can store the multi-index; reset and return the
        new object
        zBduplicate names/columns in the multi-index when storing as a tableN)r5  Zfill_missing_namesr†   r‹  Zreset_indexrŸ   rA   r&   )rÀ   r–  rŠ  Z	reset_objr8  rF   rF   rG   Úvalidate_multiindex0  s    ÿþzTable.validate_multiindexrR   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  ©rW   rŒ  rF   rF   rG   r[   D  rç   z(Table.nrows_expected.<locals>.<listcomp>)rB   r‘  r­  rÃ   rF   rF   rG   Únrows_expectedA  s    zTable.nrows_expectedc                 C  s
   d| j v S )zhas this table been createdrk   r›  rÃ   rF   rF   rG   r˜  F  s    zTable.is_existsc                 C  s   t | jdd ƒS ©Nrk   ©r`  r°   rÃ   rF   rF   rG   rX  K  s    zTable.storablec                 C  s   | j S )z,return the table group (this is my storable))rX  rÃ   rF   rF   rG   rk   O  s    zTable.tablec                 C  s   | j jS rI   )rk   rË  rÃ   rF   rF   rG   rË  T  s    zTable.dtypec                 C  s   | j jS rI   rÕ  rÃ   rF   rF   rG   rÖ  X  s    zTable.descriptionc                 C  s   t  | j| j¡S rI   )r&  r'  r­  r®  rÃ   rF   rF   rG   r9  \  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 rI   )r^   rN  rm  rF   rF   rG   r@  c  rç   zTable.ncols.<locals>.<genexpr>)Úsumr®  rÃ   rF   rF   rG   r²  `  s    zTable.ncolsc                 C  s   dS rû  rF   rÃ   rF   rF   rG   Úis_transposede  s    zTable.is_transposedc                 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  rL  rm  rF   rF   rG   r[   n  rç   z*Table.data_orientation.<locals>.<listcomp>c                 S  s   g | ]}t |jƒ‘qS rF   )rR   r  rm  rF   rF   rG   r[   o  rç   )r]   r&  r'  r  r­  rÃ   rF   rF   rG   Údata_orientationi  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   rU   c                 S  s   g | ]}|j |f‘qS rF   ©r®  rm  rF   rF   rG   r[   y  rç   z$Table.queryables.<locals>.<listcomp>c                   s   g | ]\}}ˆ | d f‘qS rI   rF   )rW   r  rN  )Ú
axis_namesrF   rG   r[   z  rç   c                   s&   g | ]}|j tˆ jƒv r|j|f‘qS rF   )rP   rE  r‰   r®  r,  rÃ   rF   rG   r[   {  s   )r­  r  r®  r;  )rÀ   Zd1Zd2Zd3rF   )rÂ  rÀ   rG   Ú
queryabless  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 rF   )r  r®  r¹  rF   rF   rG   r[   †  rç   z$Table.index_cols.<locals>.<listcomp>©r­  rÃ   rF   rF   rG   Ú
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 rF   rÁ  r¹  rF   rF   rG   r[   Š  rç   z%Table.values_cols.<locals>.<listcomp>)r®  rÃ   rF   rF   rG   Ú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/metarT  rû   rF   rF   rG   Ú_get_metadata_pathŒ  s    zTable._get_metadata_pathrÆ  )r   rN  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
        rk   )r…   rL   rŠ   rŒ   N)rµ   r“   rÇ  r+   rL   rŠ   rŒ   )rÀ   r   rN  rF   rF   rG   rã  ‘  s    	úzTable.write_metadatarÈ   c                 C  s0   t t | jddƒ|dƒdur,| j |  |¡¡S dS )z'return the meta data array for this keyr²   N)r`  r°   rµ   r«   rÇ  rÊ   rF   rF   rG   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)rN   rz  rÔ  rÅ  rÆ  r  r‰   rŒ   rL   rŠ   rŠ  rt  rÃ   rF   rF   rG   rV  ©  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 )rs  r  Nr‰   rt  rŒ   rL   rŠ   ro   rŠ  c                 S  s   g | ]}|j r|‘qS rF   ©rø  rm  rF   rF   rG   r[   ¿  rç   z#Table.get_attrs.<locals>.<listcomp>c                 S  s   g | ]}|j s|‘qS rF   rÈ  rm  rF   rF   rG   r[   À  rç   )r`  rÔ  r  r‰   rt  rŒ   rM   rL   rH   rŠ   rŠ  Ú
indexablesr­  r®  rÃ   rF   rF   rG   rW  ¶  s    zTable.get_attrsc                 C  s\   |durX| j d dkrX| j d dkrX| j d dk rXtd dd„ | j D ƒ¡ }t |t¡ dS )	rZ  Nr   rU   rG  rH  rM  c                 S  s   g | ]}t |ƒ‘qS rF   r±  r  rF   rF   rG   r[   Æ  rç   z*Table.validate_version.<locals>.<listcomp>)rI  Úincompatibility_docr¹  rí  rî  rg   )rÀ   r_   rñ  rF   rF   rG   r[  Â  s    *zTable.validate_versionc                 C  sR   |du rdS t |tƒsdS |  ¡ }|D ]&}|dkr4q&||vr&td|› d�ƒ‚q&dS )zˆ
        validate the min_itemsize doesn't contain items that are not in the
        axes this needs data_columns to be defined
        NrN  zmin_itemsize has the key [z%] which is not an axis or data_column)rA   r;  rÃ  rŸ   )rÀ   r‡   Úqr  rF   rF   rG   Úvalidate_min_itemsizeÉ  s    

ÿzTable.validate_min_itemsizec                   sÔ   g }ˆj ‰ˆjj‰tˆjjƒD ]j\}\}}tˆ|ƒ}ˆ |¡}|durJdnd}|› d�}tˆ|dƒ}	t||||	|ˆj||d�}
| |
¡ qt	ˆj
ƒ‰t|ƒ‰ ‡ ‡‡‡‡fdd„‰| ‡fdd„tˆjjƒD ƒ¡ |S )	z/create/cache the indexables if they don't existNrö  r´  )rP   r  r°  rZ  r¯  rk   r²   r±  c                   s¢   t |tƒsJ ‚t}|ˆv rt}tˆ|ƒ}t|ˆjƒ}tˆ|› d�d ƒ}tˆ|› d�d ƒ}t|ƒ}ˆ |¡}tˆ|› d�d ƒ}	|||||ˆ |  |ˆj	|	||d�
}
|
S )Nr´  r  r  )
rP   r®  rN  rZ  r°  r¯  rk   r²   r±  rË  )
rA   rN   rý  r?  r`  Ú_maybe_adjust_namerI  r  r÷  rk   )rŒ  ræ  Úklassr  Úadj_namerN  rË  rZ  Úmdr²   r–  )Úbase_posrU  ÚdescrÀ   Útable_attrsrF   rG   rl     s0    

özTable.indexables.<locals>.fc                   s   g | ]\}}ˆ ||ƒ‘qS rF   rF   )rW   rŒ  ræ  )rl   rF   rG   r[   '  rç   z$Table.indexables.<locals>.<listcomp>)rÖ  rk   rÔ  r‰  rÅ  r`  r÷  rª  r„   rE  r‰   r^   rI  rÆ  )rÀ   Ú_indexablesrŒ  r  rP   r  rÐ  r²   rµ  rZ  Ú	index_colrF   )rÑ  rU  rÒ  rl   rÀ   rÓ  rG   rÉ  ß  s2    


ø

% zTable.indexablesry   r  c              	   C  sV  |   ¡ sdS |du rdS |du s(|du r8dd„ | jD ƒ}t|ttfƒsL|g}i }|dur`||d< |durp||d< | j}|D ]Ö}t|j|dƒ}|du�r"|jrò|j	}|j
}	|j}
|durÈ|
|krÈ| ¡  n|
|d< |durê|	|krê| ¡  n|	|d< |j�sP|j d¡�rtd	ƒ‚|jf i |¤Ž qz|| jd
 d v rztd|› d|› d|› d�ƒ‚qzdS )aZ  
        Create a pytables index on the specified columns.

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

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

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

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

        Notes
        -----
        Cannot index Time64Col or ComplexCol.
        Pytables must be >= 3.0.
        NFTc                 S  s   g | ]}|j r|j‘qS rF   )rù  r®  rm  rF   rF   rG   r[   N  rç   z&Table.create_index.<locals>.<listcomp>rY  rZ  Ú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   rU   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  r9  rA   r]   r\   rk   r`  r?  rl  r†   rY  rZ  Zremove_indexrÐ   rh  r¦   r[  r  rr   )rÀ   rœ   rY  rZ  Úkwrk   ræ  rC  r†   Zcur_optlevelZcur_kindrF   rF   rG   r[  +  sR    


ÿÿþÿzTable.create_indexrx   z!list[tuple[ArrayLike, ArrayLike]]©r˜   r™   r‹   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  r3  )
Ú	Selectionr«   r9  rõ  rt  rÑ  rŒ   rL   rŠ   r„   )	rÀ   r_   r˜   r™   Ú	selectionrN  r©  rv   ÚresrF   rF   rG   Ú
_read_axes  s    
üzTable._read_axes©ru  c                 C  s   |S )zreturn the data for this objrF   ©r”  r–  ru  rF   rF   rG   Ú
get_object¡  s    zTable.get_objectc                   s²   t |ƒsg S |d \}‰ | j |i ¡}| d¡dkrL|rLtd|› d|› �ƒ‚|du r^tˆ ƒ}n|du rjg }t|tƒ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Ð   r)   z"cannot use a multi-index on axis [z] with data_columns TNc                   s    g | ]}|d kr|ˆ vr|‘qS rÒ  rF   r  )Úexisting_data_columnsrF   rG   r[   Â  s   þz/Table.validate_data_columns.<locals>.<listcomp>c                   s   g | ]}|ˆ v r|‘qS rF   rF   )rW   ræ  )Úaxis_labelsrF   rG   r[   Ê  rç   )
r^   rt  rÉ   rŸ   r\   rA   r;  rE  rI  rì   )rÀ   r‰   r‡   r  r  rt  rF   )rá  rà  rG   Úvalidate_data_columns¦  s.    ÿÿ


þÿ	zTable.validate_data_columnsr&   )r–  rY  c           /        s�  t ˆtƒs,| jj}td|› dtˆƒ› d�ƒ‚ˆ du r:dg‰ ‡fdd„ˆ D ƒ‰ |  ¡ rzd}d	d„ | jD ƒ‰ t| j	ƒ}| j
}nd
}| j}	| jdks’J ‚tˆ ƒ| jd kr¬tdƒ‚g }
|du 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àJ ‚t|
ƒdk�sòJ ‚|
D ]}t!ˆ|d |d ƒ‰�qö|jdk}|  "|||
¡}|  #ˆ|¡ $¡ }|  %|||
| j&|¡\}}g }t't(||ƒƒD �]º\}\}}t)}d}|�rÆt|ƒdk�rÆ|d |v �rÆt*}|d }|du �sÆt |t+ƒ�sÆtdƒ‚|�r(|�r(z| j&| }W nD t,t-f�y$ }  z&td|› d| j&› d�ƒ| ‚W Y d} ~ n
d} ~ 0 0 nd}|�p:d|› �}!t.|!|j/|||| j| j|d�}"t0|!| j1ƒ}#| 2|"¡}$t3|"j4j5ƒ}%d}&t6|"ddƒdu�rœt7|"j8ƒ}&d }' }(})t9|"j4ƒ�rÒ|"j:})d}'tj|"j;d
d� <¡ }(t=|"ƒ\}*}+||#|!t|ƒ|$||%|&|)|'|(|+|*d�},|, |	¡ | |,¡ |d7 }�qddd„ |D ƒ}-t| ƒ| j>| j| j| j||
||-|	|d�
}.t?| dƒ�rl| j@|._@|. A|¡ |�rŒ|�rŒ|. B| ¡ |.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->rw  r  Nr   c                   s   g | ]}ˆ   |¡‘qS rF   )Ú_get_axis_numberrm  )r–  rF   rG   r[   ø  rç   z&Table._create_axes.<locals>.<listcomp>Tc                 S  s   g | ]
}|j ‘qS rF   rA  rm  rF   rF   rG   r[   ý  rç   FrH  rU   z<currently only support ndim-1 indexers in an AppendableTableÚnanc                   s   g | ]}|ˆ vr|‘qS rF   rF   r  )r9  rF   rG   r[     rç   rÀ  r‹  rÐ   r@  zIncompatible appended table [z]with existing table [Zvalues_block_)Úexisting_colr‡   rŒ   rL   rŠ   rœ   r¬  rö  r1  )rP   r®  rN  r¯  r°  rZ  r¬  rT  r²   r±  rË  ro  c                 S  s   g | ]}|j r|j‘qS rF   )rù  rP   )rW   r×  rF   rF   rG   r[   �  rç   )
rµ   r°   rL   rŠ   r­  r  r®  r‰   rt  rŒ   rŠ  )CrA   r&   r°   r³   r¦   rÐ   r  r­  r\   r‰   rŒ   rt  rG  r^   rŸ   r9  r  r%   rB   ÚarrayrK  rë  r‹  rc   r„   Z_get_axis_namer�  rL   rŠ   r  r²  rò  rÜ  Ú_reindex_axisrâ  rß  r!  Ú_get_blocks_and_itemsr®  r‰  r(  rý  r?  rN   Ú
IndexErrorr¬   Ú_maybe_convert_for_string_atomrN  rÍ  rI  r  r  rË  rP   r`  rƒ  r¬  r   rT  r0  r6  r  rµ   rÅ  rŠ  rÌ  rY  )/rÀ   r9  r–  rY  rŒ   r‰   r‡   r°   Útable_existsZnew_infoÚnew_non_index_axesrð  rv   Zappend_axisZindexerZ
exist_axisrt  Ú	axis_nameZ	new_indexZnew_index_axesÚjru  r~  rª  r¥  ZvaxesrŒ  r¬  Úb_itemsrÎ  rP   rå  r8  Únew_nameÚdata_convertedrÏ  r¯  rZ  r¬  r²   r±  rT  ro  r	  r×  ZdcsZ	new_tablerF   )r9  r–  rG   Ú_create_axesÌ  s    
ÿÿ
ÿ
ÿ





ÿÿ"ÿÿýø


ô

ö

zTable._create_axes)r~  rë  c                 C  s|  t | jtƒr|  d¡} dd„ }| j}tt|ƒ}t|jƒ}||ƒ}t|ƒr¾|d \}	}
t	|
ƒ 
t	|ƒ¡}| j||	d�j}t|jƒ}||ƒ}|D ]0}| j|g|	d�j}| |j¡ | ||ƒ¡ qŒ|�rtdd„ t||ƒD ƒ}g }g }|D ]†}t|jƒ}z&| |¡\}}| |¡ | |¡ W qä ttf�yh } z2d d	d
„ |D ƒ¡}td|› d�ƒ|‚W Y d }~qäd }~0 0 qä|}|}||fS )Nr   c                   s   ‡ fdd„ˆ j D ƒS )Nc                   s   g | ]}ˆ j  |j¡‘qS rF   )rð   rM  r«  )rW   r¬  ©ÚmgrrF   rG   r[   Å  rç   zFTable._get_blocks_and_items.<locals>.get_blk_items.<locals>.<listcomp>)rª  ró  rF   ró  rG   Úget_blk_itemsÄ  s    z2Table._get_blocks_and_items.<locals>.get_blk_itemsr   rA  c                 S  s"   i | ]\}}t | ¡ ƒ||f“qS rF   )r]   Útolist)rW   Úbrï  rF   rF   rG   rD  Þ  s   ÿz/Table._get_blocks_and_items.<locals>.<dictcomp>r¶  c                 S  s   g | ]}t |ƒ‘qS rF   rO  )rW   ÚitemrF   rF   rG   r[   ë  rç   z/Table._get_blocks_and_items.<locals>.<listcomp>z+cannot match existing table structure for [z] on appending data)rA   r¨  r7   r©  r   r8   r\   rª  r^   r(   rJ  rS  rI  r(  r]   rN  rR  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ï  r8  ZjitemsrF   rF   rG   rè  ¶  sN    



þ


ÿýzTable._get_blocks_and_itemsrÙ  )rÚ  c           
        sª   |durt |ƒ}|durNˆjrNtˆjt ƒs.J ‚ˆjD ]}||vr4| d|¡ q4ˆjD ]\}}tˆ |||ƒ‰ qT|jdur¦|j ¡ D ]$\}‰}‡ ‡‡fdd„}	|	||ƒ‰ q€ˆ S )zprocess axes filtersNr   c                   sÌ   ˆ j D ]°}ˆ  |¡}ˆ  |¡}|d us*J ‚| |krfˆjrH| tˆjƒ¡}ˆ||ƒ}ˆ j|d�|   S | |v rtt	ˆ | ƒj
ƒ}t|ƒ}tˆ tƒr˜d| }ˆ||ƒ}ˆ j|d�|   S qtd| › d�ƒ‚d S )NrA  rU   zcannot find the field [z] for filtering!)Z_AXIS_ORDERSrã  Ú	_get_axisr·  Úunionr(   rŠ  rQ  r6   r`  rN  rA   r&   rŸ   )ÚfieldÚfiltrí  Zaxis_numberZaxis_valuesZtakersrN  ©r–  ÚoprÀ   rF   rG   Úprocess_filter
  s"    





z*Table.process_axes.<locals>.process_filter)	r\   r·  rA   rŠ  Úinsertr  rç  Úfilterr…   )
rÀ   r–  rÚ  rœ   ræ   r  Úlabelsrû  rü  rÿ  rF   rý  rG   Úprocess_axesõ  s    

!zTable.process_axes)r‚   rº   r:  r‹   c                 C  s‚   |du rt | jdƒ}d|dœ}dd„ | jD ƒ|d< |rj|du rH| jpFd}tƒ j|||pZ| jd	�}||d
< n| jdur~| j|d
< |S )z:create the description of the table from the axes & valuesNi'  rk   )rP   r:  c                 S  s   i | ]}|j |j“qS rF   )r®  r¯  rm  rF   rF   rG   rD  >  rç   z,Table.create_description.<locals>.<dictcomp>rÖ  é	   )r‚   rƒ   rº   r»   )Úmaxrº  r9  r¸   ru   rò   r¹   r¾   )rÀ   rƒ   r‚   rº   r:  r<  r»   rF   rF   rG   Úcreate_description/  s     	

ý


zTable.create_descriptionr\  c           
      C  s�   |   |¡ |  ¡ sdS t| |||d�}| ¡ }|jdurˆ|j ¡ D ]D\}}}| j|| ¡ | ¡ d d�}	|||	j	|| ¡   |ƒj
 }qBt|ƒS )zf
        select coordinates (row numbers) from a table; return the
        coordinates object
        Fr  NrU   r\  )r[  r  rÙ  Úselect_coordsr  r…   r  r¨  r  ÚilocrN  r(   )
rÀ   r_   r˜   r™   rÚ  Zcoordsrû  rþ  rü  ro  rF   rF   rG   r  N  s    

ÿ zTable.read_coordinatesr  c                 C  sº   |   ¡  |  ¡ sdS |du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 indexabler3  rU   rO   z] not found in the table)r[  r  r¦   r9  rP   rù  rŸ   r`  rk   r?  rõ  rt  rÑ  rŒ   rL   rŠ   r+   rÎ  r¬  r¬   )rÀ   r  r_   r˜   r™   rv   ræ  Z
col_valuesrF   rF   rG   r  h  s*    


ÿ
üzTable.read_column)Nro   NNNNNN)N)NNN)NN)TNNN)N)NNN)NNN)4rc   rd   re   r£  rC  rD  r¤  rŠ  r)  rÁ   r¥  r°  rÛ   rË   rY  r·  r¸  rº  r˜  rX  rk   rË  rÖ  r9  r²  r¾  r¿  rÃ  rÅ  rÆ  rÇ  rã  r÷  rV  rW  r[  rÌ  r   rÉ  r[  rÜ  r=  rß  râ  rò  Ústaticmethodrè  r  r  r  r  r>  rF   rF   rÿ  rG   rê   ²  s¦   
        õ"





	

KU ÿ"*    ù k>:  ÿ   ûrê   c                   @  s.   e Zd ZdZdZd
dddœdd„Z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‡  Nrx   r\  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 readNr]  r^  rF   rF   rG   rý   �  s    
zWORMTable.readc                 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 writeNr]  r_  rF   rF   rG   rš  ©  s    zWORMTable.write)NNNN)rc   rd   re   r£  rz  rý   rš  rF   rF   rF   rG   r‘  ”  s       ûr‘  c                   @  sV   e Zd ZdZdZddd„Zddd	d
œdd„Zdddddœdd„Zddddœdd„ZdS )rÞ  ú(support the new appendable table formatsZ
appendableNFTc                 C  s¶   |s| j r| j | jd¡ | j||||||d�}|jD ]}| ¡  q6|j s‚|j||||	d�}| ¡  ||d< |jj	|jfi |¤Ž |j
|j_
|jD ]}| ||¡ q’|j||
d� d S )Nrk   )r9  r–  rY  r‡   rŒ   r‰   )rƒ   r‚   rº   r:  r-  )rˆ   )r˜  r¶   rœ  r°   rò  r9  rÝ  r  rV  Zcreate_tablert  rÔ  rå  Ú
write_data)rÀ   r–  r9  r„   rƒ   r‚   rº   r‡   rš   r:  rˆ   rŒ   r‰   r-  rk   rv   ÚoptionsrF   rF   rG   rš  ·  s4    
ú	

ü

zAppendableTable.writerx   rz   )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´J |
ƒ‚d
d	„ | jD ƒ}dd	„ |D ƒ}g }t|ƒD ]6\}}|f| j ||
|   j }| 
||  |¡¡ qÞ|du �r$d}tjt||ƒ| j d�}|| d }t|ƒD ]x}|| ‰t|d | |ƒ‰ ˆˆ k�r| �qÈ| j|‡ ‡fdd	„|	D ƒ|du�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   rA  Úu1Fr1  rU   Nc                 S  s   g | ]
}|j ‘qS rF   )rÙ  rm  rF   rF   rG   r[     rç   z.AppendableTable.write_data.<locals>.<listcomp>c                 S  s   g | ]}|  ¡ ‘qS rF   )rÓ  rm  rF   rF   rG   r[     rç   c              	   S  s,   g | ]$}|  t t |j¡|jd  ¡¡‘qS r“  )Z	transposerB   Zrollrü  rG  r,  rF   rF   rG   r[     rç   r§  r)  c                   s   g | ]}|ˆˆ … ‘qS rF   rF   rm  ©Zend_iZstart_irF   rG   r[   )  rç   c                   s   g | ]}|ˆˆ … ‘qS rF   rF   r,  r  rF   rG   r[   +  rç   )Úindexesr<  rN  )rË  r‹  rº  r®  r.   ro  r=  rA   rB   rÊ  r„   r8  r^   r6  r­  r‰  r  Úreshaper•  r¨  rF  Úwrite_data_chunk)rÀ   rš   rˆ   r‹  r  Úmasksrv   r<  Úmr  ÚnindexesrN  ÚbvaluesrŒ  rC  Z	new_shapeÚrowsÚchunksrF   r  rG   r  ó  sL    




üzAppendableTable.write_datarÆ  zlist[np.ndarray]znp.ndarray | None)r  r  r<  rN  c                 C  sä   |D ]}t  |j¡s dS q|d jd }|t|ƒkrFt j|| jd�}| jj}t|ƒ}t|ƒD ]\}	}
|
|||	 < q^t|ƒD ]\}	}||||	|  < q||durÂ| ¡ j	t
dd� }| ¡ sÂ|| }t|ƒrà| j |¡ | j ¡  dS )zê
        Parameters
        ----------
        rows : an empty memory space where we are putting the chunk
        indexes : an array of the indexes
        mask : an array of the masks
        values : an array of the values
        Nr   r)  Fr1  )rB   r‘  r  r^   r•  rË  r‹  r‰  r6  r8  rz   r=  rk   r„   rö   )rÀ   r  r  r<  rN  rC  r  r‹  r  rŒ  rð  r  rF   rF   rG   r  .  s&    z AppendableTable.write_data_chunkr\  c                 C  sb  |d u st |ƒsf|d u r:|d u r:| j}| jj| jdd� n(|d u rH| j}| jj||d�}| j ¡  |S |  ¡ srd S | j}t	| |||d�}| 
¡ }t|ƒ ¡ }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 )NTr1  r\  rU   r   r/  )r^   r  r¶   rœ  r°   rk   Zremove_rowsrö   r  rÙ  r  r+   Zsort_valuesÚdiffr\   r†   r„   r   rR  ÚreversedrM  rF  )rÀ   r_   r˜   r™   r  rk   rÚ  rN  Zsorted_seriesÚlnr  r¨   Zpgrï   r  rF   rF   rG   r7  Z  sD    

ÿ
zAppendableTable.delete)NFNNNNNNFNNT)F)NNN)	rc   rd   re   r£  rz  rš  r  r  r7  rF   rF   rF   rG   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…  rH  rE  rF  rz   rÖ   c                 C  s   | j d jdkS )Nr   rU   )r­  r  rÃ   rF   rF   rG   r¾  Ÿ  s    z"AppendableFrameTable.is_transposedrÝ  c                 C  s   |r
|j }|S )zthese are written transposed)rw  rÞ  rF   rF   rG   rß  £  s    zAppendableFrameTable.get_objectNrx   r\  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stJ ‚|d }|| d }	g }
tˆ jƒD �]N\}}|ˆ j	vr¬q–|| \}}| d¡dkrÐt
|ƒ}n
t |¡}| d¡}|d urú|j|d	d
� ˆ j�r |}|}t
|	t|	dd ƒd�}n|j}t
|	t|	dd ƒd�}|}|jdk�rlt|tjƒ�rl| d|jd f¡}t|tjƒ�rŒt|j||d�}n.t|t
ƒ�r¨t|||d�}ntj|g||d�}|j|jk ¡ �sÜJ |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  u r|‘qS r  rÄ  )rW   rŒ  r£  rÃ   rF   rG   r[   Á  rç   z-AppendableFrameTable.read.<locals>.<listcomp>rU   rÐ   r)   r‹  T©ZinplacerP   rO   r¢  rA  )rÚ  rœ   ) r[  r  rÜ  r^   r  rt  rÉ   r‰  r9  r®  r(   r)   Úfrom_tuplesÚ	set_namesr¾  r`  rw  rG  rA   rB   rÊ  r  r  r&   Z_from_arraysZdtypesrË  r=  r„   r-   rÙ  r  )rÀ   r_   rœ   r˜   r™   ro  rt  ZindsÚindr†   ÚframesrŒ  rv   Z
index_valsrÙ  r?  r‹  rN  Zindex_Zcols_r¦  rÚ  rF   rÃ   rG   rý   ª  sZ    	
ÿý



"
zAppendableFrameTable.read)NNNN)rc   rd   re   r£  rC  rz  rG  r&   rF  r¤  r¥  r¾  r=  rß  rý   rF   rF   rF   rG   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ƒ  rH  rz   rÖ   c                 C  s   dS rû  rF   rÃ   rF   rF   rG   r¾    s    z#AppendableSeriesTable.is_transposedrÝ  c                 C  s   |S rI   rF   rÞ  rF   rF   rG   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 tablerN  ©r–  r‰   )rA   r&   rP   Zto_framerþ  rš  rœ   rö  )rÀ   r–  r‰   r®   rP   rÿ  rF   rG   rš    s    


zAppendableSeriesTable.writerx   r+   rØ  c                   s�   | j }|d urB|rBt| jtƒs"J ‚| jD ]}||vr(| d|¡ q(tƒ j||||d�}|rj|j| jdd� |jd d …df }|j	dkrŒd |_	|S )Nr   r  Tr  rN  )
r·  rA   rŠ  r\   r   rþ  rý   Ú	set_indexr  rP   )rÀ   r_   rœ   r˜   r™   r·  ræ   rE   rÿ  rF   rG   rý     s    

zAppendableSeriesTable.read)N)NNNN)rc   rd   re   r£  rC  rz  rG  r+   rF  r¥  r¾  r=  rß  rš  rý   r>  rF   rF   rÿ  rG   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*J ‚t| jƒ}| |¡ t|ƒ|_tƒ j	f d|i|¤ŽS )r   rN  r–  )
rP   r¸  rŠ  rA   r\   r„   r(   rœ   rþ  rš  )rÀ   r–  r®   rP   Znewobjr?  rÿ  rF   rG   rš  2  s    



z AppendableMultiSeriesTable.write)rc   rd   re   r£  rC  rz  rš  r>  rF   rF   rÿ  rG   rŽ  ,  s   rŽ  c                   @  sd   e Zd ZU dZdZdZdZeZde	d< e
ddœd	d
„ƒZe
dd„ ƒZ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|  rH  zlist[Hashable]rŠ  rN   rÖ   c                 C  s   | j S rI   )rC  rÃ   rF   rF   rG   r]  F  s    zGenericTable.pandas_typec                 C  s   t | jdd ƒp| jS r»  r¼  rÃ   rF   rF   rG   rX  J  s    zGenericTable.storablec                 C  sL   g | _ d| _g | _dd„ | jD ƒ| _dd„ | jD ƒ| _dd„ | jD ƒ| _dS )rs  Nc                 S  s   g | ]}|j r|‘qS rF   rÈ  rm  rF   rF   rG   r[   T  rç   z*GenericTable.get_attrs.<locals>.<listcomp>c                 S  s   g | ]}|j s|‘qS rF   rÈ  rm  rF   rF   rG   r[   U  rç   c                 S  s   g | ]
}|j ‘qS rF   rO   rm  rF   rF   rG   r[   V  rç   )r  rŒ   rŠ  rÉ  r­  r®  r‰   rÃ   rF   rF   rG   rW  N  s    zGenericTable.get_attrsc           
   
   C  s¨   | j }|  d¡}|durdnd}tdd| j||d�}|g}t|jƒD ]^\}}t|tƒsZJ ‚t||ƒ}|  |¡}|durzdnd}t	|||g|| j||d�}	| 
|	¡ qD|S )z0create the indexables from the table descriptionr†   Nrö  r   )rP   r  rk   r²   r±  )rP   r°  rN  r¯  rk   r²   r±  )rÖ  r÷  rú  rk   r‰  Z_v_namesrA   rN   r`  rA  r„   )
rÀ   r<  rÐ  r²   rÕ  rÔ  rŒ  ræ   r  rU  rF   rF   rG   rÉ  X  s.    
ÿ

ù	zGenericTable.indexablesc                 K  s   t dƒ‚d S )Nz cannot write on an generic tabler]  r_  rF   rF   rG   rš  {  s    zGenericTable.writeN)rc   rd   re   r£  rC  rz  rG  r&   rF  r¤  r¥  r]  rX  rW  r   rÉ  rš  rF   rF   rF   rG   rŒ  =  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†  rH  z^level_\d+$rN   rÖ   c                 C  s   dS )NZappendable_multirF   rÃ   rF   rF   rG   r°  ‡  s    z*AppendableMultiFrameTable.table_type_shortNc                   sx   |d u rg }n|du r |j  ¡ }|  |¡\}| _t| jtƒs@J ‚| jD ]}||vrF| d|¡ qFtƒ jf ||dœ|¤ŽS )NTr   r!  )	rœ   rö  r¸  rŠ  rA   r\   r   rþ  rš  )rÀ   r–  r‰   r®   ræ   rÿ  rF   rG   rš  ‹  s    

zAppendableMultiFrameTable.writerx   r\  c                   sD   t ƒ j||||d�}| ˆ j¡}|j ‡ fdd„|jjD ƒ¡|_|S )Nr  c                   s    g | ]}ˆ j  |¡rd n|‘qS rI   )Ú
_re_levelsÚsearch)rW   rP   rÃ   rF   rG   r[   ¤  rç   z2AppendableMultiFrameTable.read.<locals>.<listcomp>)rþ  rý   r"  rŠ  r†   r  r‹  )rÀ   r_   rœ   r˜   r™   r¦  rÿ  rÃ   rG   rý   —  s    ÿzAppendableMultiFrameTable.read)N)NNNN)rc   rd   re   r£  rz  r&   rF  rG  ÚreÚcompiler#  r¥  r°  rš  rý   r>  rF   rF   rÿ  rG   r�    s   
    ûr�  r&   r(   )r–  r  r  r‹   c                 C  s¢   |   |¡}t|ƒ}|d ur"t|ƒ}|d u s4| |¡rB| |¡rB| S t| ¡ ƒ}|d urlt| ¡ ƒj|dd�}| |¡sžtd d ƒg| j }|||< | jt|ƒ } | S )NF)Úsort)	rù  r6   ÚequalsÚuniquerP  ÚslicerG  rQ  r]   )r–  r  r  r½  r£  ZslicerrF   rF   rG   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¬  ÚzonerF   rF   rG   rƒ  Â  s    
rƒ  znp.ndarray | Indexzstr | tzinfo | Noneznp.ndarray | DatetimeIndex)rN  r¬  r&  r‹   c                 C  sŠ   t | tƒr"| jdu s"| j|ks"J ‚|du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
    NrO   rk  úM8[ns]r)  )rA   r'   r¬  rP   r›  r6  rH   rm  rn  rB   r4  )rN  r¬  r&  rP   rF   rF   rG   rÎ  È  s    

rÎ  )rP   r†   rL   rŠ   r‹   c              
   C  st  t | tƒsJ ‚|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v �r$t
| ||||d�S t |tjƒ�r>|j	tk�sBJ ‚|dk�sTJ |ƒ‚tƒ  ¡ }t
| ||||d�S d S )Nr«  r¬  )rN  rZ  r¯  r«  r¬  r­  zMultiIndex not supported here!Fr–  r   c                 S  s   g | ]}|  ¡ ‘qS rF   )Ú	toordinalr,  rF   rF   rG   r[     rç   z"_convert_index.<locals>.<listcomp>r)  )r­  rÚ  )ÚintegerZfloating)rN  rZ  r¯  r­  r5  )rA   rN   rP   r  r  r?  r  r/   r$   rË  rª  r`  r)   r¦   r   r—  rB   r4  Zint32ru   Z	Time32ColÚ_convert_string_arrayr³  rÛ  rÊ  r5  r™  )rP   r†   rL   rŠ   r­  r;  r	  rZ  r  r�  rN  r³  rF   rF   rG   r�  ð  sT    


ù


ÿ

û

ÿ
r�  )rZ  rL   rŠ   r‹   c                 C  sÎ   |dkrt | ƒ}n¸|dkr$t| ƒ}n¦|dkrvztjdd„ | D ƒtd�}W qÊ tyr   tjdd„ | D ƒtd�}Y qÊ0 nT|dv rŠt | ¡}n@|d	v r¤t| d ||d
�}n&|dkr¼t | d ¡}ntd|› �ƒ‚|S )Nr$  r'  r   c                 S  s   g | ]}t  |¡‘qS rF   r*  r,  rF   rF   rG   r[   6  rç   z$_unconvert_index.<locals>.<listcomp>r)  c                 S  s   g | ]}t  |¡‘qS rF   r-  r,  rF   rF   rG   r[   8  rç   )r.  ÚfloatrÚ  r3  r5  r   zunrecognized index type )r'   r,   rB   r4  r5  rŸ   r:  )ro  rZ  rL   rŠ   r†   rF   rF   rG   r’  -  s&    

 ÿr’  r   râ   )rP   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 u�r~| |¡}|d u�r~||k�r~|}|jd|› �dd�}|S )NFr–  r   z+[date] is not implemented as a table columnra  z>too many timezones in this block, create separate data columnsrÚ  r5  r   zNo.zCannot serialize the column [z2]
because its data contents are not [string] but [z] object dtyperN  z|Sr1  )rË  r5  r   rB   rÊ  rP   r   r—  r¦   r.   rp  rF  r  r^   r/  r  r³  rA   r;  rR   rÉ   r  rà  r8  )rP   r  rå  r‡   rŒ   rL   rŠ   rœ   r	  r�  r<  ro  rŒ  r×  Zerror_column_labelrñ  r³  ZecirF   rF   rG   rê  F  sN    

ÿþÿ 

rê  rÆ  )ro  rL   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]
    rU   ÚSr)  )r^   r+   r6  rN   Úencoder9  r  r  r   r  Ú
libwritersÚmax_len_string_arrayrB   r4  )ro  rL   rŠ   Úensuredr³  rF   rF   rG   r/  ‘  s    ÿþÿr/  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u 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.
    r)  ÚUr   )rŠ   Fr1  Nrä  )r  rB   r4  r6  r5  r^   r3  r4  r   rA   rp  r+   rN   rD   r9  r8  Z!string_array_replace_from_nan_repr  )ro  rŒ   rL   rŠ   r  r³  rË  rF   rF   rG   r:  °  s    
r:  )rN  rÏ  rL   rŠ   c                 C  s6   t |tƒsJ t|ƒƒ‚t|ƒr2t|||ƒ}|| ƒ} | S rI   )rA   rN   rÐ   Ú_need_convertÚ_get_converter)rN  rÏ  rL   rŠ   ÚconvrF   rF   rG   rÍ  ×  s
    rÍ  ©rZ  rL   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 )Nr,  r)  )rB   r4  ©r  rF   rF   rG   r‘   á  rç   z _get_converter.<locals>.<lambda>rÚ  c                   s   t | d ˆ ˆd�S )Nr3  )r:  r;  r�  rF   rG   r‘   ã  s   ÿzinvalid kind )rŸ   r:  rF   r�  rG   r8  ß  s
    r8  r  c                 C  s   | dv rdS dS )N)r$  rÚ  TFrF   r  rF   rF   rG   r7  ê  s    r7  zSequence[int])rP   rI  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   rU   rG  rH  zvalues_block_(\d+)Zvalues_)rA   rN   r^   rŸ   r%  r$  r¨   )rP   rI  r  ÚgrprF   rF   rG   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Ú  rp  r0  rÖ  rR   r  r.  r$  Ú	timedeltar'  rz   rö  r  r5  zcannot interpret dtype of [r  )rH   rh  rŸ   )r>  rZ  rF   rF   rG   r  	  s.    






r  r  c                 C  sb   t | tƒr| j} | jj d¡d }| jjdv r@t |  	d¡¡} nt | t
ƒrP| j} t | ¡} | |fS )zJ
    Convert the passed data into a storable form and a dtype string.
    rP  r   )r  ÚMrÈ  )rA   r0   r  rË  rP   rž  rZ  rB   r4  rš  r*   r›  )ro  r	  rF   rF   rG   r  *  s    


r  c                   @  s<   e Zd ZdZ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ê   rx   )rk   r˜   r™   c                 C  sh  || _ || _|| _|| _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 u r”d}|d u r¤| j j}t ||¡| | _nVt|jjtjƒ�r| jd urä|| jk  ¡ �s | jd u�r|| jk ¡ �rt
dƒ‚|| _W d   ƒ n1 �s$0    Y  | jd u �rd|  |¡| _| jd u�rd| j ¡ \| _| _d S )NFr–  r.  Úbooleanr   z3where must have index locations >= start and < stop)rk   r_   r˜   r™   Ú	conditionr  Ztermsr%  r!   r   rŸ   r   r—  rB   r4  rË  Zbool_r  rü  Ú
issubclassrÐ   r.  r7  ÚgenerateÚevaluate)rÀ   rk   r_   r˜   r™   ÚinferredrF   rF   rG   rÁ   L  sD    


ÿÿÿ&zSelection.__init__c              
   C  s‚   |du rdS | j  ¡ }zt||| j jd�W S  ty| } z:d | ¡ ¡}td|› d|› d�ƒ}t|ƒ|‚W Y d}~n
d}~0 0 dS )z'where can be a : dict,list,tuple,stringN)rÃ  rL   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
                )	rk   rÃ  r3   rL   Ú	NameErrorr¹  rì   r   rŸ   )rÀ   r_   rË  r8  Zqkeysrô   rF   rF   rG   rD  {  s    
ÿûÿ	zSelection.generatec                 C  sX   | j dur(| jjj| j  ¡ | j| jd�S | jdurB| jj | j¡S | jjj| j| jd�S )ú(
        generate the selection
        Nr\  )	rB  rk   Z
read_wherer…   r˜   r™   r%  r  rý   rÃ   rF   rF   rG   r«   ’  s    
ÿ
zSelection.selectc                 C  s”   | j | j }}| jj}|du r$d}n|dk r4||7 }|du rB|}n|dk rR||7 }| jdurx| jjj| j ¡ ||dd�S | jdurˆ| jS t 	||¡S )rH  Nr   T)r˜   r™   r'  )
r˜   r™   rk   r  rB  Zget_where_listr…   r%  rB   rü  )rÀ   r˜   r™   r  rF   rF   rG   r  ž  s"    
ÿ
zSelection.select_coords)NNN)rc   rd   re   r£  rÁ   rD  r«   r  rF   rF   rF   rG   rÙ  @  s      û/rÙ  )rv   NNFNTNNNNro   r@   )	Nr—   ro   NNNNFN)N)F)¨r£  Ú
__future__r   Ú
contextlibr   rp  ra  r   r   r&  r£   r%  Útextwrapr   Útypingr   r   r	   r
   r   r   r   rí  ÚnumpyrB   Zpandas._configr   r   Zpandas._libsr   r   r3  Zpandas._libs.tslibsr   Zpandas._typingr   r   r   Zpandas.compat._optionalr   Zpandas.compat.pickle_compatr   Zpandas.errorsr   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á   r&   r'   r(   r)   r*   r+   r,   r-   r.   Zpandas.core.apir/   Zpandas.core.arraysr0   r1   r2   Zpandas.core.commonÚcoreÚcommonr5  Z pandas.core.computation.pytablesr3   r4   Zpandas.core.constructionr5   Zpandas.core.indexes.apir6   Zpandas.core.internalsr7   r8   Zpandas.io.commonr9   Zpandas.io.formats.printingr:   r;   rq   r<   r=   r>   r?   rS  rJ   rH   rM   rQ   rV   r`   r4  ra   rf   ÚWarningrg   rÊ  rh   rì  ri   Zduplicate_docr˜  ru  rH  Z
dropna_docZ
format_docZconfig_prefixZregister_optionZis_boolZis_one_of_factoryrp   rt   ru   r–   r¯   r©   r”   r  rª  rú  rý  r?  rA  rB  r`  r‰  rž  rŠ  rê   r‘  rÞ  r�  r�  rŽ  rŒ  r�  rç  rƒ  rÎ  r�  r’  rê  r/  r:  rÍ  r8  r7  rÍ  r  r  rÙ  rF   rF   rF   rG   Ú<module>   s0  $	0,
ü&            ñ*:         ö           Np  '   1  d _       i fd1B+	 ý(=K'!