o
    Û­jµÅ ã                	   @  sÒ  U d Z ddlmZ ddlmZ ddlZddlmZmZ ddl	Z	ddl
Z
ddlZddlmZ ddlmZmZmZmZmZmZmZ ddlZddlZddlmZmZmZmZ dd	lmZm Z! dd
l"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z< ddl=m>Z>m?Z?m@Z@mAZA ddlBmCZC ddlDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZO ddlPmQZQmRZRmSZS ddlTmUZU ddlVmW  mXZY ddlZm[Z[m\Z\ ddl]m^Z_m`Z` ddlambZb ddlcmdZdmeZe ddlfmgZg ddlhmiZimjZj e�rKddlkmlZlmmZmmnZn ddlompZp dd lqmrZrmsZsmtZt dd!lumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z} dd"lcm~Z~ d#Zd$Z€d%d&„ Z�dÕd+d,„Z‚d-d.„ Zƒe[Z„dÖd1d2„Z…d3Z†d4e‡d5< d6Zˆd4e‡d7< d8Z‰d4e‡d9< d:d:d;d;d<œZŠeEdgiZ‹d=ZŒd4e‡d>< d?Z�d4e‡d@< e ŽdA¡�  ej�dBdCeŒej�dD� ej�dEde�e ‘g dF¢¡dD� W d  ƒ n	1 �s¶w   Y  da’dCa“dGdH„ Z”	I			C		J					K	$d×dØdadb„Z•		c	K					C	dÙdÚdldm„Z–dÛdqdr„Z—G dsdt„ dtƒZ˜G dudv„ dvƒZ™G dwdx„ dxƒZšG dydz„ dzešƒZ›G d{d|„ d|ešƒZœG d}d~„ d~eœƒZ�G dd€„ d€e�ƒZžG d�d‚„ d‚ƒ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£G d‹dŒ„ 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¨G d•d–„ d–e¨ƒZ©G d—d˜„ d˜e§ƒZªG d™dš„ dše§ƒZ«	dÜdÝd¡d¢„Z¬dÞd¦d§„Z­e	Cdßdàd¬d­„ƒZ®edßdád¯d­„ƒZ®	Cdßdâd²d­„Z®dãd´dµ„Z¯däd·d¸„Z°dåd¼d½„Z±dæd¿dÀ„Z²dædÁdÂ„Z³dçdÄdÅ„Z´dèdÆdÇ„ZµdédÈdÉ„Z¶dêdÌdÍ„Z·dëdÏdÐ„Z¸dìdÑdÒ„Z¹G dÓdÔ„ dÔƒZºdS )ízY
High level interface to PyTables for reading and writing pandas data structures
to disk
é    )Úannotations)ÚsuppressN)ÚdateÚtzinfo)Údedent)ÚTYPE_CHECKINGÚAnyÚCallableÚFinalÚLiteralÚcastÚoverload)ÚconfigÚ
get_optionÚusing_copy_on_writeÚusing_string_dtype)ÚlibÚwriters)Úis_string_array)Ú	timezones)ÚHAS_PYARROW)Úimport_optional_dependency)Úpatch_pickle)ÚAttributeConflictWarningÚClosedFileErrorÚIncompatibilityWarningÚPerformanceWarningÚPossibleDataLossError)Úcache_readonly)Úfind_stack_level)Úensure_objectÚis_bool_dtypeÚis_complex_dtypeÚis_list_likeÚis_string_dtypeÚneeds_i8_conversion)ÚCategoricalDtypeÚDatetimeTZDtypeÚExtensionDtypeÚPeriodDtype)Úarray_equivalent)Ú	DataFrameÚDatetimeIndexÚIndexÚ
MultiIndexÚPeriodIndexÚ
RangeIndexÚSeriesÚStringDtypeÚTimedeltaIndexÚconcatÚisna)ÚCategoricalÚDatetimeArrayÚPeriodArray)ÚBaseStringArray)ÚPyTablesExprÚmaybe_expression)ÚarrayÚextract_array)Úensure_index)ÚArrayManagerÚBlockManager)Ústringify_path)ÚadjoinÚpprint_thing)ÚHashableÚIteratorÚSequence)ÚTracebackType)ÚColÚFileÚNode)ÚAnyArrayLikeÚ	ArrayLikeÚAxisIntÚDtypeArgÚFilePathÚSelfÚShapeÚnpt)ÚBlockz0.15.2úUTF-8c                 C  s   t | tjƒr|  d¡} | S )z(if we have bytes, decode them to unicoderT   )Ú
isinstanceÚnpÚbytes_Údecode)Ús© rZ   úO/var/www/html/CropPilot/venv/lib/python3.10/site-packages/pandas/io/pytables.pyÚ_ensure_decoded’   s   
r\   Úencodingú
str | NoneÚreturnÚstrc                 C  s   | d u rt } | S ©N)Ú_default_encoding©r]   rZ   rZ   r[   Ú_ensure_encoding™   s   rd   c                 C  s   t | tƒr	t| ƒ} | S )zÓ
    Ensure that an index / column name is a str (python 3); otherwise they
    may be np.string dtype. Non-string dtypes are passed through unchanged.

    https://github.com/pandas-dev/pandas/issues/13492
    )rU   r`   ©ÚnamerZ   rZ   r[   Ú_ensure_str¡   s   
rg   Úscope_levelÚintc                   sV   |d ‰ t | ttfƒr‡ fdd„| D ƒ} n
t| ƒrt| ˆ d�} | du s't| ƒr)| S dS )zÔ
    Ensure that the where is a Term or a list of Term.

    This makes sure that we are capturing the scope of variables that are
    passed create the terms here with a frame_level=2 (we are 2 levels down)
    é   c                   s0   g | ]}|d urt |ƒrt|ˆ d d�n|‘qS )Nrj   ©rh   )r;   ÚTerm)Ú.0Úterm©ÚlevelrZ   r[   Ú
<listcomp>»   s
    þz _ensure_term.<locals>.<listcomp>rk   N)rU   ÚlistÚtupler;   rl   Úlen)Úwhererh   rZ   ro   r[   Ú_ensure_term°   s   	
þrv   z¨
where criteria is being ignored as this version [%s] is too old (or
not-defined), read the file in and write it out to a new file to upgrade (with
the copy_to method)
r
   Úincompatibility_doczu
the [%s] attribute of the existing index is [%s] which conflicts with the new
[%s], resetting the attribute to None
Úattribute_conflict_docz‘
your performance may suffer as PyTables will pickle object types that it cannot
map directly to c-types [inferred_type->%s,key->%s] [items->%s]
Úperformance_docÚfixedÚtable)Úfrz   Útr{   z;
: boolean
    drop ALL nan rows when appending to a table
Ú
dropna_docz~
: format
    default format writing format, if None, then
    put will default to 'fixed' and append will default to 'table'
Ú
format_doczio.hdfÚdropna_tableF)Ú	validatorÚdefault_format)rz   r{   Nc                  C  sN   t d u r%dd l} | a ttƒ� | jjdkaW d   ƒ t S 1 s w   Y  t S )Nr   Ústrict)Ú
_table_modÚtablesr   ÚAttributeErrorÚfileÚ_FILE_OPEN_POLICYÚ!_table_file_open_policy_is_strict)r…   rZ   rZ   r[   Ú_tablesô   s   

ÿ
ÿûrŠ   ÚaTrƒ   Úpath_or_bufúFilePath | HDFStoreÚkeyÚvalueúDataFrame | SeriesÚmodeÚ	complevelú
int | NoneÚcomplibÚappendÚboolÚformatÚindexÚmin_itemsizeúint | dict[str, int] | NoneÚdropnaúbool | NoneÚdata_columnsú Literal[True] | list[str] | NoneÚerrorsÚNonec              
     sž   |r‡ ‡‡‡‡‡‡‡‡‡	f
dd„}n‡ ‡‡‡‡‡‡‡‡‡	f
dd„}t | ƒ} t| tƒrIt| |||d��}||ƒ W d  ƒ dS 1 sBw   Y  dS || ƒ dS )z+store this object, close it if we opened itc                   s   | j ˆˆ	ˆˆˆˆˆˆ ˆˆd�
S )N)r—   r˜   r™   Únan_repr›   r�   rŸ   r]   )r•   ©Ústore©
r�   r›   r]   rŸ   r—   r˜   rŽ   r™   r¡   r�   rZ   r[   Ú<lambda>  ó    özto_hdf.<locals>.<lambda>c                   s   | j ˆˆ	ˆˆˆˆˆ ˆˆˆd�
S )N)r—   r˜   r™   r¡   r�   rŸ   r]   r›   ©Úputr¢   r¤   rZ   r[   r¥   +  r¦   )r‘   r’   r”   N)rA   rU   r`   ÚHDFStore)rŒ   rŽ   r�   r‘   r’   r”   r•   r—   r˜   r™   r¡   r›   r�   rŸ   r]   r|   r£   rZ   r¤   r[   Úto_hdf
  s    
ÿ
"ýrª   Úrru   ústr | list | NoneÚstartÚstopÚcolumnsúlist[str] | NoneÚiteratorÚ	chunksizec
                 K  s†  |dvrt d|› d�ƒ‚|durt|dd�}t| tƒr'| js"tdƒ‚| }d}n:t| ƒ} t| tƒs4td	ƒ‚zt	j
 | ¡}W n tt fyI   d}Y nw |sTtd
| › d�ƒ‚t| f||dœ|
¤Ž}d}z9|du r�| ¡ }t|ƒdkrtt dƒ‚|d }|dd… D ]}t||ƒs‰t dƒ‚q~|j}|j|||||||	|d�W S  t ttfyÂ   t| tƒsÁttƒ� | ¡  W d  ƒ ‚ 1 s¼w   Y  ‚ w )a>
  
    Read from the store, close it if we opened it.

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

    .. warning::

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

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

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

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

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

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

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

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

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

    Examples
    --------
    >>> df = pd.DataFrame([[1, 1.0, 'a']], columns=['x', 'y', 'z'])  # doctest: +SKIP
    >>> df.to_hdf('./store.h5', 'data')  # doctest: +SKIP
    >>> reread = pd.read_hdf('./store.h5')  # doctest: +SKIP
    )r«   úr+r‹   zmode zG is not allowed while performing a read. Allowed modes are r, r+ and a.Nrj   rk   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.)ru   r­   r®   r¯   r±   r²   Ú
auto_close)Ú
ValueErrorrv   rU   r©   Úis_openÚOSErrorrA   r`   ÚNotImplementedErrorÚosÚpathÚexistsÚ	TypeErrorÚFileNotFoundErrorÚgroupsrt   Ú_is_metadata_ofÚ_v_pathnameÚselectÚLookupErrorr   r†   Úclose)rŒ   rŽ   r‘   rŸ   ru   r­   r®   r¯   r±   r²   Úkwargsr£   r´   r»   r¾   Úcandidate_only_groupÚgroup_to_checkrZ   rZ   r[   Úread_hdfB  sv   V
ÿ

ÿÿÿ
ÿÿø




ÿýúrÇ   ÚgrouprJ   Úparent_groupc                 C  sN   | j |j krdS | }|j dkr%|j}||kr|jdkrdS |j}|j dksdS )zDCheck if a given group is a metadata group for a given parent_group.Frj   ÚmetaT)Ú_v_depthÚ	_v_parentÚ_v_name)rÈ   rÉ   ÚcurrentÚparentrZ   rZ   r[   r¿   ä  s   

ür¿   c                   @  s¢  e Zd ZU dZded< ded< 				dŸd dd„Zd¡dd„Zedd„ ƒZed¡dd„ƒZ	d¢dd„Z
d£dd„Zd£dd„Zd¤d d!„Zd¥d"d#„Zd¦d%d&„Zd¡d'd(„Zd§d*d+„Zd¨d2d3„Zd©dªd7d8„Zd«d:d;„Zd¬d=d>„Zd­d®d?d@„Zd¯dAdB„Zed°dCdD„ƒZd±d²dFdG„Zd¢dHdI„Z							d³d´dMdN„Z			dµd¶dQdR„Z		d·d¸dTdU„Z								d¹dºdVdW„Z		X								Y	X	d»d¼dedf„Zdµd£dgdh„Z 			X	X											Yd½d¾dkdl„Z!			d¿dÀdodp„Z"			dµdÁdtdu„Z#dÂdwdx„Z$dÃdÄd|d}„Z%dÅdd€„Z&dÆd‚dƒ„Z'	„	X					XdÇdÈd‡dˆ„Z(d¡d‰dŠ„Z)d¯d‹dŒ„Z*dÉdŽd�„Z+			�	YdÊdËd“d”„Z,		X												Y	XdÌdÍd•d–„Z-dÎd™dš„Z.dÏd›dœ„Z/dÐd�dž„Z0dS )Ñr©   aS	  
    Dict-like IO interface for storing pandas objects in PyTables.

    Either Fixed or Table format.

    .. warning::

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

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

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

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

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

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

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

    >>> bar = pd.DataFrame(np.random.randn(10, 4))
    >>> store = pd.HDFStore('test.h5', driver='H5FD_CORE')
    >>> store['foo'] = bar
    >>> store.close()   # only now, data is written to disk
    zFile | NoneÚ_handler`   Ú_moder‹   NFr‘   r’   r“   Ú
fletcher32r–   r_   r    c                 K  s²   d|v rt dƒ‚tdƒ}|d ur ||jjvr t d|jj› d�ƒ‚|d u r,|d ur,|jj}t|ƒ| _|d u r7d}|| _d | _|rA|nd| _	|| _
|| _d | _| jd	d|i|¤Ž d S )
Nr—   z-format is not a defined argument for HDFStorer…   zcomplib only supports z compression.r‹   r   r‘   rZ   )rµ   r   ÚfiltersÚall_complibsÚdefault_complibrA   Ú_pathrÑ   rÐ   Ú
_complevelÚ_complibÚ_fletcher32Ú_filtersÚopen)Úselfrº   r‘   r’   r”   rÒ   rÄ   r…   rZ   rZ   r[   Ú__init__7  s&   	ÿ
zHDFStore.__init__c                 C  ó   | j S ra   ©rÖ   ©rÜ   rZ   rZ   r[   Ú
__fspath__X  s   zHDFStore.__fspath__c                 C  s   |   ¡  | jdusJ ‚| jjS )zreturn the root nodeN)Ú_check_if_openrÐ   Úrootrà   rZ   rZ   r[   rã   [  s   zHDFStore.rootc                 C  rÞ   ra   rß   rà   rZ   rZ   r[   Úfilenameb  ó   zHDFStore.filenamerŽ   c                 C  ó
   |   |¡S ra   )Úget©rÜ   rŽ   rZ   rZ   r[   Ú__getitem__f  ó   
zHDFStore.__getitem__c                 C  s   |   ||¡ d S ra   r§   )rÜ   rŽ   r�   rZ   rZ   r[   Ú__setitem__i  s   zHDFStore.__setitem__c                 C  ræ   ra   )Úremoverè   rZ   rZ   r[   Ú__delitem__l  rê   zHDFStore.__delitem__rf   c              	   C  s@   z|   |¡W S  ttfy   Y nw tdt| ƒj› d|› d�ƒ‚)z$allow attribute access to get storesú'z' object has no attribute ')rç   ÚKeyErrorr   r†   ÚtypeÚ__name__)rÜ   rf   rZ   rZ   r[   Ú__getattr__o  s   ÿÿzHDFStore.__getattr__c                 C  s4   |   |¡}|dur|j}|||dd… fv rdS dS )zx
        check for existence of this key
        can match the exact pathname or the pathnm w/o the leading '/'
        Nrj   TF)Úget_noderÀ   )rÜ   rŽ   Únoderf   rZ   rZ   r[   Ú__contains__y  s   
zHDFStore.__contains__ri   c                 C  ó   t |  ¡ ƒS ra   )rt   r¾   rà   rZ   rZ   r[   Ú__len__…  ó   zHDFStore.__len__c                 C  s   t | jƒ}t| ƒ› d|› d�S )Nú
File path: Ú
)rC   rÖ   rð   )rÜ   ÚpstrrZ   rZ   r[   Ú__repr__ˆ  s   
zHDFStore.__repr__rP   c                 C  s   | S ra   rZ   rà   rZ   rZ   r[   Ú	__enter__Œ  ó   zHDFStore.__enter__Úexc_typeútype[BaseException] | NoneÚ	exc_valueúBaseException | NoneÚ	tracebackúTracebackType | Nonec                 C  ó   |   ¡  d S ra   )rÃ   )rÜ   rÿ   r  r  rZ   rZ   r[   Ú__exit__�  s   zHDFStore.__exit__ÚpandasÚincludeú	list[str]c                 C  sZ   |dkrdd„ |   ¡ D ƒS |dkr%| jdusJ ‚dd„ | jjddd	�D ƒS td
|› d�ƒ‚)aƒ  
        Return a list of keys corresponding to objects stored in HDFStore.

        Parameters
        ----------

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

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

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

        Examples
        --------
        >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df)  # doctest: +SKIP
        >>> store.get('data')  # doctest: +SKIP
        >>> print(store.keys())  # doctest: +SKIP
        ['/data1', '/data2']
        >>> store.close()  # doctest: +SKIP
        r  c                 S  ó   g | ]}|j ‘qS rZ   ©rÀ   ©rm   ÚnrZ   rZ   r[   rq   ¶  ó    z!HDFStore.keys.<locals>.<listcomp>ÚnativeNc                 S  r
  rZ   r  r  rZ   rZ   r[   rq   º  s    ÿú/ÚTable)Ú	classnamez8`include` should be either 'pandas' or 'native' but is 'rî   )r¾   rÐ   Ú
walk_nodesrµ   )rÜ   r  rZ   rZ   r[   Úkeys—  s   ÿ
ÿzHDFStore.keysúIterator[str]c                 C  rö   ra   )Úiterr  rà   rZ   rZ   r[   Ú__iter__Á  rø   zHDFStore.__iter__úIterator[tuple[str, list]]c                 c  s    � |   ¡ D ]}|j|fV  qdS )z'
        iterate on key->group
        N)r¾   rÀ   )rÜ   ÚgrZ   rZ   r[   ÚitemsÄ  s   €ÿzHDFStore.itemsc                 K  s¾   t ƒ }| j|kr)| jdv r|dv rn|dv r&| jr&td| j› d| j› d�ƒ‚|| _| jr0|  ¡  | jrE| jdkrEt ƒ j| j| j| j	d�| _
trP| jrPd	}t|ƒ‚|j| j| jfi |¤Ž| _d
S )a9  
        Open the file in the specified mode

        Parameters
        ----------
        mode : {'a', 'w', 'r', 'r+'}, default 'a'
            See HDFStore docstring or tables.open_file for info about modes
        **kwargs
            These parameters will be passed to the PyTables open_file method.
        )r‹   Úw)r«   r³   )r  zRe-opening the file [z] with mode [z] will delete the current file!r   )rÒ   zGCannot open HDF5 file, which is already opened, even in read-only mode.N)rŠ   rÑ   r¶   r   rÖ   rÃ   r×   ÚFiltersrØ   rÙ   rÚ   r‰   rµ   Ú	open_filerÐ   )rÜ   r‘   rÄ   r…   ÚmsgrZ   rZ   r[   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à   rZ   rZ   r[   rÃ   ø  s   


zHDFStore.closec                 C  s   | j du rdS t| j jƒS )zF
        return a boolean indicating whether the file is open
        NF)rÐ   r–   Úisopenrà   rZ   rZ   r[   r¶      s   
zHDFStore.is_openÚfsyncc                 C  s^   | j dur+| j  ¡  |r-ttƒ� t | j  ¡ ¡ W d  ƒ dS 1 s$w   Y  dS dS dS )aó  
        Force all buffered modifications to be written to disk.

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

        Notes
        -----
        Without ``fsync=True``, flushing may not guarantee that the OS writes
        to disk. With fsync, the operation will block until the OS claims the
        file has been written; however, other caching layers may still
        interfere.
        N)rÐ   Úflushr   r·   r¹   r   Úfileno)rÜ   r   rZ   rZ   r[   r!  	  s   


"ÿýzHDFStore.flushc                 C  sV   t ƒ � |  |¡}|du rtd|› d�ƒ‚|  |¡W  d  ƒ S 1 s$w   Y  dS )a  
        Retrieve pandas object stored in file.

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

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

        Examples
        --------
        >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df)  # doctest: +SKIP
        >>> store.get('data')  # doctest: +SKIP
        >>> store.close()  # doctest: +SKIP
        NúNo object named ú in the file)r   ró   rï   Ú_read_group©rÜ   rŽ   rÈ   rZ   rZ   r[   rç     s   
$úzHDFStore.getr±   r²   r´   c	                   st   |   |¡}	|	du rtd|› d�ƒ‚t|dd�}|  |	¡‰ˆ ¡  ‡ ‡fdd„}
t| ˆ|
|ˆj|||||d�
}| ¡ S )	a6  
        Retrieve pandas object stored in file, optionally based on where criteria.

        .. warning::

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

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

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

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

        Examples
        --------
        >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df)  # doctest: +SKIP
        >>> store.get('data')  # doctest: +SKIP
        >>> print(store.keys())  # doctest: +SKIP
        ['/data1', '/data2']
        >>> store.select('/data1')  # doctest: +SKIP
           A  B
        0  1  2
        1  3  4
        >>> store.select('/data1', where='columns == A')  # doctest: +SKIP
           A
        0  1
        1  3
        >>> store.close()  # doctest: +SKIP
        Nr#  r$  rj   rk   c                   s   ˆj | ||ˆ d�S )N)r­   r®   ru   r¯   ©Úread©Ú_startÚ_stopÚ_where©r¯   rY   rZ   r[   Úfunc†  s   zHDFStore.select.<locals>.func©ru   Únrowsr­   r®   r±   r²   r´   )ró   rï   rv   Ú_create_storerÚ
infer_axesÚTableIteratorr0  Ú
get_result)rÜ   rŽ   ru   r­   r®   r¯   r±   r²   r´   rÈ   r.  ÚitrZ   r-  r[   rÁ   <  s(   
@
özHDFStore.selectr­   r®   c                 C  s8   t |dd�}|  |¡}t|tƒstdƒ‚|j|||d�S )a“  
        return the selection as an Index

        .. warning::

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

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


        Parameters
        ----------
        key : str
        where : list of Term (or convertible) objects, optional
        start : integer (defaults to None), row number to start selection
        stop  : integer (defaults to None), row number to stop selection
        rj   rk   z&can only read_coordinates with a table©ru   r­   r®   )rv   Ú
get_storerrU   r  r¼   Úread_coordinates)rÜ   rŽ   ru   r­   r®   ÚtblrZ   rZ   r[   Úselect_as_coordinates™  s
   

zHDFStore.select_as_coordinatesÚcolumnc                 C  s,   |   |¡}t|tƒstdƒ‚|j|||d�S )a~  
        return a single column from the table. This is generally only useful to
        select an indexable

        .. warning::

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

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

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

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

        z!can only read_column with a table)r;  r­   r®   )r7  rU   r  r¼   Úread_column)rÜ   rŽ   r;  r­   r®   r9  rZ   rZ   r[   Úselect_column¹  s   
#
zHDFStore.select_columnc
                   st  t |dd�}t|ttfƒrt|ƒdkr|d }t|tƒr)ˆj||ˆ|||||	d�S t|ttfƒs4tdƒ‚t|ƒs<tdƒ‚|du rD|d }‡fdd	„|D ƒ‰ˆ 	|¡}
d}t
 |
|fgtˆ|ƒ¡D ]-\}}|du rptd
|› d�ƒ‚|js|td|j› d�ƒ‚|du r„|j}q`|j|kr�tdƒ‚q`dd	„ ˆD ƒ}dd„ |D ƒ ¡ ‰ ‡ ‡‡fdd„}tˆ|
||||||||	d�
}|jdd�S )aÙ  
        Retrieve pandas objects from multiple tables.

        .. warning::

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

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

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

        Raises
        ------
        raises KeyError if keys or selector is not found or keys is empty
        raises TypeError if keys is not a list or tuple
        raises ValueError if the tables are not ALL THE SAME DIMENSIONS
        rj   rk   r   )rŽ   ru   r¯   r­   r®   r±   r²   r´   zkeys must be a list/tuplez keys must have a non-zero lengthNc                   ó   g | ]}ˆ   |¡‘qS rZ   )r7  ©rm   Úkrà   rZ   r[   rq   %  ó    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 rZ   )rU   r  ©rm   ÚxrZ   rZ   r[   rq   :  ó    c                 S  s   h | ]	}|j d  d  ’qS ©r   )Únon_index_axes©rm   r}   rZ   rZ   r[   Ú	<setcomp>=  rE  z.HDFStore.select_as_multiple.<locals>.<setcomp>c                   s*   ‡ ‡‡‡fdd„ˆD ƒ}t |ˆdd� ¡ S )Nc                   s   g | ]}|j ˆˆˆ ˆd �‘qS )©ru   r¯   r­   r®   r'  rH  )r*  r+  r,  r¯   rZ   r[   rq   B  s    ÿÿz=HDFStore.select_as_multiple.<locals>.func.<locals>.<listcomp>F)ÚaxisÚverify_integrity)r4   Ú_consolidate)r*  r+  r,  Úobjs)rK  r¯   Útblsr)  r[   r.  ?  s   þz)HDFStore.select_as_multiple.<locals>.funcr/  T)Úcoordinates)rv   rU   rr   rs   rt   r`   rÁ   r¼   rµ   r7  Ú	itertoolsÚchainÚziprï   Úis_tableÚpathnamer0  Úpopr3  r4  )rÜ   r  ru   Úselectorr¯   r­   r®   r±   r²   r´   rY   r0  r}   r@  Ú_tblsr.  r5  rZ   )rK  r¯   rÜ   rO  r[   Úselect_as_multipleá  sf   +
ø
 ÿ
ÿözHDFStore.select_as_multipleTrƒ   r�   r�   r˜   r•   r™   rš   r�   rž   rŸ   Útrack_timesr›   c                 C  sH   |du r
t dƒp	d}|  |¡}| j|||||||||	|
||||d� dS )a¬  
        Store object in HDFStore.

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

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

        Examples
        --------
        >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df)  # doctest: +SKIP
        Núio.hdf.default_formatrz   )r—   r˜   r•   r”   r’   r™   r¡   r�   r]   rŸ   rZ  r›   )r   Ú_validate_formatÚ_write_to_group)rÜ   rŽ   r�   r—   r˜   r•   r”   r’   r™   r¡   r�   r]   rŸ   rZ  r›   rZ   rZ   r[   r¨   Z  s&   8

òzHDFStore.putc              
   C  sØ   t |dd�}z|  |¡}W n? ty   ‚  ty   ‚  tyL } z%|dur,tdƒ|‚|  |¡}|durB|jdd� W Y d}~dS W Y d}~nd}~ww t 	|||¡r]|j
jdd� dS |jsdtdƒ‚|j|||d�S )	a:  
        Remove pandas object partially by specifying the where condition

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

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

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

        rj   rk   Nz5trying to remove a node with a non-None where clause!T©Ú	recursivez7can only remove with where on objects written as tablesr6  )rv   r7  rï   ÚAssertionErrorÚ	Exceptionrµ   ró   Ú	_f_removeÚcomÚall_nonerÈ   rT  Údelete)rÜ   rŽ   ru   r­   r®   rY   Úerrrô   rZ   rZ   r[   rì   ¦  s8   ÿþ
þ€õÿzHDFStore.removeúbool | list[str]rœ   c                 C  sl   |	durt dƒ‚|du rtdƒ}|du rtdƒpd}|  |¡}| j|||||||||
|||||||d� dS )a|  
        Append to Table in file.

        Node must already exist and be Table format.

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

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

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

        Examples
        --------
        >>> df1 = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df1, format='table')  # doctest: +SKIP
        >>> df2 = pd.DataFrame([[5, 6], [7, 8]], columns=['A', 'B'])
        >>> store.append('data', df2)  # doctest: +SKIP
        >>> store.close()  # doctest: +SKIP
           A  B
        0  1  2
        1  3  4
        0  5  6
        1  7  8
        Nz>columns is not a supported keyword in append, try data_columnszio.hdf.dropna_tabler[  r{   )r—   Úaxesr˜   r•   r”   r’   r™   r¡   r²   Úexpectedrowsr›   r�   r]   rŸ   )r¼   r   r\  r]  )rÜ   rŽ   r�   r—   rh  r˜   r•   r”   r’   r¯   r™   r¡   r²   ri  r›   r�   r]   rŸ   rZ   rZ   r[   r•   ß  s6   Iÿ

ðzHDFStore.appendÚdÚdictc                   s¢  |durt dƒ‚t|tƒstdƒ‚||vrtdƒ‚ttttˆjƒƒtt	t
ˆƒ ƒ ƒƒ}d}	g }
| ¡ D ]\}‰ ˆ du rG|	durDtdƒ‚|}	q4|
 ˆ ¡ q4|	durkˆj| }| t|
ƒ¡}t| |¡ƒ}| |¡||	< |du rs|| }|r“‡fdd„| ¡ D ƒ}t|ƒ}|D ]}| |¡}q†ˆj| ‰| dd¡}| ¡ D ]1\}‰ ||kr§|nd}ˆjˆ |d	�}|dur¿‡ fd
d„| ¡ D ƒnd}| j||f||dœ|¤Ž q�dS )a  
        Append to multiple tables

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

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

        Nztaxes is currently not accepted as a parameter to append_to_multiple; you can create the tables independently insteadzQappend_to_multiple must have a dictionary specified as the way to split the valuez=append_to_multiple requires a selector that is in passed dictz<append_to_multiple can only have one value in d that is Nonec                 3  s"   � | ]}ˆ | j d d�jV  qdS )Úall)ÚhowN)r›   r˜   )rm   Úcols)r�   rZ   r[   Ú	<genexpr>�  s   €  z.HDFStore.append_to_multiple.<locals>.<genexpr>r™   ©rK  c                   s   i | ]\}}|ˆ v r||“qS rZ   rZ   ©rm   rŽ   r�   )ÚvrZ   r[   Ú
<dictcomp>   s    z/HDFStore.append_to_multiple.<locals>.<dictcomp>)r�   r™   )r¼   rU   rk  rµ   Únextr  ÚsetÚrangeÚndimÚ	_AXES_MAPrð   r  Úextendrh  Ú
differencer-   ÚsortedÚget_indexerÚtakeÚvaluesÚintersectionÚlocrV  Úreindexr•   )rÜ   rj  r�   rW  r�   rh  r›   rÄ   rK  Ú
remain_keyÚremain_valuesr@  ÚorderedÚorddÚidxsÚvalid_indexr˜   r™   ÚdcÚvalÚfilteredrZ   )rr  r�   r[   Úappend_to_multipleE  s\   ÿ
ÿÿ&ÿ

ÿýõzHDFStore.append_to_multipleÚoptlevelÚkindr^   c                 C  sB   t ƒ  |  |¡}|du rdS t|tƒstdƒ‚|j|||d� dS )aà  
        Create a pytables index on the table.

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

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

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

        Raises
        ------
        TypeError: raises if the node is not a table
        Nz1cannot create table index on a Fixed format store)r¯   rŒ  r�  )rŠ   r7  rU   r  r¼   Úcreate_index)rÜ   rŽ   r¯   rŒ  r�  rY   rZ   rZ   r[   Úcreate_table_index¦  s   

zHDFStore.create_table_indexrr   c                 C  s<   t ƒ  |  ¡  | jdusJ ‚tdusJ ‚dd„ | j ¡ D ƒS )a�  
        Return a list of all the top-level nodes.

        Each node returned is not a pandas storage object.

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

        Examples
        --------
        >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df)  # doctest: +SKIP
        >>> print(store.groups())  # doctest: +SKIP
        >>> store.close()  # doctest: +SKIP
        [/data (Group) ''
          children := ['axis0' (Array), 'axis1' (Array), 'block0_values' (Array),
          'block0_items' (Array)]]
        Nc                 S  sP   g | ]$}t |tjjƒs&t|jd dƒs$t|ddƒs$t |tjjƒr&|jdkr|‘qS )Úpandas_typeNr{   )	rU   r„   ÚlinkÚLinkÚgetattrÚ_v_attrsr{   r  rÍ   )rm   r  rZ   rZ   r[   rq   è  s    üú
ùø
ùz#HDFStore.groups.<locals>.<listcomp>)rŠ   râ   rÐ   r„   Úwalk_groupsrà   rZ   rZ   r[   r¾   Î  s   þzHDFStore.groupsr  ru   ú*Iterator[tuple[str, list[str], list[str]]]c                 c  s¾   � t ƒ  |  ¡  | jdusJ ‚tdusJ ‚| j |¡D ]A}t|jddƒdur'qg }g }|j ¡ D ]!}t|jddƒ}|du rKt	|tj
jƒrJ| |j¡ q0| |j¡ q0|j d¡||fV  qdS )a€  
        Walk the pytables group hierarchy for pandas objects.

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

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

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

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

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

        Examples
        --------
        >>> df1 = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df1, format='table')  # doctest: +SKIP
        >>> df2 = pd.DataFrame([[5, 6], [7, 8]], columns=['A', 'B'])
        >>> store.append('data', df2)  # doctest: +SKIP
        >>> store.close()  # doctest: +SKIP
        >>> for group in store.walk():  # doctest: +SKIP
        ...     print(group)  # doctest: +SKIP
        >>> store.close()  # doctest: +SKIP
        Nr�  r  )rŠ   râ   rÐ   r„   r•  r“  r”  Ú_v_childrenr~  rU   rÈ   ÚGroupr•   rÍ   rÀ   Úrstrip)rÜ   ru   r  r¾   ÚleavesÚchildr�  rZ   rZ   r[   Úwalkõ  s&   €'€òzHDFStore.walkúNode | Nonec                 C  s~   |   ¡  | d¡sd| }| jdusJ ‚tdusJ ‚z
| j | j|¡}W n tjjy0   Y dS w t|tj	ƒs=J t
|ƒƒ‚|S )z9return the node with the key or None if it does not existr  N)râ   Ú
startswithrÐ   r„   ró   rã   Ú
exceptionsÚNoSuchNodeErrorrU   rJ   rð   )rÜ   rŽ   rô   rZ   rZ   r[   ró   1  s   
ÿzHDFStore.get_nodeúGenericFixed | Tablec                 C  s8   |   |¡}|du rtd|› d�ƒ‚|  |¡}| ¡  |S )z<return the storer object for a key, raise if not in the fileNr#  r$  )ró   rï   r1  r2  )rÜ   rŽ   rÈ   rY   rZ   rZ   r[   r7  A  s   

zHDFStore.get_storerr  ÚpropindexesÚ	overwritec	              	   C  sÎ   t |||||d�}	|du rt|  ¡ ƒ}t|ttfƒs|g}|D ]E}
|  |
¡}|durd|
|	v r5|r5|	 |
¡ |  |
¡}t|tƒr[d}|rKdd„ |j	D ƒ}|	j
|
||t|ddƒ|jd� q|	j|
||jd� q|	S )	a;  
        Copy the existing store to a new file, updating in place.

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

        Returns
        -------
        open file handle of the new store
        )r‘   r”   r’   rÒ   NFc                 S  ó   g | ]}|j r|j‘qS rZ   )Ú
is_indexedrf   ©rm   r‹   rZ   rZ   r[   rq   y  ó    z!HDFStore.copy.<locals>.<listcomp>r�   )r˜   r�   r]   rc   )r©   rr   r  rU   rs   r7  rì   rÁ   r  rh  r•   r“  r]   r¨   )rÜ   r‡   r‘   r¢  r  r”   r’   rÒ   r£  Ú	new_storer@  rY   Údatar˜   rZ   rZ   r[   ÚcopyK  s8   
ÿ




û€zHDFStore.copyc           
      C  s  t | jƒ}t| ƒ› d|› d�}| jr~t|  ¡ ƒ}t|ƒrxg }g }|D ]K}z|  |¡}|durA| t |j	p5|ƒ¡ | t |p>dƒ¡ W q" t
yJ   ‚  tym } z| |¡ t |ƒ}	| d|	› d�¡ W Y d}~q"d}~ww |td||ƒ7 }|S |d7 }|S |d	7 }|S )
a  
        Print detailed information on the store.

        Returns
        -------
        str

        Examples
        --------
        >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
        >>> store = pd.HDFStore("store.h5", 'w')  # doctest: +SKIP
        >>> store.put('data', df)  # doctest: +SKIP
        >>> print(store.info())  # doctest: +SKIP
        >>> store.close()  # doctest: +SKIP
        <class 'pandas.io.pytables.HDFStore'>
        File path: store.h5
        /data    frame    (shape->[2,2])
        rù   rú   Nzinvalid_HDFStore nodez[invalid_HDFStore node: rB  é   ÚEmptyzFile is CLOSED)rC   rÖ   rð   r¶   r{  r  rt   r7  r•   rU  r`  ra  rB   )
rÜ   rº   ÚoutputÚlkeysr  r~  r@  rY   ÚdetailÚdstrrZ   rZ   r[   Úinfo†  s8   

€
€ýüþzHDFStore.infoc                 C  s   | j st| j› d�ƒ‚d S )Nz file is not open!)r¶   r   rÖ   rà   rZ   rZ   r[   râ   »  s   ÿzHDFStore._check_if_openr—   c              
   C  s>   z	t | ¡  }W |S  ty } z	td|› d�ƒ|‚d}~ww )zvalidate / deprecate formatsz#invalid HDFStore format specified [rB  N)Ú_FORMAT_MAPÚlowerrï   r¼   )rÜ   r—   rf  rZ   rZ   r[   r\  ¿  s   ý€ÿzHDFStore._validate_formatrT   úDataFrame | Series | Noner]   c              
   C  s
  |durt |ttfƒstdƒ‚tt|jddƒƒ}tt|jddƒƒ}|du rZ|du rHtƒ  tdus2J ‚t|ddƒs?t |tj	j
ƒrDd}d}ntdƒ‚t |tƒrPd	}nd
}|dkrZ|d7 }d|vrŽttdœ}z|| }	W n ty… }
 ztd|› dt|ƒ› d|› �ƒ|
‚d}
~
ww |	| |||d�S |du rÑ|durÑ|dkr´t|ddƒ}|dur³|jdkr¬d}n%|jdkr³d}n|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 n tyü }
 ztd|› dt|ƒ› d|› �ƒ|
‚d}
~
ww |	| |||d�S )z"return a suitable class to operateNz(value must be None, Series, or DataFramer�  Ú
table_typer{   Úframe_tableÚgeneric_tablezKcannot create a storer if the object is not existing nor a value are passedÚseriesÚframeÚ_table)r¸  r¹  z=cannot properly create the storer for: [_STORER_MAP] [group->ú,value->z	,format->©r]   rŸ   Úseries_tabler˜   rj   Úappendable_seriesÚappendable_multiseriesÚappendable_frameÚappendable_multiframe)r·  r¾  r¿  rÀ  rÁ  Úwormz<cannot properly create the storer for: [_TABLE_MAP] [group->)rU   r1   r+   r¼   r\   r“  r”  rŠ   r„   r{   r  ÚSeriesFixedÚ
FrameFixedrï   rð   ÚnlevelsÚGenericTableÚAppendableSeriesTableÚAppendableMultiSeriesTableÚAppendableFrameTableÚAppendableMultiFrameTableÚ	WORMTable)rÜ   rÈ   r—   r�   r]   rŸ   ÚptÚttÚ_STORER_MAPÚclsrf  r˜   Ú
_TABLE_MAPrZ   rZ   r[   r1  É  s¢   ÿÿ

ÿÿÿÿý€ÿ

€

úÿÿÿÿý€ÿzHDFStore._create_storerc                 C  sÖ   t |dd ƒr|dks|rd S |  ||¡}| j|||||d�}|r9|jr-|jr1|dkr1|jr1tdƒ‚|js8| ¡  n| ¡  |jsF|rFtdƒ‚|j||||||	|
||||||d� t|t	ƒrg|ri|j
|d� d S d S d S )	NÚemptyr{   r¼  rz   zCan only append to Tablesz0Compression not supported on Fixed format stores)Úobjrh  r•   r”   r’   rÒ   r™   r²   ri  r›   r¡   r�   rZ  )r¯   )r“  Ú_identify_groupr1  rT  Ú	is_existsrµ   Úset_object_infoÚwriterU   r  rŽ  )rÜ   rŽ   r�   r—   rh  r˜   r•   r”   r’   rÒ   r™   r²   ri  r›   r¡   r�   r]   rŸ   rZ  rÈ   rY   rZ   rZ   r[   r]  $  s>   €
óÿzHDFStore._write_to_grouprÈ   rJ   c                 C  s   |   |¡}| ¡  | ¡ S ra   )r1  r2  r(  )rÜ   rÈ   rY   rZ   rZ   r[   r%  b  s   
zHDFStore._read_groupc                 C  sN   |   |¡}| jdusJ ‚|dur|s| jj|dd� d}|du r%|  |¡}|S )z@Identify HDF5 group based on key, delete/create group if needed.NTr^  )ró   rÐ   Úremove_nodeÚ_create_nodes_and_group)rÜ   rŽ   r•   rÈ   rZ   rZ   r[   rÓ  g  s   

zHDFStore._identify_groupc                 C  sv   | j dusJ ‚| d¡}d}|D ](}t|ƒsq|}| d¡s"|d7 }||7 }|  |¡}|du r6| j  ||¡}|}q|S )z,Create nodes from key and return group name.Nr  )rÐ   Úsplitrt   Úendswithró   Úcreate_group)rÜ   rŽ   Úpathsrº   ÚpÚnew_pathrÈ   rZ   rZ   r[   rØ  y  s   


z HDFStore._create_nodes_and_group)r‹   NNF)r‘   r`   r’   r“   rÒ   r–   r_   r    ©r_   r`   ©rŽ   r`   )rŽ   r`   r_   r    )rf   r`   )rŽ   r`   r_   r–   ©r_   ri   )r_   rP   )rÿ   r   r  r  r  r  r_   r    )r  )r  r`   r_   r	  )r_   r  )r_   r  )r‹   )r‘   r`   r_   r    ©r_   r    ©r_   r–   ©F)r   r–   r_   r    )NNNNFNF)rŽ   r`   r±   r–   r²   r“   r´   r–   ©NNN©rŽ   r`   r­   r“   r®   r“   ©NN)rŽ   r`   r;  r`   r­   r“   r®   r“   )NNNNNFNF)r±   r–   r²   r“   r´   r–   )NTFNNNNNNrƒ   TF)rŽ   r`   r�   r�   r˜   r–   r•   r–   r’   r“   r™   rš   r�   rž   rŸ   r`   rZ  r–   r›   r–   r_   r    )NNTTNNNNNNNNNNrƒ   )rŽ   r`   r�   r�   r˜   rg  r•   r–   r’   r“   r™   rš   r²   r“   r›   rœ   r�   rž   rŸ   r`   r_   r    )NNF)rj  rk  r›   r–   r_   r    )rŽ   r`   rŒ  r“   r�  r^   r_   r    )r_   rr   )r  )ru   r`   r_   r–  )rŽ   r`   r_   r�  )rŽ   r`   r_   r¡  )r  TNNNFT)r‘   r`   r¢  r–   r’   r“   rÒ   r–   r£  r–   r_   r©   )r—   r`   r_   r`   )NNrT   rƒ   )r�   r´  r]   r`   rŸ   r`   r_   r¡  )NTFNNNNNNFNNNrƒ   T)rŽ   r`   r�   r�   r˜   rg  r•   r–   r’   r“   r™   rš   r²   r“   r›   r–   rŸ   r`   rZ  r–   r_   r    )rÈ   rJ   )rŽ   r`   r•   r–   r_   rJ   )rŽ   r`   r_   rJ   )1rñ   Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__rÝ   rá   Úpropertyrã   rä   ré   rë   rí   rò   rõ   r÷   rü   rý   r  r  r  r  rÛ   rÃ   r¶   r!  rç   rÁ   r:  r=  rY  r¨   rì   r•   r‹  r�  r¾   rœ  ró   r7  rª  r±  râ   r\  r1  r]  r%  rÓ  rØ  rZ   rZ   rZ   r[   r©   ò  s
  
 Aú
!











*

-
 ÷`û$û+ö}ñL=îkùdû
('
<
÷
;
5
ú`í
>
r©   c                   @  s`   e Zd ZU dZded< ded< ded< 							dddd„Zddd„Zddd„Zdddd„ZdS )r3  aa  
    Define the iteration interface on a table

    Parameters
    ----------
    store : HDFStore
    s     : the referred storer
    func  : the function to execute the query
    where : the where of the query
    nrows : the rows to iterate on
    start : the passed start value (default is None)
    stop  : the passed stop value (default is None)
    iterator : bool, default False
        Whether to use the default iterator.
    chunksize : the passed chunking value (default is 100000)
    auto_close : bool, default False
        Whether to automatically close the store at the end of iteration.
    r“   r²   r©   r£   r¡  rY   NFr±   r–   r´   r_   r    c                 C  sš   || _ || _|| _|| _| jjr'|d u rd}|d u rd}|d u r"|}t||ƒ}|| _|| _|| _d | _	|s9|	d urE|	d u r?d}	t
|	ƒ| _nd | _|
| _d S )Nr   é † )r£   rY   r.  ru   rT  Úminr0  r­   r®   rP  ri   r²   r´   )rÜ   r£   rY   r.  ru   r0  r­   r®   r±   r²   r´   rZ   rZ   r[   rÝ   §  s,   

zTableIterator.__init__rE   c                 c  s€   � | j }| jd u rtdƒ‚|| jk r:t|| j | jƒ}|  d d | j||… ¡}|}|d u s1t|ƒs2q|V  || jk s|  ¡  d S )Nz*Cannot iterate until get_result is called.)	r­   rP  rµ   r®   rî  r²   r.  rt   rÃ   )rÜ   rÎ   r®   r�   rZ   rZ   r[   r  Ñ  s   €


ù	zTableIterator.__iter__c                 C  s   | j r
| j ¡  d S d S ra   )r´   r£   rÃ   rà   rZ   rZ   r[   rÃ   á  s   ÿzTableIterator.closerP  c                 C  sŠ   | j d urt| jtƒstdƒ‚| jj| jd�| _| S |r3t| jtƒs&tdƒ‚| jj| j| j| j	d�}n| j}|  
| j| j	|¡}|  ¡  |S )Nz0can only use an iterator or chunksize on a table)ru   z$can only read_coordinates on a tabler6  )r²   rU   rY   r  r¼   r8  ru   rP  r­   r®   r.  rÃ   )rÜ   rP  ru   ÚresultsrZ   rZ   r[   r4  å  s   
ÿzTableIterator.get_result)NNFNF)r£   r©   rY   r¡  r±   r–   r²   r“   r´   r–   r_   r    ©r_   rE   râ  rä  )rP  r–   )	rñ   rè  ré  rê  rë  rÝ   r  rÃ   r4  rZ   rZ   rZ   r[   r3  �  s   
 	õ
*
r3  c                   @  s\  e Zd ZU dZdZded< dZded< g d¢Z													dMdNdd„Ze	dOdd„ƒZ
e	dPdd„ƒZdQdd„ZdPdd„ZdRdd„ZdSdd„Ze	dSd d!„ƒZdTd'd(„Zd)d*„ Ze	d+d,„ ƒZe	d-d.„ ƒZe	d/d0„ ƒZe	d1d2„ ƒZdUd4d5„ZdVdWd6d7„ZdWd8d9„ZdXd=d>„ZdVd?d@„ZdYdAdB„ZdWdCdD„ZdWdEdF„ZdWdGdH„ZdZdIdJ„Z dZdKdL„Z!dS )[ÚIndexCola  
    an index column description class

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

    Tr–   Úis_an_indexableÚis_data_indexable)ÚfreqÚtzÚ
index_nameNrf   r`   Úcnamer^   r_   r    c                 C  s    t |tƒs	tdƒ‚|| _|| _|| _|| _|p|| _|| _|| _	|| _
|	| _|
| _|| _|| _|| _|| _|d ur>|  |¡ t | jtƒsFJ ‚t | jtƒsNJ ‚d S )Nz`name` must be a str.)rU   r`   rµ   r~  r�  Útyprf   r÷  rK  Úposrô  rõ  rö  r„  r{   rÊ   ÚmetadataÚset_pos)rÜ   rf   r~  r�  rø  r÷  rK  rù  rô  rõ  rö  r„  r{   rÊ   rú  rZ   rZ   r[   rÝ     s(   


zIndexCol.__init__ri   c                 C  ó   | j jS ra   )rø  Úitemsizerà   rZ   rZ   r[   rý  <  s   zIndexCol.itemsizec                 C  ó   | j › d�S )NÚ_kindre   rà   rZ   rZ   r[   Ú	kind_attrA  ó   zIndexCol.kind_attrrù  c                 C  s,   || _ |dur| jdur|| j_dS dS dS )z,set the position of this column in the TableN)rù  rø  Ú_v_pos)rÜ   rù  rZ   rZ   r[   rû  E  s   ÿzIndexCol.set_posc                 C  ó@   t tt| j| j| j| j| jfƒƒ}d dd„ t	g d¢|ƒD ƒ¡S )Nú,c                 S  ó   g | ]\}}|› d |› �‘qS ©z->rZ   rq  rZ   rZ   r[   rq   P  ó    ÿÿz%IndexCol.__repr__.<locals>.<listcomp>)rf   r÷  rK  rù  r�  )
rs   ÚmaprC   rf   r÷  rK  rù  r�  ÚjoinrS  ©rÜ   ÚtemprZ   rZ   r[   rü   K  s   ÿþÿzIndexCol.__repr__ÚotherÚobjectc                   ó   t ‡ ‡fdd„dD ƒƒS )úcompare 2 col itemsc                 3  ó(   � | ]}t ˆ|d ƒt ˆ |d ƒkV  qd S ra   ©r“  r¦  ©r  rÜ   rZ   r[   ro  X  ó
   € ÿ
ÿz"IndexCol.__eq__.<locals>.<genexpr>)rf   r÷  rK  rù  ©rl  ©rÜ   r  rZ   r  r[   Ú__eq__V  ó   þzIndexCol.__eq__c                 C  s   |   |¡ S ra   )r  r  rZ   rZ   r[   Ú__ne__]  rø   zIndexCol.__ne__c                 C  s"   t | jdƒsdS t| jj| jƒjS )z%return whether I am an indexed columnrn  F)Úhasattrr{   r“  rn  r÷  r¥  rà   rZ   rZ   r[   r¥  `  s   zIndexCol.is_indexedr~  ú
np.ndarrayr]   rŸ   ú3tuple[np.ndarray, np.ndarray] | tuple[Index, Index]c              
   C  st  t |tjƒsJ t|ƒƒ‚|jjdur|| j  ¡ }t| j	ƒ}t
||||ƒ}i }t| jƒ|d< | jdur:t| jƒ|d< t}t |jd¡sIt |jtƒrLt}n|jdkrYd|v rYdd„ }z
||fi |¤Ž}W nL ty— }	 z(|dkrŒtd	ƒrŒt|	ƒ d
¡rŒtrŒ||fdtdtjd�i|¤Ž}n‚ W Y d}	~	nd}	~	w ty¯   d|v r¥d|d< ||fi |¤Ž}Y nw t|| jƒ}
|
|
fS )zV
        Convert the data from this selection to the appropriate pandas type.
        Nrf   rô  ÚMÚi8c                 [  s    t j| | dd ¡d� |d ¡S )Nrô  )rô  rf   )r/   Úfrom_ordinalsrç   Ú_rename)rD  ÚkwdsrZ   rZ   r[   r¥   ˆ  s    ÿÿz"IndexCol.convert.<locals>.<lambda>Úsurrogatepassúfuture.infer_stringúsurrogates not allowedÚdtypeÚpython©ÚstorageÚna_value)rU   rV   Úndarrayrð   r$  Úfieldsr÷  rª  r\   r�  Ú_maybe_convertrö  rô  r-   r   Úis_np_dtyper'   r,   ÚUnicodeEncodeErrorr   r`   rÚ  r   r2   Únanrµ   Ú_set_tzrõ  )rÜ   r~  r¡   r]   rŸ   Úval_kindrÄ   ÚfactoryÚnew_pd_indexrf  Úfinal_pd_indexrZ   rZ   r[   Úconverth  sV   

ÿÿþýÿþýú€ûzIndexCol.convertc                 C  rÞ   )zreturn the values©r~  rà   rZ   rZ   r[   Ú	take_data¨  rå   zIndexCol.take_datac                 C  rü  ra   )r{   r”  rà   rZ   rZ   r[   Úattrs¬  ó   zIndexCol.attrsc                 C  rü  ra   ©r{   Údescriptionrà   rZ   rZ   r[   r:  °  r8  zIndexCol.descriptionc                 C  s   t | j| jdƒS )z!return my current col descriptionN)r“  r:  r÷  rà   rZ   rZ   r[   Úcol´  ó   zIndexCol.colc                 C  rÞ   ©zreturn my cython valuesr5  rà   rZ   rZ   r[   Úcvalues¹  ó   zIndexCol.cvaluesrE   c                 C  s
   t | jƒS ra   )r  r~  rà   rZ   rZ   r[   r  ¾  rê   zIndexCol.__iter__c                 C  s\   t | jƒdkr(t|tƒr| | j¡}|dur*| jj|k r,tƒ j	|| j
d�| _dS dS dS dS )zŸ
        maybe set a string col itemsize:
            min_itemsize can be an integer or a dict with this columns name
            with an integer size
        ÚstringN)rý  rù  )r\   r�  rU   rk  rç   rf   rø  rý  rŠ   Ú	StringColrù  )rÜ   r™   rZ   rZ   r[   Úmaybe_set_sizeÁ  s   
ûzIndexCol.maybe_set_sizec                 C  ó   d S ra   rZ   rà   rZ   rZ   r[   Úvalidate_namesÎ  rþ   zIndexCol.validate_namesÚhandlerÚAppendableTabler•   c                 C  s:   |j | _ |  ¡  |  |¡ |  |¡ |  |¡ |  ¡  d S ra   )r{   Úvalidate_colÚvalidate_attrÚvalidate_metadataÚwrite_metadataÚset_attr)rÜ   rE  r•   rZ   rZ   r[   Úvalidate_and_setÑ  s   


zIndexCol.validate_and_setc                 C  s^   t | jƒdkr-| j}|dur-|du r| j}|j|k r*td|› d| j› d|j› d�ƒ‚|jS dS )z:validate this column: return the compared against itemsizer@  Nz#Trying to store a string with len [z] in [z)] column but
this column has a limit of [zC]!
Consider using min_itemsize to preset the sizes on these columns)r\   r�  r;  rý  rµ   r÷  )rÜ   rý  ÚcrZ   rZ   r[   rG  Ù  s   
ÿþÿzIndexCol.validate_colc                 C  sJ   |rt | j| jd ƒ}|d ur!|| jkr#td|› d| j› d�ƒ‚d S d S d S )Nzincompatible kind in col [ú - rB  )r“  r7  r   r�  r¼   )rÜ   r•   Úexisting_kindrZ   rZ   r[   rH  ì  s   ÿýzIndexCol.validate_attrc                 C  sÆ   | j D ]]}t| |dƒ}| | ji ¡}| |¡}||v rT|durT||krT|dv rBt|||f }tj|tt	ƒ d� d||< t
| |dƒ qtd| j› d|› d|› d|› d�	ƒ‚|dus\|dur`|||< qdS )	z
        set/update the info for this indexable with the key/value
        if there is a conflict raise/warn as needed
        N)rô  rö  ©Ú
stacklevelzinvalid info for [z] for [z], existing_value [z] conflicts with new value [rB  )Ú_info_fieldsr“  Ú
setdefaultrf   rç   rx   ÚwarningsÚwarnr   r   Úsetattrrµ   )rÜ   r±  rŽ   r�   ÚidxÚexisting_valueÚwsrZ   rZ   r[   Úupdate_infoõ  s.   

ÿÿþÿ€èzIndexCol.update_infoc                 C  s(   |  | j¡}|dur| j |¡ dS dS )z!set my state from the passed infoN)rç   rf   Ú__dict__Úupdate)rÜ   r±  rW  rZ   rZ   r[   Úset_info	  s   ÿzIndexCol.set_infoc                 C  s   t | j| j| jƒ dS )zset the kind for this columnN)rV  r7  r   r�  rà   rZ   rZ   r[   rK  	  ó   zIndexCol.set_attrc                 C  sT   | j dkr"| j}| | j¡}|dur$|dur&t||ddd�s(tdƒ‚dS dS dS dS )z:validate that kind=category does not change the categoriesÚcategoryNT©Ú
strict_nanÚdtype_equalzEcannot append a categorical with different categories to the existing)rÊ   rú  Úread_metadatar÷  r*   rµ   )rÜ   rE  Únew_metadataÚcur_metadatarZ   rZ   r[   rI  	  s   
ÿÿÿözIndexCol.validate_metadatac                 C  s"   | j dur| | j| j ¡ dS dS )zset the meta dataN)rú  rJ  r÷  )rÜ   rE  rZ   rZ   r[   rJ  /	  s   
ÿzIndexCol.write_metadata)NNNNNNNNNNNNN)rf   r`   r÷  r^   r_   r    rá  rß  )rù  ri   r_   r    ©r  r  r_   r–   rã  )r~  r  r]   r`   rŸ   r`   r_   r  rð  ra   râ  )rE  rF  r•   r–   r_   r    )r•   r–   r_   r    )rE  rF  r_   r    )"rñ   rè  ré  rê  rò  rë  ró  rR  rÝ   rì  rý  r   rû  rü   r  r  r¥  r4  r6  r7  r:  r;  r>  r  rB  rD  rL  rG  rH  rZ  r]  rK  rI  rJ  rZ   rZ   rZ   r[   rñ  ÿ  sd   
 ñ+




@









	


rñ  c                   @  s2   e Zd ZdZeddd„ƒZddd„Zddd„ZdS )ÚGenericIndexColz:an index which is not represented in the data of the tabler_   r–   c                 C  ó   dS ©NFrZ   rà   rZ   rZ   r[   r¥  8	  ó   zGenericIndexCol.is_indexedr~  r  r]   r`   rŸ   útuple[Index, Index]c                 C  s,   t |tjƒsJ t|ƒƒ‚tt|ƒƒ}||fS )zÛ
        Convert the data from this selection to the appropriate pandas type.

        Parameters
        ----------
        values : np.ndarray
        nan_rep : str
        encoding : str
        errors : str
        )rU   rV   r)  rð   r0   rt   )rÜ   r~  r¡   r]   rŸ   r˜   rZ   rZ   r[   r4  <	  s   zGenericIndexCol.convertr    c                 C  rC  ra   rZ   rà   rZ   rZ   r[   rK  N	  rþ   zGenericIndexCol.set_attrNrã  )r~  r  r]   r`   rŸ   r`   r_   rk  râ  )rñ   rè  ré  rê  rì  r¥  r4  rK  rZ   rZ   rZ   r[   rg  5	  s    
rg  c                      s  e Zd ZdZdZdZddgZ												d>d?‡ fdd„Zed@dd„ƒZ	ed@dd„ƒZ
d@dd„ZdAdd„ZdBdd„Zdd „ ZedCd#d$„ƒZed%d&„ ƒZedDd)d*„ƒZedEd+d,„ƒZed-d.„ ƒZed/d0„ ƒZed1d2„ ƒZed3d4„ ƒZdFd5d6„ZdGd:d;„ZdFd<d=„Z‡  ZS )HÚDataCola3  
    a data holding column, by definition this is not indexable

    Parameters
    ----------
    data   : the actual data
    cname  : the column name in the table to hold the data (typically
                values)
    meta   : a string description of the metadata
    metadata : the actual metadata
    Frõ  r„  Nrf   r`   r÷  r^   r$  úDtypeArg | Noner_   r    c                   s2   t ƒ j|||||||||	|
|d� || _|| _d S )N)rf   r~  r�  rø  rù  r÷  rõ  r„  r{   rÊ   rú  )ÚsuperrÝ   r$  r©  )rÜ   rf   r~  r�  rø  r÷  rù  rõ  r„  r{   rÊ   rú  r$  r©  ©Ú	__class__rZ   r[   rÝ   c	  s   õ
zDataCol.__init__c                 C  rþ  )NÚ_dtypere   rà   rZ   rZ   r[   Ú
dtype_attrƒ	  r  zDataCol.dtype_attrc                 C  rþ  )NÚ_metare   rà   rZ   rZ   r[   Ú	meta_attr‡	  r  zDataCol.meta_attrc                 C  r  )Nr  c                 S  r  r  rZ   rq  rZ   rZ   r[   rq   ’	  r  z$DataCol.__repr__.<locals>.<listcomp>)rf   r÷  r$  r�  Úshape)
rs   r  rC   rf   r÷  r$  r�  ru  r	  rS  r
  rZ   rZ   r[   rü   ‹	  s   ÿÿþÿzDataCol.__repr__r  r  r–   c                   r  )r  c                 3  r  ra   r  r¦  r  rZ   r[   ro  š	  r  z!DataCol.__eq__.<locals>.<genexpr>)rf   r÷  r$  rù  r  r  rZ   r  r[   r  ˜	  r  zDataCol.__eq__r©  rL   c                 C  s@   |d usJ ‚| j d u sJ ‚t|ƒ\}}|| _|| _ t|ƒ| _d S ra   )r$  Ú_get_data_and_dtype_namer©  Ú_dtype_to_kindr�  )rÜ   r©  Ú
dtype_namerZ   rZ   r[   Úset_dataŸ	  s   zDataCol.set_datac                 C  rÞ   )zreturn the data©r©  rà   rZ   rZ   r[   r6  ©	  rå   zDataCol.take_datar~  rH   c                 C  sÖ   |j }|j}|j}|jdkrd|jf}t|tƒr&|j}| j||j j	d�}|S t
 |d¡s1t|tƒr8|  |¡}|S t
 |d¡rE|  |¡}|S t|ƒrUtƒ j||d d�}|S t|ƒra|  ||¡}|S | j||j	d�}|S )zW
        Get an appropriately typed and shaped pytables.Col object for values.
        rj   ©r�  r  Úmr   ©rý  ru  )r$  rý  ru  rw  ÚsizerU   r6   ÚcodesÚget_atom_datarf   r   r,  r'   Úget_atom_datetime64Úget_atom_timedelta64r"   rŠ   Ú
ComplexColr$   Úget_atom_string)rÏ  r~  r$  rý  ru  r  ÚatomrZ   rZ   r[   Ú	_get_atom­	  s.   


õ

÷
ùûþzDataCol._get_atomc                 C  s   t ƒ j||d d�S )Nr   r}  ©rŠ   rA  ©rÏ  ru  rý  rZ   rZ   r[   r„  Í	  ó   zDataCol.get_atom_stringr�  ú	type[Col]c                 C  sR   |  d¡r|dd… }d|› d�}n|  d¡rd}n	| ¡ }|› d�}ttƒ |ƒS )z0return the PyTables column class for this columnÚuinté   NÚUIntrH   ÚperiodÚInt64Col)rž  Ú
capitalizer“  rŠ   )rÏ  r�  Úk4Úcol_nameÚkcaprZ   rZ   r[   Úget_atom_coltypeÑ	  s   


zDataCol.get_atom_coltypec                 C  s   | j |d�|d d�S )Nr{  r   ©ru  ©r”  ©rÏ  ru  r�  rZ   rZ   r[   r€  à	  r^  zDataCol.get_atom_datac                 C  ó   t ƒ j|d d�S ©Nr   r•  ©rŠ   r�  ©rÏ  ru  rZ   rZ   r[   r�  ä	  ó   zDataCol.get_atom_datetime64c                 C  r˜  r™  rš  r›  rZ   rZ   r[   r‚  è	  rœ  zDataCol.get_atom_timedelta64c                 C  ó   t | jdd ƒS )Nru  )r“  r©  rà   rZ   rZ   r[   ru  ì	  ó   zDataCol.shapec                 C  rÞ   r=  rz  rà   rZ   rZ   r[   r>  ð	  r?  zDataCol.cvaluesc                 C  sh   |r.t | j| jdƒ}|dur|t| jƒkrtdƒ‚t | j| jdƒ}|dur0|| jkr2tdƒ‚dS dS dS )zAvalidate that we have the same order as the existing & same dtypeNz4appended items do not match existing items in table!z@appended items dtype do not match existing items dtype in table!)r“  r7  r   rr   r~  rµ   rr  r$  )rÜ   r•   Úexisting_fieldsÚexisting_dtyperZ   rZ   r[   rH  õ	  s   ÿùzDataCol.validate_attrr  r]   rŸ   c                 C  s  t |tjƒsJ t|ƒƒ‚|jjdur|| j }| jdusJ ‚| jdu r.t|ƒ\}}t	|ƒ}n|}| j}| j
}t |tjƒs>J ‚t| jƒ}| j}	| j}
| j}|dusRJ ‚t|ƒ}| d¡rct||dd�}n‹|dkrotj|dd�}n|dkr—ztjd	d
„ |D ƒtd�}W nl ty–   tjdd
„ |D ƒtd�}Y nXw |dkrÔ|	}| ¡ }|du r­tg tjd�}nt|ƒ}| ¡ rÊ||  }||dk  | t¡ ¡ j8  < tj|||
dd�}nz	|j|dd�}W n t yí   |jddd�}Y nw t|ƒdk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  ó   g | ]}t  |¡‘qS rZ   ©r   Úfromordinal©rm   rr  rZ   rZ   r[   rq   9
  rA  z#DataCol.convert.<locals>.<listcomp>c                 S  r§  rZ   ©r   Úfromtimestamprª  rZ   rZ   r[   rq   =
  rA  r_  éÿÿÿÿF)Ú
categoriesr„  Úvalidate©rª  ÚOr@  ©r¡   r]   rŸ   )#rU   rV   r)  rð   r$  r*  r÷  rø  rv  rw  r�  r\   rÊ   rú  r„  rõ  rž  r/  Úasarrayr  rµ   Úravelr-   Úfloat64r5   ÚanyÚastyperi   ÚcumsumÚ_valuesr6   Ú
from_codesr¼   Ú_unconvert_string_arrayr~  )rÜ   r~  r¡   r]   rŸ   Ú	convertedrx  r�  rÊ   rú  r„  rõ  r$  r®  r  ÚmaskrZ   rZ   r[   r4  
  sj   





ÿ
ÿÿ
 ÿÿÿ
zDataCol.convertc                 C  sH   t | j| j| jƒ t | j| j| jƒ | jdusJ ‚t | j| j| jƒ dS )zset the data for this columnN)rV  r7  r   r~  rt  rÊ   r$  rr  rà   rZ   rZ   r[   rK  f
  s   zDataCol.set_attr)NNNNNNNNNNNN)rf   r`   r÷  r^   r$  rm  r_   r    rß  rf  )r©  rL   r_   r    )r~  rL   r_   rH   )r�  r`   r_   rŠ  ©r�  r`   r_   rH   râ  )r~  r  r]   r`   rŸ   r`   )rñ   rè  ré  rê  rò  ró  rR  rÝ   rì  rr  rt  rü   r  ry  r6  Úclassmethodr†  r„  r”  r€  r�  r‚  ru  r>  rH  r4  rK  Ú__classcell__rZ   rZ   ro  r[   rl  R	  sZ    ò 










drl  c                   @  sP   e Zd ZdZdZddd„Zedd„ ƒZeddd„ƒZedd„ ƒZ	edd„ ƒZ
dS )ÚDataIndexableColz+represent a data column that can be indexedTr_   r    c                 C  s   t t| jƒjƒstdƒ‚d S )Nú-cannot have non-object label DataIndexableCol)r$   r-   r~  r$  rµ   rà   rZ   rZ   r[   rD  s
  s   þzDataIndexableCol.validate_namesc                 C  s   t ƒ j|d�S )N)rý  r‡  rˆ  rZ   rZ   r[   r„  x
  rž  z DataIndexableCol.get_atom_stringr�  r`   rH   c                 C  s   | j |d�ƒ S )Nr{  r–  r—  rZ   rZ   r[   r€  |
  rž  zDataIndexableCol.get_atom_datac                 C  ó
   t ƒ  ¡ S ra   rš  r›  rZ   rZ   r[   r�  €
  ó   
z$DataIndexableCol.get_atom_datetime64c                 C  rÃ  ra   rš  r›  rZ   rZ   r[   r‚  „
  rÄ  z%DataIndexableCol.get_atom_timedelta64Nrâ  r¾  )rñ   rè  ré  rê  ró  rD  r¿  r„  r€  r�  r‚  rZ   rZ   rZ   r[   rÁ  n
  s    


rÁ  c                   @  s   e Zd ZdZdS )ÚGenericDataIndexableColz(represent a generic pytables data columnN)rñ   rè  ré  rê  rZ   rZ   rZ   r[   rÅ  ‰
  s    rÅ  c                   @  s~  e Zd ZU dZded< dZded< ded< ded	< d
ed< dZded< 		dPdQdd„ZedRdd„ƒZ	edSdd„ƒZ
edd „ ƒZdTd!d"„ZdUd#d$„ZdVd%d&„Zed'd(„ ƒZed)d*„ ƒZed+d,„ ƒZed-d.„ ƒZedWd/d0„ƒZedRd1d2„ƒZed3d4„ ƒZdUd5d6„ZdUd7d8„Zed9d:„ ƒZedRd;d<„ƒZed=d>„ ƒZdXd@dA„ZdYdUdCdD„ZdRdEdF„Z	B	B	B	BdZd[dJdK„ZdUdLdM„Z	Bd\d]dNdO„Z dBS )^ÚFixedzø
    represent an object in my store
    facilitate read/write of various types of objects
    this is an abstract base class

    Parameters
    ----------
    parent : HDFStore
    group : Node
        The group node where the table resides.
    r`   Úpandas_kindrz   Úformat_typeútype[DataFrame | Series]Úobj_typeri   rw  r©   rÏ   Fr–   rT  rT   rƒ   rÈ   rJ   r]   r^   rŸ   r_   r    c                 C  sZ   t |tƒsJ t|ƒƒ‚td usJ ‚t |tjƒsJ t|ƒƒ‚|| _|| _t|ƒ| _|| _	d S ra   )
rU   r©   rð   r„   rJ   rÏ   rÈ   rd   r]   rŸ   )rÜ   rÏ   rÈ   r]   rŸ   rZ   rZ   r[   rÝ   ¡
  s   

zFixed.__init__c                 C  s*   | j d dko| j d dko| j d dk S )Nr   rj   é
   é   )Úversionrà   rZ   rZ   r[   Úis_old_version°
  s   *zFixed.is_old_versionútuple[int, int, int]c                 C  sf   t t| jjddƒƒ}ztdd„ | d¡D ƒƒ}t|ƒdkr$|d }W |S W |S  ty2   d}Y |S w )	zcompute and set our versionÚpandas_versionNc                 s  s   � | ]}t |ƒV  qd S ra   ©ri   rC  rZ   rZ   r[   ro  ¹
  s   € z Fixed.version.<locals>.<genexpr>Ú.rÌ  rF  )r   r   r   )r\   r“  rÈ   r”  rs   rÙ  rt   r†   )rÜ   rÍ  rZ   rZ   r[   rÍ  ´
  s   
üþþzFixed.versionc                 C  s   t t| jjdd ƒƒS )Nr�  )r\   r“  rÈ   r”  rà   rZ   rZ   r[   r�  À
  r‰  zFixed.pandas_typec                 C  s^   |   ¡  | j}|dur,t|ttfƒr"d dd„ |D ƒ¡}d|› d�}| jd›d|› d	�S | jS )
ú(return a pretty representation of myselfNr  c                 S  ó   g | ]}t |ƒ‘qS rZ   ©rC   rC  rZ   rZ   r[   rq   Ê
  ó    z"Fixed.__repr__.<locals>.<listcomp>ú[rB  ú12.12z	 (shape->ú))r2  ru  rU   rr   rs   r	  r�  )rÜ   rY   ÚjshaperZ   rZ   r[   rü   Ä
  s   zFixed.__repr__c                 C  s   t | jƒ| j_t tƒ| j_dS )zset my pandas type & versionN)r`   rÇ  r7  r�  Ú_versionrÐ  rà   rZ   rZ   r[   rÕ  Ï
  s   zFixed.set_object_infoc                 C  s   t   | ¡}|S ra   r°  )rÜ   Únew_selfrZ   rZ   r[   rª  Ô
  s   
z
Fixed.copyc                 C  rÞ   ra   )r0  rà   rZ   rZ   r[   ru  Ø
  rå   zFixed.shapec                 C  rü  ra   ©rÈ   rÀ   rà   rZ   rZ   r[   rU  Ü
  r8  zFixed.pathnamec                 C  rü  ra   )rÏ   rÐ   rà   rZ   rZ   r[   rÐ   à
  r8  zFixed._handlec                 C  rü  ra   )rÏ   rÚ   rà   rZ   rZ   r[   rÚ   ä
  r8  zFixed._filtersc                 C  rü  ra   )rÏ   r×   rà   rZ   rZ   r[   r×   è
  r8  zFixed._complevelc                 C  rü  ra   )rÏ   rÙ   rà   rZ   rZ   r[   rÙ   ì
  r8  zFixed._fletcher32c                 C  rü  ra   )rÈ   r”  rà   rZ   rZ   r[   r7  ð
  r8  zFixed.attrsc                 C  rh  ©zset our object attributesNrZ   rà   rZ   rZ   r[   Ú	set_attrsô
  ó    zFixed.set_attrsc                 C  rh  )zget our object attributesNrZ   rà   rZ   rZ   r[   Ú	get_attrs÷
  rà  zFixed.get_attrsc                 C  rÞ   )zreturn my storable©rÈ   rà   rZ   rZ   r[   Ústorableú
  r?  zFixed.storablec                 C  rh  ri  rZ   rà   rZ   rZ   r[   rÔ  ÿ
  rj  zFixed.is_existsc                 C  r�  )Nr0  )r“  rã  rà   rZ   rZ   r[   r0    rž  zFixed.nrowsúLiteral[True] | Nonec                 C  s   |du rdS dS )z%validate against an existing storableNTrZ   r  rZ   rZ   r[   r¯    s   zFixed.validateNc                 C  rh  )ú+are we trying to operate on an old version?NrZ   )rÜ   ru   rZ   rZ   r[   Úvalidate_version  rà  zFixed.validate_versionc                 C  s   | j }|du r	dS |  ¡  dS )zr
        infer the axes of my storer
        return a boolean indicating if we have a valid storer or not
        NFT)rã  rá  )rÜ   rY   rZ   rZ   r[   r2    s
   zFixed.infer_axesr­   r“   r®   c                 C  ó   t dƒ‚)Nz>cannot read on an abstract storer: subclasses should implement©r¸   ©rÜ   ru   r¯   r­   r®   rZ   rZ   r[   r(    s   ÿz
Fixed.readc                 K  rç  )Nz?cannot write on an abstract storer: subclasses should implementrè  ©rÜ   rÒ  rÄ   rZ   rZ   r[   rÖ  &  s   ÿzFixed.writec                 C  s,   t  |||¡r| jj| jdd� dS tdƒ‚)zs
        support fully deleting the node in its entirety (only) - where
        specification must be None
        Tr^  Nz#cannot delete on an abstract storer)rc  rd  rÐ   r×  rÈ   r¼   )rÜ   ru   r­   r®   rZ   rZ   r[   re  +  s   zFixed.delete)rT   rƒ   )
rÏ   r©   rÈ   rJ   r]   r^   rŸ   r`   r_   r    rã  )r_   rÏ  rß  râ  )r_   rÆ  rá  )r_   rä  ra   ©NNNN©r­   r“   r®   r“   rå  )r­   r“   r®   r“   r_   r    )!rñ   rè  ré  rê  rë  rÈ  rT  rÝ   rì  rÎ  rÍ  r�  rü   rÕ  rª  ru  rU  rÐ   rÚ   r×   rÙ   r7  rß  rá  rã  rÔ  r0  r¯  ræ  r2  r(  rÖ  re  rZ   rZ   rZ   r[   rÆ  �
  sj   
 û














û
ÿrÆ  c                   @  sî   e Zd ZU dZedediZdd„ e ¡ D ƒZg Z	de
d< d<d
d„Zdd„ Zdd„ Zd=dd„Zed>dd„ƒZd=dd„Zd=dd„Zd=dd„Zd?d@d!d"„Z	d?dAd$d%„ZdBd'd(„ZdCd*d+„Z	d?dDd,d-„Z	d?dEd0d1„ZdFd4d5„Z	dGdHd:d;„ZdS )IÚGenericFixedza generified fixed versionÚdatetimerŽ  c                 C  s   i | ]\}}||“qS rZ   rZ   )rm   r@  rr  rZ   rZ   r[   rs  =  rA  zGenericFixed.<dictcomp>r	  Ú
attributesr_   r`   c                 C  s   | j  |d¡S )NÚ )Ú_index_type_maprç   )rÜ   rÏ  rZ   rZ   r[   Ú_class_to_aliasA  s   zGenericFixed._class_to_aliasc                 C  s   t |tƒr|S | j |t¡S ra   )rU   rð   Ú_reverse_index_maprç   r-   )rÜ   ÚaliasrZ   rZ   r[   Ú_alias_to_classD  s   
zGenericFixed._alias_to_classc                 C  s¸   |   tt|ddƒƒ¡}|tkrd	dd„}|}n|tkr#d	dd„}|}n|}i }d|v r7|d |d< |tu r7t}d|v rXt|d tƒrL|d  	d¡|d< n|d |d< |tu sXJ ‚||fS )
NÚindex_classrð  c                 S  s>   t j| j| j|d�}tj|d d�}|d ur| d¡ |¡}|S )N)r$  rô  re   ÚUTC)r7   Ú_simple_newr~  r$  r,   Útz_localizeÚ
tz_convert)r~  rô  rõ  ÚdtaÚresultrZ   rZ   r[   r|   S  s   
ÿz*GenericFixed._get_index_factory.<locals>.fc                 S  s$   t |ƒ}tj| |d�}tj|d d�S )Nr¦  re   )r)   r8   rø  r/   )r~  rô  rõ  r$  ÚparrrZ   rZ   r[   r|   `  s   rô  rõ  zutf-8rç  )
rõ  r\   r“  r,   r/   r-   r3   rU   ÚbytesrX   )rÜ   r7  rö  r|   r1  rÄ   rZ   rZ   r[   Ú_get_index_factoryJ  s*   ÿ


zGenericFixed._get_index_factoryr    c                 C  s$   |durt dƒ‚|durt dƒ‚dS )zE
        raise if any keywords are passed which are not-None
        Nzqcannot pass a column specification when reading a Fixed format store. this store must be selected in its entiretyzucannot pass a where specification when reading from a Fixed format store. this store must be selected in its entirety)r¼   )rÜ   r¯   ru   rZ   rZ   r[   Úvalidate_read{  s   ÿÿÿzGenericFixed.validate_readr–   c                 C  rh  )NTrZ   rà   rZ   rZ   r[   rÔ  Š  rj  zGenericFixed.is_existsc                 C  s   | j | j_ | j| j_dS rÞ  )r]   r7  rŸ   rà   rZ   rZ   r[   rß  Ž  s   
zGenericFixed.set_attrsc              	   C  sR   t t| jddƒƒ| _tt| jddƒƒ| _| jD ]}t| |tt| j|dƒƒƒ qdS )úretrieve our attributesr]   NrŸ   rƒ   )rd   r“  r7  r]   r\   rŸ   rï  rV  )rÜ   r  rZ   rZ   r[   rá  “  s
   
ÿzGenericFixed.get_attrsc                 K  r  ra   )rß  rê  rZ   rZ   r[   rÖ  š  rø   zGenericFixed.writeNrŽ   r­   r“   r®   c                 C  sò   ddl }t| j|ƒ}|j}t|ddƒ}t||jƒr2|d ||… }t|ddƒ}	|	dur1t||	d�}n@tt|ddƒƒ}	t|ddƒ}
|
durLtj	|
|	d�}n|||… }|	rg|	 
d¡rgt|d	dƒ}t||d
d�}n|	dkrrtj|dd�}|rw|jS |S )z2read an array for the specified node (off of groupr   NÚ
transposedFÚ
value_typer¦  ru  r¡  rõ  Tr¢  r¤  r¥  )r…   r“  rÈ   r”  rU   ÚVLArrayÚpd_arrayr\   rV   rÑ  rž  r/  r³  ÚT)rÜ   rŽ   r­   r®   r…   rô   r7  r  Úretr$  ru  rõ  rZ   rZ   r[   Ú
read_array�  s.   €zGenericFixed.read_arrayr-   c                 C  sd   t t| j|› d�ƒƒ}|dkr| j|||d�S |dkr+t| j|ƒ}| j|||d�}|S td|› �ƒ‚)NÚ_varietyÚmulti©r­   r®   Úregularzunrecognized index variety: )r\   r“  r7  Úread_multi_indexrÈ   Úread_index_noder¼   )rÜ   rŽ   r­   r®   Úvarietyrô   r˜   rZ   rZ   r[   Ú
read_indexÂ  s   zGenericFixed.read_indexr˜   c                 C  sê   t |tƒrt| j|› d�dƒ |  ||¡ d S t| j|› d�dƒ td|| j| jƒ}|  ||j	¡ t
| j|ƒ}|j|j_|j|j_t |ttfƒrQ|  t|ƒ¡|j_t |tttfƒr^|j|j_t |tƒrq|jd urst|jƒ|j_d S d S d S )Nr	  r
  r  r˜   )rU   r.   rV  r7  Úwrite_multi_indexÚ_convert_indexr]   rŸ   Úwrite_arrayr~  r“  rÈ   r�  r”  rf   r,   r/   rò  rð   rö  r3   rô  rõ  Ú_get_tz)rÜ   rŽ   r˜   r¼  rô   rZ   rZ   r[   Úwrite_indexÐ  s    



ÿzGenericFixed.write_indexr.   c                 C  sÒ   t | j|› d�|jƒ tt|j|j|jƒƒD ]P\}\}}}t|j	t
ƒr'tdƒ‚|› d|› �}t||| j| jƒ}|  ||j¡ t| j|ƒ}	|j|	j_||	j_t |	j|› d|› �|ƒ |› d|› �}
|  |
|¡ qd S )NÚ_nlevelsz=Saving a MultiIndex with an extension dtype is not supported.Ú_levelÚ_nameÚ_label)rV  r7  rÅ  Ú	enumeraterS  Úlevelsr  ÚnamesrU   r$  r(   r¸   r  r]   rŸ   r  r~  r“  rÈ   r�  r”  rf   )rÜ   rŽ   r˜   ÚiÚlevÚlevel_codesrf   Ú	level_keyÚ
conv_levelrô   Ú	label_keyrZ   rZ   r[   r  ç  s$   ÿÿ
ìzGenericFixed.write_multi_indexc                 C  s¤   t | j|› d�ƒ}g }g }g }t|ƒD ]6}|› d|› �}	t | j|	ƒ}
| j|
||d�}| |¡ | |j¡ |› d|› �}| j|||d�}| |¡ qt|||dd�S )Nr  r  r  r  T)r  r  r  rL  )	r“  r7  rv  rÈ   r  r•   rf   r  r.   )rÜ   rŽ   r­   r®   rÅ  r  r  r  r  r   rô   r  r"  r  rZ   rZ   r[   r     s    
ÿzGenericFixed.read_multi_indexrô   rJ   c              
   C  sX  |||… }d|j v rt |j j¡dkrtj|j j|j jd�}t|j jƒ}d }d|j v r6t|j j	ƒ}t|ƒ}|j }|  
|¡\}}	|dv rW|t||| j| jd�fdti|	¤Ž}
nPz|t||| j| jd�fi |	¤Ž}
W n= ty¦ } z1| jdkr›td	ƒr›t|ƒ d
¡r›tr›|t||| j| jd�fdtdtjd�i|	¤Ž}
n‚ W Y d }~nd }~ww ||
_	|
S )Nru  r   r¦  rf   )r   r  r¼  r$  r!  r"  r#  r%  r&  )r”  rV   Úprodru  rÑ  r  r\   r�  rg   rf   rÿ  Ú_unconvert_indexr]   rŸ   r  r-  r   r`   rÚ  r   r2   r.  )rÜ   rô   r­   r®   r©  r�  rf   r7  r1  rÄ   r˜   rf  rZ   rZ   r[   r    sf   
ÿÿüûÿÿ
ü
ÿþýÿÿüûø€ùzGenericFixed.read_index_noder�   rL   c                 C  sJ   t  d|j ¡}| j | j||¡ t| j|ƒ}t|jƒ|j	_
|j|j	_dS )zwrite a 0-len array©rj   N)rV   rÑ  rw  rÐ   Úcreate_arrayrÈ   r“  r`   r$  r”  r  ru  )rÜ   rŽ   r�   Úarrrô   rZ   rZ   r[   Úwrite_array_emptyN  s
   zGenericFixed.write_array_emptyrÒ  rK   r  úIndex | Nonec                 C  sª  t |dd�}|| jv r| j | j|¡ |jdk}d}t|jtƒr$tdƒ‚|s0t	|dƒr0|j
}d}d }| jd urSttƒ� tƒ j |j¡}W d   ƒ n1 sNw   Y  |d uru|sn| jj| j|||j| jd�}||d d …< nÝ|  ||¡ nÖ|jjtjkr­tj|dd�}	|r†n|	d	kr‹nt|	||f }
tj|
ttƒ d
� | j | j|tƒ  ¡ ¡}|  |¡ nžt !|jd¡rÌ| j "| j|| #d¡¡ t$|jƒt%| j|ƒj&_'nt|jt(ƒrô| j "| j||j)¡ t%| j|ƒ}t*|j+ƒ|j&_+d|jj,› d�|j&_'nWt !|jd¡�r| j "| j|| #d¡¡ dt%| j|ƒj&_'n:t|t-ƒ�r8| j | j|tƒ  ¡ ¡}|  | .¡ ¡ t%| j|ƒ}t$|jƒ|j&_'n|�rB|  ||¡ n	| j "| j||¡ |t%| j|ƒj&_/d S )NT)Úextract_numpyr   Fz]Cannot store a category dtype in a HDF5 dataset that uses format="fixed". Use format="table".r  )rÓ   ©Úskipnar@  rP  r  r  údatetime64[rB  r|  r¤  )0r=   rÈ   rÐ   r×  r~  rU   r$  r&   r¸   r  r  rÚ   r   rµ   rŠ   ÚAtomÚ
from_dtypeÚcreate_carrayru  r(  rð   rV   Úobject_r   Úinfer_dtypery   rT  rU  r   r   Úcreate_vlarrayÚ
ObjectAtomr•   r,  r&  Úviewr`   r“  r”  r  r'   Úasi8r  rõ  Úunitr9   Úto_numpyr  )rÜ   rŽ   rÒ  r  r�   Úempty_arrayr  r…  ÚcaÚinferred_typerY  Úvlarrrô   rZ   rZ   r[   r  W  sr   

ÿ


þÿ
ÿzGenericFixed.write_arrayrß  râ  rã  rç  ræ  )rŽ   r`   r­   r“   r®   r“   r_   r-   )rŽ   r`   r˜   r-   r_   r    )rŽ   r`   r˜   r.   r_   r    )rŽ   r`   r­   r“   r®   r“   r_   r.   )rô   rJ   r­   r“   r®   r“   r_   r-   )rŽ   r`   r�   rL   r_   r    ra   )rŽ   r`   rÒ  rK   r  r)  r_   r    )rñ   rè  ré  rê  r,   r/   rñ  r  ró  rï  rë  rò  rõ  rÿ  r   rì  rÔ  rß  rá  rÖ  r  r  r  r  r  r  r(  r  rZ   rZ   rZ   r[   rí  9  s4   
 

1


&ÿ

ÿÿ
7
ÿrí  c                      sR   e Zd ZU dZdgZded< edd„ ƒZ				dddd„Zd‡ fdd„Z	‡  Z
S )rÃ  r¸  rf   rD   c              	   C  s*   zt | jjƒfW S  ttfy   Y d S w ra   )rt   rÈ   r~  r¼   r†   rà   rZ   rZ   r[   ru  ½  s
   ÿzSeriesFixed.shapeNr­   r“   r®   r_   r1   c           	      C  s²   |   ||¡ | jd||d�}| jd||d�}zt||| jdd�}W |S  tyX } z*| jdkrLtdƒrLt|ƒ 	d¡rLt
rLt||| jdtd	tjd
�d�}n‚ W Y d }~|S d }~ww )Nr˜   r  r~  F)r˜   rf   rª  r!  r"  r#  r%  r&  )r˜   rf   rª  r$  )r   r  r  r1   rf   r-  rŸ   r   r`   rÚ  r   r2   rV   r.  )	rÜ   ru   r¯   r­   r®   r˜   r~  rü  rf  rZ   rZ   r[   r(  Ä  s4   ð
ÿþýû
ø	€ðzSeriesFixed.readr    c                   s<   t ƒ j|fi |¤Ž |  d|j¡ |  d|¡ |j| j_d S )Nr˜   r~  )rn  rÖ  r  r˜   r  rf   r7  rê  ro  rZ   r[   rÖ  â  s   zSeriesFixed.writerë  ©r­   r“   r®   r“   r_   r1   râ  )rñ   rè  ré  rÇ  rï  rë  rì  ru  r(  rÖ  rÀ  rZ   rZ   ro  r[   rÃ  ·  s   
 
ûrÃ  c                      sR   e Zd ZU ddgZded< eddd„ƒZ				dddd„Zd‡ fdd„Z‡  Z	S )ÚBlockManagerFixedrw  Únblocksri   r_   úShape | Nonec                 C  sª   zJ| j }d}t| jƒD ]}t| jd|› d�ƒ}t|dd ƒ}|d ur'||d 7 }q| jj}t|dd ƒ}|d urAt|d|d … ƒ}ng }| |¡ |W S  tyT   Y d S w )Nr   ÚblockÚ_itemsru  rj   )	rw  rv  r?  r“  rÈ   Úblock0_valuesrr   r•   r†   )rÜ   rw  r  r  rô   ru  rZ   rZ   r[   ru  î  s&   €
ÿzBlockManagerFixed.shapeNr­   r“   r®   r+   c                 C  sX  |   ||¡ |  ¡  d¡}g }t| jƒD ]}||kr||fnd\}}	| jd|› �||	d�}
| |
¡ q|d }g }t| jƒD ]F}|  d|› d�¡}| jd|› d�||	d�}|| 	|¡ }t
|j||d d	d
�}tƒ rt|tjƒrt|dd�r| ttjd�¡}| |¡ q>t|ƒdkr¢t|ddd�}tƒ r™| ¡ }|j|d	d�}|S t
|d |d d�S )Nr   rç  rK  r  rA  rB  r¹  rj   F©r¯   r˜   rª  Tr+  )r(  )rK  rª  )r¯   rª  ©r¯   r˜   )r   rÊ  Ú_get_block_manager_axisrv  rw  r  r•   r?  r  r|  r+   r  r   rU   rV   r)  r   r·  r2   r.  rt   r4   r   rª  r�  )rÜ   ru   r¯   r­   r®   Úselect_axisrh  r  r*  r+  Úaxr  ÚdfsÚ	blk_itemsr~  ÚdfÚoutrZ   rZ   r[   r(  	  s:   ÿ
þ
ýzBlockManagerFixed.readr    c                   sè   t ƒ j|fi |¤Ž t|jtƒr| d¡}|j}| ¡ s | ¡ }|j| j	_t
|jƒD ]\}}|dkr9|js9tdƒ‚|  d|› �|¡ q*t|jƒ| j	_t
|jƒD ]"\}}|j |j¡}| jd|› d�|j|d� |  d|› d�|¡ qOd S )NrA  r   z/Columns index has to be unique for fixed formatrK  r¹  )r  rB  )rn  rÖ  rU   Ú_mgrr?   Ú_as_managerÚis_consolidatedÚconsolidaterw  r7  r  rh  Ú	is_uniquerµ   r  rt   Úblocksr?  r  r}  Úmgr_locsr  r~  )rÜ   rÒ  rÄ   r©  r  rH  ÚblkrJ  ro  rZ   r[   rÖ  6  s"   

üzBlockManagerFixed.write)r_   r@  rë  )r­   r“   r®   r“   r_   r+   râ  )
rñ   rè  ré  rï  rë  rì  ru  r(  rÖ  rÀ  rZ   rZ   ro  r[   r>  é  s   
 û-r>  c                   @  s   e Zd ZdZeZdS )rÄ  r¹  N)rñ   rè  ré  rÇ  r+   rÊ  rZ   rZ   rZ   r[   rÄ  P  s    rÄ  c                      s(  e Zd ZU dZdZdZded< ded< dZded	< d
Zded< 								d‹dŒ‡ fd"d#„Z	e
d�d$d%„ƒZd�d&d'„ZdŽd)d*„Zd�d+d,„Ze
d�d.d/„ƒZd‘d3d4„Ze
d’d6d7„ƒZe
d�d8d9„ƒZe
d:d;„ ƒZe
d<d=„ ƒZe
d>d?„ ƒZe
d@dA„ ƒZe
d“dCdD„ƒZe
d’dEdF„ƒZe
d�dGdH„ƒZe
d”dJdK„ƒZd•dMdN„ZdOdP„ Zd–dRdS„Zd—dUdV„Zd˜dYdZ„Zd™d[d\„Z d�d]d^„Z!d�d_d`„Z"dšd�dadb„Z#d�dcdd„Z$e%dedf„ ƒZ&	d›dœdhdi„Z'	d�dždndo„Z(e)dŸdqdr„ƒZ*dsdt„ Z+	
			d d¡dwdx„Z,e-d¢d{d|„ƒZ.dšd£dd€„Z/d¤d„d…„Z0	d›d¥d†d‡„Z1			d›d¦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
    Ú
wide_tabler{   r`   rÈ  rµ  rj   zint | list[Hashable]r  Trr   rú  Nrƒ   rÏ   r©   rÈ   rJ   r]   r^   rŸ   Ú
index_axesúlist[IndexCol] | NonerG  ú list[tuple[AxisInt, Any]] | NoneÚvalues_axesúlist[DataCol] | Noner�   úlist | Noner±  údict | Noner_   r    c                   sP   t ƒ j||||d� |pg | _|pg | _|pg | _|pg | _|	p!i | _|
| _d S )Nr¼  )rn  rÝ   rV  rG  rY  r�   r±  r¡   )rÜ   rÏ   rÈ   r]   rŸ   rV  rG  rY  r�   r±  r¡   ro  rZ   r[   rÝ   u  s   





zTable.__init__c                 C  s   | j  d¡d S )NÚ_r   )rµ  rÙ  rà   rZ   rZ   r[   Útable_type_shortŠ  ó   zTable.table_type_shortc                 C  s¦   |   ¡  t| jƒrd | j¡nd}d|› d�}d}| jr-d dd„ | jD ƒ¡}d|› d�}d d	d„ | jD ƒ¡}| jd
›|› d| j› d| j	› d| j
› d|› d|› d�S )rÓ  r  rð  z,dc->[rB  rÒ  c                 S  rÔ  rZ   ©r`   rC  rZ   rZ   r[   rq   –  rÖ  z"Table.__repr__.<locals>.<listcomp>r×  c                 S  r
  rZ   re   r¦  rZ   rZ   r[   rq   ™  r  rØ  z (typ->z,nrows->z,ncols->z,indexers->[rÙ  )r2  rt   r�   r	  rÎ  rÍ  rV  r�  r^  r0  Úncols)rÜ   Újdcrˆ  ÚverÚjverÚjindex_axesrZ   rZ   r[   rü   Ž  s(   ÿÿþþþÿzTable.__repr__rM  c                 C  s"   | j D ]}||jkr|  S qdS )zreturn the axis for cN)rh  rf   )rÜ   rM  r‹   rZ   rZ   r[   ré      s
   

ÿzTable.__getitem__c              
   C  sô   |du rdS |j | j krtd|j › d| j › d�ƒ‚dD ]\}t| |dƒ}t||dƒ}||krwt|ƒD ]7\}}|| }||krh|dkrZ|j|jkrZtd|jd › d	|j› d
|j› d�ƒ‚td|› d|› d|› d�ƒ‚q1td|› d|› d|› d�ƒ‚qdS )z"validate against an existing tableNz'incompatible table_type with existing [rN  rB  )rV  rG  rY  rY  úCannot serialize the column [r   z%] because its data contents are not [z] but [ú] object dtypezinvalid combination of [z] on appending data [z] vs current table [)rµ  r¼   r“  r  r�  rµ   r~  ra  )rÜ   r  rM  ÚsvÚovr  ÚsaxÚoaxrZ   rZ   r[   r¯  §  sP   ÿÿÿÿþÿÿÿÿùÿÿìýzTable.validater–   c                 C  s   t | jtƒS )z@the levels attribute is 1 or a list in the case of a multi-index)rU   r  rr   rà   rZ   rZ   r[   Úis_multi_indexÎ  s   zTable.is_multi_indexrÒ  r�   ú tuple[DataFrame, list[Hashable]]c              
   C  sT   t  |jj¡}z| ¡ }W n ty } ztdƒ|‚d}~ww t|tƒs&J ‚||fS )ze
        validate that we can store the multi-index; reset and return the
        new object
        zBduplicate names/columns in the multi-index when storing as a tableN)rc  Úfill_missing_namesr˜   r  Úreset_indexrµ   rU   r+   )rÜ   rÒ  r  Ú	reset_objrf  rZ   rZ   r[   Úvalidate_multiindexÓ  s   ÿþ€ÿzTable.validate_multiindexri   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 rF  )r>  ru  ©rm   r  rZ   rZ   r[   rq   ç  r§  z(Table.nrows_expected.<locals>.<listcomp>)rV   r#  rV  rà   rZ   rZ   r[   Únrows_expectedä  s   zTable.nrows_expectedc                 C  s
   d| j v S )zhas this table been createdr{   râ  rà   rZ   rZ   r[   rÔ  é  s   
zTable.is_existsc                 C  r�  ©Nr{   ©r“  rÈ   rà   rZ   rZ   r[   rã  î  rž  zTable.storablec                 C  rÞ   )z,return the table group (this is my storable))rã  rà   rZ   rZ   r[   r{   ò  r?  zTable.tablec                 C  rü  ra   )r{   r$  rà   rZ   rZ   r[   r$  ÷  r8  zTable.dtypec                 C  rü  ra   r9  rà   rZ   rZ   r[   r:  û  r8  zTable.descriptionúitertools.chain[IndexCol]c                 C  s   t  | j| j¡S ra   )rQ  rR  rV  rY  rà   rZ   rZ   r[   rh  ÿ  r_  z
Table.axesc                 C  s   t dd„ | jD ƒƒS )z.the number of total columns in the values axesc                 s  s   � | ]}t |jƒV  qd S ra   )rt   r~  r¦  rZ   rZ   r[   ro    s   € zTable.ncols.<locals>.<genexpr>)ÚsumrY  rà   rZ   rZ   r[   ra    s   zTable.ncolsc                 C  rh  ri  rZ   rà   rZ   rZ   r[   Úis_transposed  rj  zTable.is_transposedútuple[int, ...]c                 C  s(   t t dd„ | jD ƒdd„ | jD ƒ¡ƒS )z@return a tuple of my permutated axes, non_indexable at the frontc                 S  s   g | ]}t |d  ƒ‘qS rF  rÑ  r¦  rZ   rZ   r[   rq     r§  z*Table.data_orientation.<locals>.<listcomp>c                 S  s   g | ]}t |jƒ‘qS rZ   )ri   rK  r¦  rZ   rZ   r[   rq     rA  )rs   rQ  rR  rG  rV  rà   rZ   rZ   r[   Údata_orientation  s   þÿzTable.data_orientationúdict[str, Any]c                   sR   dddœ‰ dd„ ˆj D ƒ}‡ fdd„ˆjD ƒ}‡fdd„ˆjD ƒ}t|| | ƒS )z<return a dict of the kinds allowable columns for this objectr˜   r¯   ©r   rj   c                 S  s   g | ]}|j |f‘qS rZ   ©r÷  r¦  rZ   rZ   r[   rq     rA  z$Table.queryables.<locals>.<listcomp>c                   s   g | ]
\}}ˆ | d f‘qS ra   rZ   )rm   rK  r~  )Ú
axis_namesrZ   r[   rq     s    c                   s&   g | ]}|j tˆ jƒv r|j|f‘qS rZ   )rf   ru  r�   r÷  rª  rà   rZ   r[   rq     s     )rV  rG  rY  rk  )rÜ   Úd1Úd2Úd3rZ   )r~  rÜ   r[   Ú
queryables  s   

ÿzTable.queryablesc                 C  ó   dd„ | j D ƒS )zreturn a list of my index colsc                 S  s   g | ]}|j |jf‘qS rZ   )rK  r÷  rr  rZ   rZ   r[   rq   '  r§  z$Table.index_cols.<locals>.<listcomp>©rV  rà   rZ   rZ   r[   Ú
index_cols$  r<  zTable.index_colsr	  c                 C  rƒ  )zreturn a list of my values colsc                 S  r
  rZ   r}  rr  rZ   rZ   r[   rq   +  r  z%Table.values_cols.<locals>.<listcomp>)rY  rà   rZ   rZ   r[   Úvalues_cols)  r_  zTable.values_colsrŽ   c                 C  s   | j j}|› d|› d�S )z)return the metadata pathname for this keyz/meta/z/metarÝ  r&  rZ   rZ   r[   Ú_get_metadata_path-  s   zTable._get_metadata_pathr~  r  c                 C  s0   | j j|  |¡t|dd�d| j| j| jd� dS )z£
        Write out a metadata array to the key as a fixed-format Series.

        Parameters
        ----------
        key : str
        values : ndarray
        Fr°  r{   )r—   r]   rŸ   r¡   N)rÏ   r¨   r‡  r1   r]   rŸ   r¡   )rÜ   rŽ   r~  rZ   rZ   r[   rJ  2  s   	

úzTable.write_metadatac                 C  s0   t t | jddƒ|dƒdur| j |  |¡¡S dS )z'return the meta data array for this keyrÊ   N)r“  rÈ   rÏ   rÁ   r‡  rè   rZ   rZ   r[   rc  D  s   zTable.read_metadatac                 C  sp   t | jƒ| j_|  ¡ | j_|  ¡ | j_| j| j_| j| j_| j| j_| j| j_| j	| j_	| j
| j_
| j| j_dS )zset our table type & indexablesN)r`   rµ  r7  r…  r†  rG  r�   r¡   r]   rŸ   r  r±  rà   rZ   rZ   r[   rß  J  s   





zTable.set_attrsc                 C  s°   t | jddƒpg | _t | jddƒpg | _t | jddƒpi | _t | jddƒ| _tt | jddƒƒ| _tt | jddƒƒ| _	t | jd	dƒpBg | _
d
d„ | jD ƒ| _dd„ | jD ƒ| _dS )r  rG  Nr�   r±  r¡   r]   rŸ   rƒ   r  c                 S  ó   g | ]}|j r|‘qS rZ   ©rò  r¦  rZ   rZ   r[   rq   `  rA  z#Table.get_attrs.<locals>.<listcomp>c                 S  ó   g | ]}|j s|‘qS rZ   r‰  r¦  rZ   rZ   r[   rq   a  rA  )r“  r7  rG  r�   r±  r¡   rd   r]   r\   rŸ   r  Ú
indexablesrV  rY  rà   rZ   rZ   r[   rá  W  s   zTable.get_attrsc                 C  sF   |dur| j r!td dd„ | jD ƒ¡ }tj|ttƒ d� dS dS dS )rå  NrÒ  c                 S  rÔ  rZ   r`  rC  rZ   rZ   r[   rq   g  rÖ  z*Table.validate_version.<locals>.<listcomp>rP  )rÎ  rw   r	  rÍ  rT  rU  r   r   )rÜ   ru   rY  rZ   rZ   r[   ræ  c  s   
ýýzTable.validate_versionc                 C  sR   |du rdS t |tƒsdS |  ¡ }|D ]}|dkrq||vr&td|› d�ƒ‚qdS )zˆ
        validate the min_itemsize doesn't contain items that are not in the
        axes this needs data_columns to be defined
        Nr~  zmin_itemsize has the key [z%] which is not an axis or data_column)rU   rk  r‚  rµ   )rÜ   r™   Úqr@  rZ   rZ   r[   Úvalidate_min_itemsizen  s   

ÿÿüzTable.validate_min_itemsizec                   sÔ   g }ˆj ‰ˆjj‰tˆjjƒD ]5\}\}}tˆ|ƒ}ˆ |¡}|dur%dnd}|› d�}tˆ|dƒ}	t||||	|ˆj||d�}
| |
¡ qt	ˆj
ƒ‰t|ƒ‰ ‡ ‡‡‡‡fdd„‰| ‡fdd„tˆjjƒD ƒ¡ |S )	z/create/cache the indexables if they don't existNr_  rÿ  )rf   rK  rù  r�  rø  r{   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ÿ  rq  rs  )
rf   r÷  r~  r�  rù  rø  r{   rÊ   rú  r$  )
rU   r`   rl  rÁ  r“  Ú_maybe_adjust_namerÍ  rw  rc  r{   )r  rM  Úklassr…  Úadj_namer~  r$  r�  ÚmdrÊ   rÒ  )Úbase_posrˆ  ÚdescrÜ   Útable_attrsrZ   r[   r|   ¦  s0   

özTable.indexables.<locals>.fc                   s   g | ]	\}}ˆ ||ƒ‘qS rZ   rZ   )rm   r  rM  )r|   rZ   r[   rq   Ë  rE  z$Table.indexables.<locals>.<listcomp>)r:  r{   r7  r  r…  r“  rc  rñ  r•   ru  r�   rt   ry  r†  )rÜ   Ú_indexablesr  rK  rf   r…  r‘  rÊ   r   r�  Ú	index_colrZ   )r’  rˆ  r“  r|   rÜ   r”  r[   r‹  ƒ  s2   


ø

 %zTable.indexablesr�  c              	   C  sP  |   ¡ sdS |du rdS |du s|du rdd„ | jD ƒ}t|ttfƒs&|g}i }|dur0||d< |dur8||d< | j}|D ]h}t|j|dƒ}|durŽ|jrx|j	}|j
}	|j}
|durc|
|krc| ¡  n|
|d< |durt|	|krt| ¡  n|	|d< |js�|j d¡r…td	ƒ‚|jdi |¤Ž q=|| jd
 d v r¥td|› d|› d|› d�ƒ‚q=dS )aZ  
        Create a pytables index on the specified columns.

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

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

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

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

        Notes
        -----
        Cannot index Time64Col or ComplexCol.
        Pytables must be >= 3.0.
        NFTc                 S  r¤  rZ   )ró  r÷  r¦  rZ   rZ   r[   rq   ô  r§  z&Table.create_index.<locals>.<listcomp>rŒ  r�  Ú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   rj   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.rZ   )r2  rh  rU   rs   rr   r{   r“  rn  r¥  r˜   rŒ  r�  Úremove_indexrð   rž  r¼   rŽ  rG  r†   )rÜ   r¯   rŒ  r�  Úkwr{   rM  rr  r˜   Úcur_optlevelÚcur_kindrZ   rZ   r[   rŽ  Ï  sX   

ÿ€ÿþÿþâzTable.create_indexr­   r“   r®   ú9list[tuple[np.ndarray, np.ndarray] | tuple[Index, Index]]c           	      C  sZ   t | |||d�}| ¡ }g }| jD ]}| | j¡ |j|| j| j| jd�}| 	|¡ q|S )a  
        Create the axes sniffed from the table.

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

        Returns
        -------
        List[Tuple[index_values, column_values]]
        r6  r²  )
Ú	SelectionrÁ   rh  r]  r±  r4  r¡   r]   rŸ   r•   )	rÜ   ru   r­   r®   Ú	selectionr~  rï  r‹   ÚresrZ   rZ   r[   Ú
_read_axes%  s   
üzTable._read_axesr  c                 C  ó   |S )zreturn the data for this objrZ   ©rÏ  rÒ  r  rZ   rZ   r[   Ú
get_objectG  s   zTable.get_objectc                   s²   t |ƒsg S |d \}‰ | j |i ¡}| d¡dkr&|r&td|› d|› �ƒ‚|du r/tˆ ƒ}n|du r5g }t|tƒrPt|ƒ‰t|ƒ}| ‡fdd	„| 	¡ D ƒ¡ ‡ fd
d	„|D ƒS )zd
        take the input data_columns and min_itemize and create a data
        columns spec
        r   rð   r.   z"cannot use a multi-index on axis [z] with data_columns TNc                   s    g | ]}|d kr|ˆ vr|‘qS r5  rZ   r?  )Úexisting_data_columnsrZ   r[   rq   h  s
    þz/Table.validate_data_columns.<locals>.<listcomp>c                   s   g | ]}|ˆ v r|‘qS rZ   rZ   )rm   rM  )Úaxis_labelsrZ   r[   rq   p  r§  )
rt   r±  rç   rµ   rr   rU   rk  ru  ry  r  )rÜ   r�   r™   rG  rK  r±  rZ   )r¥  r¤  r[   Úvalidate_data_columnsL  s.   ÿÿ


þÿ	zTable.validate_data_columnsr+   r¯  c           /        s˜  t ˆtƒs| jj}td|› dtˆƒ› d�ƒ‚ˆ du rdg‰ ‡fdd„ˆ D ƒ‰ |  ¡ r=d}d	d„ | jD ƒ‰ t| j	ƒ}| j
}nd
}| j}	| jdksIJ ‚tˆ ƒ| jd krVtdƒ‚g }
|du r^d}t‡ fdd„dD ƒƒ}ˆj| }t|ƒ}|r¡t|
ƒ}| j| d }tt |¡t |¡ddd�s¡tt t|ƒ¡t t|ƒ¡ddd�r¡|}|	 |i ¡}t|jƒ|d< t|ƒj|d< |
 ||f¡ ˆ d }ˆj| }ˆ |¡}t||| j| jƒ}||_| d¡ |  |	¡ | !|¡ |g}t|ƒ}|dksòJ ‚t|
ƒdksúJ ‚|
D ]}t"ˆ|d |d ƒ‰qü|jdk}|  #|||
¡}|  $ˆ|¡ %¡ }|  &|||
| j'|¡\}}g }t(t)||ƒƒD ]â\}\}}t*}d}|�rbt|ƒdk�rb|d |v �rbt+}|d }|du �sbt |t,ƒ�sbtdƒ‚|�rŒ|�rŒz| j'| }W n t-t.f�y‹ }  ztd|› d| j'› d�ƒ| ‚d} ~ ww d}|�p•d|› �}!t/|!|j0|||| j| j|d�}"t1|!| j2ƒ}#| 3|"¡}$t4|"j5j6ƒ}%d}&t7|"ddƒdu�rÆt8|"j9ƒ}&d }' }(})t |"j5t:ƒ�rá|"j;})d}'t <|"j=¡ >¡ }(nt |j5t?ƒ�rít,|j5ƒ}'t@|"ƒ\}*}+||#|!t|ƒ|$||%|&|)|'|(|+|*d�},|,  |	¡ | |,¡ |d7 }�q2dd„ |D ƒ}-t| ƒ| jA| j| j| j||
||-|	|d�
}.tB| dƒ�r:| jC|._C|. D|¡ |�rJ|�rJ|. E| ¡ |.S ) a0  
        Create and return the axes.

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

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

        min_itemsize: Dict[str, int] or None, default None
            The min itemsize for a column in bytes.
        z/cannot properly create the storer for: [group->r»  rB  Nr   c                   r>  rZ   )Ú_get_axis_numberr¦  )rÒ  rZ   r[   rq   ž  rA  z&Table._create_axes.<locals>.<listcomp>Tc                 S  r
  rZ   rp  r¦  rZ   rZ   r[   rq   £  r  FrÌ  rj   z<currently only support ndim-1 indexers in an AppendableTabler.  c                 3  s   � | ]	}|ˆ vr|V  qd S ra   rZ   rC  )rh  rZ   r[   ro  »  s   € z%Table._create_axes.<locals>.<genexpr>r|  r`  r  rð   rÂ  zIncompatible appended table [z]with existing table [Úvalues_block_)Úexisting_colr™   r¡   r]   rŸ   r¯   rõ  r_  )rf   r÷  r~  rø  rù  r�  rõ  r„  rÊ   rú  r$  r©  c                 S  r¤  rZ   )ró  rf   )rm   r;  rZ   rZ   r[   rq   K  r§  )
rÏ   rÈ   r]   rŸ   rV  rG  rY  r�   r±  r¡   r  )FrU   r+   rÈ   rÍ   r¼   rð   r2  rV  rr   r�   r¡   r±  rw  rt   rµ   rt  rh  rG  r*   rV   r<   r{  rS  r  rñ   r•   Ú_get_axis_namer  r]   rŸ   rK  rû  rZ  rB  Ú_reindex_axisr¦  r£  rM  Ú_get_blocks_and_itemsrY  r  rS  rl  rÁ  r`   Ú
IndexErrorrï   Ú_maybe_convert_for_string_atomr~  rŽ  rÍ  r†  rw  r$  rf   r“  r  rõ  r&   r„  r³  r®  r´  r2   rv  rÏ   r  r  r�  r¯  )/rÜ   rh  rÒ  r¯  r¡   r�   r™   rÈ   Útable_existsÚnew_infoÚnew_non_index_axesrW  r‹   Úappend_axisÚindexerÚ
exist_axisr±  Ú	axis_nameÚ	new_indexÚnew_index_axesÚjr  r¹  rR  rJ  Úvaxesr  rT  Úb_itemsr�  rf   r©  rf  Únew_nameÚdata_convertedr�  rø  r�  rõ  rÊ   rú  r„  r©  rx  r;  ÚdcsÚ	new_tablerZ   )rh  rÒ  r[   Ú_create_axesr  s4  
 ÿÿ
ÿ
üü





ÿÿ"ÿÿý€ÿø



ô

ö

zTable._create_axesr¹  r¯  c                 C  s~  t | jtƒr|  d¡} dd„ }| j}tt|ƒ}t|jƒ}||ƒ}t|ƒri|d \}	}
t	|
ƒ 
t	|ƒ¡}| j||	d�j}tt|ƒ}t|jƒ}||ƒ}|D ]}| j|g|	d�j}tt|ƒ}| |j¡ | ||ƒ¡ qK|r»dd„ t||ƒD ƒ}g }g }|D ];}t|jƒ}z| |¡\}}| |¡ | |¡ W q{ ttfy¶ } zd d	d
„ |D ƒ¡}td|› d�ƒ|‚d }~ww |}|}||fS )NrA  c                   s   ‡ fdd„ˆ j D ƒS )Nc                   s   g | ]	}ˆ j  |j¡‘qS rZ   )r  r}  rS  )rm   rT  ©ÚmgrrZ   r[   rq   s  rE  zFTable._get_blocks_and_items.<locals>.get_blk_items.<locals>.<listcomp>)rR  rÀ  rZ   rÀ  r[   Úget_blk_itemsr  s   z2Table._get_blocks_and_items.<locals>.get_blk_itemsr   rp  c                 S  s"   i | ]\}}t | ¡ ƒ||f“qS rZ   )rs   Útolist)rm   Úbrº  rZ   rZ   r[   rs  ‘  s    ÿÿz/Table._get_blocks_and_items.<locals>.<dictcomp>r  c                 S  rÔ  rZ   rÕ  )rm   ÚitemrZ   rZ   r[   rq   ž  rÖ  z/Table._get_blocks_and_items.<locals>.<listcomp>z+cannot match existing table structure for [z] on appending data)rU   rM  r?   rN  r   r@   rr   rR  rt   r-   rz  r�  ry  rS  rs   r~  rV  r•   r­  rï   r	  rµ   )r¹  r¯  r±  rY  r�   rÂ  rÁ  rR  rJ  rK  r¥  Ú
new_labelsrM  Úby_itemsÚ
new_blocksÚnew_blk_itemsÚear  rÄ  rº  rf  ÚjitemsrZ   rZ   r[   r¬  d  sV   





þ


ÿý€þzTable._get_blocks_and_itemsrž  r�  c                   sª   |durt |ƒ}|dur'ˆjr'tˆjt ƒsJ ‚ˆjD ]}||vr&| d|¡ qˆjD ]\}}tˆ |||ƒ‰ ‡ ‡fdd„}q*|jdurS|j ¡ D ]\}}	}
|||
|	ƒ‰ qGˆ S )zprocess axes filtersNr   c                   sÈ   ˆ j D ]X}ˆ  |¡}ˆ  |¡}|d usJ ‚| |kr3ˆjr$| tˆjƒ¡}|||ƒ}ˆ j|d�|   S | |v r[tt	ˆ | ƒj
ƒ}t|ƒ}tˆ tƒrLd| }|||ƒ}ˆ j|d�|   S qtd| › d�ƒ‚)Nrp  rj   zcannot find the field [z] for filtering!)Ú_AXIS_ORDERSr§  Ú	_get_axisrl  Úunionr-   r  r€  r>   r“  r~  rU   r+   rµ   )ÚfieldÚfiltÚoprµ  Úaxis_numberÚaxis_valuesÚtakersr~  ©rÒ  rÜ   rZ   r[   Úprocess_filter¹  s$   





öz*Table.process_axes.<locals>.process_filter)	rr   rl  rU   r  ÚinsertrG  r«  Úfilterr—   )rÜ   rÒ  rž  r¯   r  rK  ÚlabelsrÖ  rÏ  rÑ  rÐ  rZ   rÕ  r[   Úprocess_axes¨  s   
€
 zTable.process_axesr’   rÒ   ri  c                 C  s„   |du r
t | jdƒ}d|dœ}dd„ | jD ƒ|d< |r6|du r$| jp#d}tƒ j|||p-| jd	�}||d
< |S | jdur@| j|d
< |S )z:create the description of the table from the axes & valuesNi'  r{   )rf   ri  c                 S  s   i | ]}|j |j“qS rZ   )r÷  rø  r¦  rZ   rZ   r[   rs  î  rA  z,Table.create_description.<locals>.<dictcomp>r:  é	   )r’   r”   rÒ   rÓ   )Úmaxrs  rh  r×   rŠ   r  rÙ   rÚ   )rÜ   r”   r’   rÒ   ri  rj  rÓ   rZ   rZ   r[   Úcreate_descriptionß  s"   	

ý
ý
zTable.create_descriptionc           
      C  s�   |   |¡ |  ¡ sdS t| |||d�}| ¡ }|jdurD|j ¡ D ]"\}}}| j|| ¡ | ¡ d d�}	|||	j	|| ¡   |ƒj
 }q!t|ƒS )zf
        select coordinates (row numbers) from a table; return the
        coordinates object
        Fr6  Nrj   r  )ræ  r2  r�  Úselect_coordsrØ  r—   r<  rî  rÜ  Úilocr~  r-   )
rÜ   ru   r­   r®   rž  ÚcoordsrÏ  rÑ  rÐ  r©  rZ   rZ   r[   r8  þ  s   

ÿ zTable.read_coordinatesr;  c           
      C  sÔ   |   ¡  |  ¡ s
dS |durtdƒ‚| jD ]L}||jkra|js'td|› d�ƒ‚t| jj	|ƒ}| 
| j¡ |j|||… | j| j| jd�}t|d |jƒ}t| jj|› d�dƒ}	t||d|	d	�  S qtd|› d
�ƒ‚)zj
        return a single column from the table, generally only indexables
        are interesting
        FNz4read_column does not currently accept a where clausezcolumn [z=] can not be extracted individually; it is not data indexabler²  rj   rs  )rf   rª  r$  z] not found in the table)ræ  r2  r¼   rh  rf   ró  rµ   r“  r{   rn  r]  r±  r4  r¡   r]   rŸ   r/  rõ  r7  r1   rï   )
rÜ   r;  ru   r­   r®   r‹   rM  Ú
col_valuesÚcvsr$  rZ   rZ   r[   r<    s0   


ÿ
üîzTable.read_column)Nrƒ   NNNNNN)rÏ   r©   rÈ   rJ   r]   r^   rŸ   r`   rV  rW  rG  rX  rY  rZ  r�   r[  r±  r\  r_   r    rß  )rM  r`   râ  rã  )rÒ  r�   r_   rm  rá  )r_   rv  )r_   ry  )r_   r{  )r_   r	  )rŽ   r`   r_   r`   )rŽ   r`   r~  r  r_   r    rà  ra   rå  )r�  r^   r_   r    rç  )r­   r“   r®   r“   r_   rœ  ©r  r–   )TNNN)rÒ  r+   r¯  r–   )r¹  r+   r¯  r–   )rž  r�  r_   r+   )r’   r“   rÒ   r–   ri  r“   r_   r{  rì  )r;  r`   r­   r“   r®   r“   )4rñ   rè  ré  rê  rÇ  rÈ  rë  r  rT  rÝ   rì  r^  rü   ré   r¯  rl  rq  rs  rÔ  rã  r{   r$  r:  rh  ra  rx  rz  r‚  r…  r†  r‡  rJ  rc  rß  rá  ræ  r�  r   r‹  rŽ  r   r¿  r£  r¦  r¿  Ústaticmethodr¬  rÚ  rÝ  r8  r<  rÀ  rZ   rZ   ro  r[   r  U  s    
 õ


'





	







LÿWÿ"*ù sC
7 ÿûr  c                   @  s2   e Zd ZdZdZ				dddd„Zddd„ZdS )rË  zË
    a write-once read-many table: this format DOES NOT ALLOW appending to a
    table. writing is a one-time operation the data are stored in a format
    that allows for searching the data on disk
    rÂ  Nr­   r“   r®   c                 C  rç  )z[
        read the indices and the indexing array, calculate offset rows and return
        z!WORMTable needs to implement readrè  ré  rZ   rZ   r[   r(  O  s   
zWORMTable.readr_   r    c                 K  rç  )zÞ
        write in a format that we can search later on (but cannot append
        to): write out the indices and the values using _write_array
        (e.g. a CArray) create an indexing table so that we can search
        z"WORMTable needs to implement writerè  rê  rZ   rZ   r[   rÖ  [  s   zWORMTable.writerë  rì  râ  )rñ   rè  ré  rê  rµ  r(  rÖ  rZ   rZ   rZ   r[   rË  F  s    ûrË  c                   @  sZ   e Zd ZdZdZ												dd dd„Zd!d"dd„Zd#dd„Zd$d%dd„ZdS )&rF  ú(support the new appendable table formatsÚ
appendableNFTr•   r–   r²   r“   r›   rZ  r_   r    c                 C  s¶   |s| j r| j | jd¡ | j||||||d�}|jD ]}| ¡  q|j sA|j||||	d�}| ¡  ||d< |jj	|jfi |¤Ž |j
|j_
|jD ]}| ||¡ qI|j||
d� d S )Nr{   )rh  rÒ  r¯  r™   r¡   r�   )r”   r’   rÒ   ri  rZ  )r›   )rÔ  rÐ   r×  rÈ   r¿  rh  rD  rÝ  rß  Úcreate_tabler±  r7  rL  Ú
write_data)rÜ   rÒ  rh  r•   r”   r’   rÒ   r™   r²   ri  r›   r¡   r�   rZ  r{   r‹   ÚoptionsrZ   rZ   r[   rÖ  j  s4   
ú
	
ü

zAppendableTable.writec                   sÀ  | j j}| j}g }|r*| jD ]}t|jƒjdd�}t|tj	ƒr)| 
|jddd�¡ qt|ƒrD|d }|dd… D ]}||@ }q8| ¡ }nd}dd	„ | jD ƒ}	t|	ƒ}
|
dksZJ |
ƒ‚d
d	„ | jD ƒ}dd	„ |D ƒ}g }t|ƒD ]\}}|f| j ||
|   j }| 
| |¡¡ qo|du r�d}tjt||ƒ| j d�}|| d }t|ƒD ]9}|| ‰t|d | |ƒ‰ ˆˆ krº dS | j|‡ ‡fdd	„|	D ƒ|durÐ|ˆˆ … nd‡ ‡fdd	„|D ƒd� q¤dS )z`
        we form the data into a 2-d including indexes,values,mask write chunk-by-chunk
        r   rp  Úu1Fr°  rj   Nc                 S  r
  rZ   )r>  r¦  rZ   rZ   r[   rq   À  r  z.AppendableTable.write_data.<locals>.<listcomp>c                 S  ó   g | ]}|  ¡ ‘qS rZ   )r6  r¦  rZ   rZ   r[   rq   Æ  rÖ  c              	   S  s,   g | ]}|  t t |j¡|jd  ¡¡‘qS r%  )Ú	transposerV   ÚrollÚarangerw  rª  rZ   rZ   r[   rq   Ç  s   , rí  r¦  c                   ó   g | ]}|ˆˆ … ‘qS rZ   rZ   r¦  ©Úend_iÚstart_irZ   r[   rq   Û  r§  c                   rï  rZ   rZ   rª  rð  rZ   r[   rq   Ý  r§  )Úindexesr½  r~  )r$  r  rs  rY  r5   r©  rl  rU   rV   r)  r•   r·  rt   r´  rV  r  ru  ÚreshaperÑ  rî  rv  Úwrite_data_chunk)rÜ   r²   r›   r  r0  Úmasksr‹   r½  r|  ró  Únindexesr~  Úbvaluesr  rr  Ú	new_shapeÚrowsÚchunksrZ   rð  r[   rè  ¥  sP   
€

üúzAppendableTable.write_datarú  r  ró  úlist[np.ndarray]r½  únpt.NDArray[np.bool_] | Noner~  c                 C  sè   |D ]}t  |j¡s dS q|d jd }|t|ƒkr#t j|| jd�}| jj}t|ƒ}t|ƒD ]
\}	}
|
|||	 < q/t|ƒD ]\}	}||||	|  < q>|dura| ¡ j	t
dd� }| ¡ sa|| }t|ƒrr| j |¡ | j ¡  dS dS )zê
        Parameters
        ----------
        rows : an empty memory space where we are putting the chunk
        indexes : an array of the indexes
        mask : an array of the masks
        values : an array of the values
        Nr   r¦  Fr°  )rV   r#  ru  rt   rÑ  r$  r  r  r´  r·  r–   rl  r{   r•   r!  )rÜ   rú  ró  r½  r~  rr  r0  r  r÷  r  rW  r|  rZ   rZ   r[   rõ  à  s*   ÿþz AppendableTable.write_data_chunkr­   r®   c                 C  sb  |d u st |ƒs4|d u r|d u r| j}| jj| jdd� |S |d u r%| j}| jj||d�}| j ¡  |S |  ¡ s:d S | j}t	| |||d�}| 
¡ }t|dd� ¡ }t |ƒ}	|	r¯| ¡ }
t|
|
dk jƒ}t |ƒskdg}|d |	krv| |	¡ |d dkr‚| dd¡ | ¡ }t|ƒD ]}| t||ƒ¡}|j||jd  ||jd  d d� |}qŠ| j ¡  |	S )	NTr^  r  Fr°  rj   r   r­  )rt   r0  rÐ   r×  rÈ   r{   Úremove_rowsr!  r2  r�  rÞ  r1   Úsort_valuesÚdiffrr   r˜   r•   r×  rV  Úreversedr}  rv  )rÜ   ru   r­   r®   r0  r{   rž  r~  Úsorted_seriesÚlnr   r¾   Úpgr  rú  rZ   rZ   r[   re    sF   ü

ÿ
zAppendableTable.delete)NFNNNNNNFNNT)
r•   r–   r²   r“   r›   r–   rZ  r–   r_   r    rä  )r²   r“   r›   r–   r_   r    )
rú  r  ró  rü  r½  rý  r~  rü  r_   r    rå  rì  )	rñ   rè  ré  rê  rµ  rÖ  rè  rõ  re  rZ   rZ   rZ   r[   rF  d  s&    ò;
;,rF  c                   @  sZ   e Zd ZU dZdZdZdZeZde	d< e
dd	d
„ƒZeddd„ƒZ				dddd„ZdS )rÉ  rå  r¶  rÀ  rÌ  rÉ  rÊ  r_   r–   c                 C  s   | j d jdkS )Nr   rj   )rV  rK  rà   rZ   rZ   r[   rx  O  r_  z"AppendableFrameTable.is_transposedr  c                 C  s   |r|j }|S )zthese are written transposed)r  r¢  rZ   rZ   r[   r£  S  s   zAppendableFrameTable.get_objectNr­   r“   r®   c                   sì  ˆ   |¡ ˆ  ¡ sd S ˆ j|||d�}tˆ jƒr$ˆ j ˆ jd d i ¡ni }‡ fdd„tˆ jƒD ƒ}t|ƒdks:J ‚|d }|| d }	g }
tˆ jƒD �]\}}|ˆ j	vrVqK|| \}}| d¡dkrht
|ƒ}nt |¡}| d¡}|d ur}|j|d	d
� ˆ jr�|}|}t
|	t|	dd ƒd�}n|j}t
|	t|	dd ƒd�}|}|jdkr³t|tjƒr³| d|jd f¡}t|tjƒrúzt|j||dd�}W nL tyù } z)ˆ jdkrîtdƒrît|ƒ d¡rîtrît|j||dtdtjd�d�}n‚ W Y d }~nd }~ww t|t
ƒ�rt|||d�}n	tj |g||d�}t!ƒ �r|j"j#dk�s-|j$|j"k %¡ �s-J |j$|j"fƒ‚|D ]}tˆ j&j'|› d�d ƒ}|dv �rJ||  (|¡||< �q/|
 )|¡ qKt|
ƒdk�r^|
d }nt*|
dd�}t+ˆ |||d�}ˆ j,|||d�}|S )Nr6  r   c                   s"   g | ]\}}|ˆ j d  u r|‘qS rF  r„  )rm   r  rH  rà   rZ   r[   rq   p  s   " z-AppendableFrameTable.read.<locals>.<listcomp>rj   rð   r.   r  T©Úinplacerf   re   FrD  r!  r"  r#  r%  r&  )r¯   r˜   rª  r$  rE  r±  rs  )r`   r@  rp  )rž  r¯   )-ræ  r2  r   rt   rG  r±  rç   r  rh  rY  r-   r.   Úfrom_tuplesÚ	set_namesrx  r“  r  rw  rU   rV   r)  rô  ru  r+   r-  rŸ   r   r`   rÚ  r   r2   r.  Ú_from_arraysr   r$  r�  Údtypesrl  r{   r7  r·  r•   r4   r�  rÚ  )rÜ   ru   r¯   r­   r®   rü  r±  ÚindsÚindr˜   Úframesr  r‹   Ú
index_valsr>  rn  r  r~  Úindex_Úcols_rK  rf  r;  r$  rž  rZ   rà   r[   r(  Z  sŽ   
ÿý




ÿþýûø€ù"
€
zAppendableFrameTable.readrã  rã  rë  rì  )rñ   rè  ré  rê  rÇ  rµ  rw  r+   rÊ  rë  rì  rx  r¿  r£  r(  rZ   rZ   rZ   r[   rÉ  G  s   
 ûrÉ  c                      sh   e Zd ZdZdZdZdZeZe	ddd„ƒZ
edd
d„ƒZdd‡ fdd„Z				dd‡ fdd„Z‡  ZS )rÇ  rå  r½  r¾  rÌ  r_   r–   c                 C  rh  ri  rZ   rà   rZ   rZ   r[   rx  É  rj  z#AppendableSeriesTable.is_transposedr  c                 C  r¡  ra   rZ   r¢  rZ   rZ   r[   r£  Í  rj  z AppendableSeriesTable.get_objectNr    c                   s@   t |tƒs|jp	d}| |¡}tƒ jd||j ¡ dœ|¤Ž dS )ú+we are going to write this as a frame tabler~  ©rÒ  r�   NrZ   )rU   r+   rf   Úto_framern  rÖ  r¯   rÃ  )rÜ   rÒ  r�   rÄ   rf   ro  rZ   r[   rÖ  Ò  s   


"zAppendableSeriesTable.writer­   r“   r®   r1   c                   s�   | j }|d ur!|r!t| jtƒsJ ‚| jD ]}||vr | d|¡ qtƒ j||||d�}|r5|j| jdd� |jd d …df }|j	dkrFd |_	|S )Nr   rJ  Tr  r~  )
rl  rU   r  rr   r×  rn  r(  Ú	set_indexrß  rf   )rÜ   ru   r¯   r­   r®   rl  r  rY   ro  rZ   r[   r(  Ù  s   
€
zAppendableSeriesTable.readrã  rã  ra   râ  rë  r=  )rñ   rè  ré  rê  rÇ  rµ  rw  r1   rÊ  rì  rx  r¿  r£  rÖ  r(  rÀ  rZ   rZ   ro  r[   rÇ  Á  s     	ûrÇ  c                      s*   e Zd ZdZdZdZd‡ fdd„Z‡  ZS )	rÈ  rå  r½  r¿  r_   r    c                   sb   |j pd}|  |¡\}| _t| jtƒsJ ‚t| jƒ}| |¡ t|ƒ|_tƒ j	dd|i|¤Ž dS )r  r~  rÒ  NrZ   )
rf   rq  r  rU   rr   r•   r-   r¯   rn  rÖ  )rÜ   rÒ  rÄ   rf   Únewobjrn  ro  rZ   r[   rÖ  ù  s   



z AppendableMultiSeriesTable.writerâ  )rñ   rè  ré  rê  rÇ  rµ  rÖ  rÀ  rZ   rZ   ro  r[   rÈ  ò  s
    rÈ  c                   @  sd   e Zd ZU dZdZdZdZeZde	d< e
dd	d
„ƒZe
dd„ ƒZddd„Zedd„ ƒZddd„ZdS )rÆ  z:a table that read/writes the generic pytables table formatr¶  r·  rÌ  zlist[Hashable]r  r_   r`   c                 C  rÞ   ra   )rÇ  rà   rZ   rZ   r[   r�    rå   zGenericTable.pandas_typec                 C  s   t | jdd ƒp	| jS rt  ru  rà   rZ   rZ   r[   rã    r‰  zGenericTable.storabler    c                 C  sL   g | _ d| _g | _dd„ | jD ƒ| _dd„ | jD ƒ| _dd„ | jD ƒ| _dS )r  Nc                 S  rˆ  rZ   r‰  r¦  rZ   rZ   r[   rq     rA  z*GenericTable.get_attrs.<locals>.<listcomp>c                 S  rŠ  rZ   r‰  r¦  rZ   rZ   r[   rq     rA  c                 S  r
  rZ   re   r¦  rZ   rZ   r[   rq     r  )rG  r¡   r  r‹  rV  rY  r�   rà   rZ   rZ   r[   rá    s   zGenericTable.get_attrsc           
   
   C  s¨   | j }|  d¡}|durdnd}tdd| j||d�}|g}t|jƒD ]/\}}t|tƒs-J ‚t||ƒ}|  |¡}|dur=dnd}t	|||g|| j||d�}	| 
|	¡ q"|S )z0create the indexables from the table descriptionr˜   Nr_  r   )rf   rK  r{   rÊ   rú  )rf   rù  r~  rø  r{   rÊ   rú  )r:  rc  rg  r{   r  Ú_v_namesrU   r`   r“  rÅ  r•   )
rÜ   rj  r‘  rÊ   r–  r•  r  r  r…  rˆ  rZ   rZ   r[   r‹    s.   
ÿ

ù	zGenericTable.indexablesc                 K  rç  )Nz cannot write on an generic tablerè  )rÜ   rÄ   rZ   rZ   r[   rÖ  C  s   zGenericTable.writeNrß  râ  )rñ   rè  ré  rê  rÇ  rµ  rw  r+   rÊ  rë  rì  r�  rã  rá  r   r‹  rÖ  rZ   rZ   rZ   r[   rÆ    s   
 



#rÆ  c                      s`   e Zd ZdZdZeZdZe 	d¡Z
eddd„ƒZdd‡ fdd„Z								dd‡ fdd„Z‡  ZS )rÊ  za frame with a multi-indexrÁ  rÌ  z^level_\d+$r_   r`   c                 C  rh  )NÚappendable_multirZ   rà   rZ   rZ   r[   r^  O  rj  z*AppendableMultiFrameTable.table_type_shortNr    c                   s|   |d u rg }n	|du r|j  ¡ }|  |¡\}| _t| jtƒs J ‚| jD ]}||vr/| d|¡ q#tƒ jd||dœ|¤Ž d S )NTr   r  rZ   )	r¯   rÃ  rq  r  rU   rr   r×  rn  rÖ  )rÜ   rÒ  r�   rÄ   r  ro  rZ   r[   rÖ  T  s   

€zAppendableMultiFrameTable.writer­   r“   r®   c                   sD   t ƒ j||||d�}| ˆ j¡}|j ‡ fdd„|jjD ƒ¡|_|S )NrJ  c                   s    g | ]}ˆ j  |¡rd n|‘qS ra   )Ú
_re_levelsÚsearch)rm   rf   rà   rZ   r[   rq   l  s     z2AppendableMultiFrameTable.read.<locals>.<listcomp>)rn  r(  r  r  r˜   r  r  )rÜ   ru   r¯   r­   r®   rK  ro  rà   r[   r(  `  s   ÿzAppendableMultiFrameTable.readrß  ra   râ  rë  rì  )rñ   rè  ré  rê  rµ  r+   rÊ  rw  ÚreÚcompiler  rì  r^  rÖ  r(  rÀ  rZ   rZ   ro  r[   rÊ  G  s    
ûrÊ  rÒ  r+   rK  rM   rÙ  r-   c                 C  s¢   |   |¡}t|ƒ}|d urt|ƒ}|d u s| |¡r!| |¡r!| S t| ¡ ƒ}|d ur6t| ¡ ƒj|dd�}| |¡sOtd d ƒg| j }|||< | jt|ƒ } | S )NF)Úsort)	rÍ  r>   ÚequalsÚuniquer  Úslicerw  r€  rs   )rÒ  rK  rÙ  r  rH  ÚslicerrZ   rZ   r[   r«  r  s   

r«  rõ  r   ústr | tzinfoc                 C  s   t  | ¡}|S )z+for a tz-aware type, return an encoded zone)r   Úget_timezone)rõ  ÚzonerZ   rZ   r[   r  Œ  s   
r  r~  únp.ndarray | Indexr£  r,   c                 C  rC  ra   rZ   ©r~  rõ  r£  rZ   rZ   r[   r/  ’  s   r/  r  c                 C  rC  ra   rZ   r%  rZ   rZ   r[   r/  ™  rj  ústr | tzinfo | Noneúnp.ndarray | DatetimeIndexc                 C  s”   t | tƒr| jdu s| j|ksJ ‚| jdur| S |dur?t | tƒr%| j}nd}|  ¡ } t|ƒ}t| |d�} |  d¡ |¡} | S |rHtj	| dd�} | S )a  
    coerce the values to a DatetimeIndex if tz is set
    preserve the input shape if possible

    Parameters
    ----------
    values : ndarray or Index
    tz : str or tzinfo
    coerce : if we do not have a passed timezone, coerce to M8[ns] ndarray
    Nre   r÷  úM8[ns]r¦  )
rU   r,   rõ  rf   r´  r\   rù  rú  rV   r³  )r~  rõ  r£  rf   rZ   rZ   r[   r/  ž  s    


ûrf   c              
   C  st  t | tƒsJ ‚|j}t|ƒ\}}t|ƒ}t |¡}t |j	d¡s*t
|j	ƒs*t|j	ƒr=t| |||t|dd ƒt|dd ƒ|d�S t |tƒrFtdƒ‚tj|dd�}	t |¡}
|	dkrotjd	d
„ |
D ƒtjd�}t| |dtƒ  ¡ |d�S |	dkrŠt|
||ƒ}|j	j}t| |dtƒ  |¡|d�S |	dv r—t| ||||d�S t |tjƒr¢|j	tks¤J ‚|dks¬J |ƒ‚tƒ  ¡ }t| ||||d�S )NÚiurô  rõ  )r~  r�  rø  rô  rõ  rö  zMultiIndex not supported here!Fr+  r   c                 S  rë  rZ   )Ú	toordinalrª  rZ   rZ   r[   rq   ë  rÖ  z"_convert_index.<locals>.<listcomp>r¦  )rö  r@  )ÚintegerÚfloating)r~  r�  rø  rö  r  )rU   r`   rf   rv  rw  rÁ  r†  r   r,  r$  r%   r!   rñ  r“  r.   r¼   r2  rV   r³  Úint32rŠ   Ú	Time32ColÚ_convert_string_arrayrý  rA  r)  r  r4  )rf   r˜   r]   rŸ   rö  r¼  rx  r�  r…  r;  r~  rý  rZ   rZ   r[   r  Å  s^   
ÿþý

ù


ÿ
û
ÿ
r  r�  c                 C  sò   |  d¡r|dkrt| ƒ}|S t|  |¡ƒ}|S |dkr"t| ƒ}|S |dkrLztjdd„ | D ƒtd�}W |S  tyK   tjdd„ | D ƒtd�}Y |S w |dv rWt | ¡}|S |d	v ret| d ||d
�}|S |dkrrt | d ¡}|S td|› �ƒ‚)Nr¡  r¤  r   c                 S  r§  rZ   r¨  rª  rZ   rZ   r[   rq     rA  z$_unconvert_index.<locals>.<listcomp>r¦  c                 S  r§  rZ   r«  rª  rZ   rZ   r[   rq     rA  )r+  Úfloatr–   r@  r²  r  r   zunrecognized index type )	rž  r,   r5  r3   rV   r³  r  rµ   r»  )r©  r�  r]   rŸ   r˜   rZ   rZ   r[   r$    s:   
îïñôô
	øÿüÿr$  rø  rL   r	  c                 C  sº  t |jtƒr
| ¡ }|jtkr|S ttj|ƒ}|jj}t	j
|dd�}	|	dkr*tdƒ‚|	dkr2tdƒ‚|	dks<|dks<|S t|ƒ}
| ¡ }|||
< |rY|
 ¡ rYt|ƒ|jkrYtd	ƒ‚t	j
|dd�}	|	dkr—t|jd
 ƒD ]+}|| }t	j
|dd�}	|	dkr–t|ƒ|kr†|| nd|› �}td|› d|	› d�ƒ‚qkt|||ƒ |j¡}|j}t |tƒr·t| | ¡pµ| d¡pµd
ƒ}t|p»d
|ƒ}|d urÑ| |¡}|d urÑ||krÑ|}|jd|› �dd�}|S )NFr+  r   z+[date] is not implemented as a table columnrî  z>too many timezones in this block, create separate data columnsr@  r  z8NaN representation is too large for existing column sizer   zNo.rf  z2]
because its data contents are not [string] but [rg  r~  z|Sr°  )rU   r$  r2   r8  r  r   rV   r)  rf   r   r2  r¼   r5   rª  r¶  rt   rý  rµ   rv  ru  r/  rô  rk  ri   rç   rÜ  rG  r·  )rf   rø  r©  r™   r¡   r]   rŸ   r¯   rx  r;  r½  r©  r  r;  Úerror_column_labelr¼  rý  ÚecirZ   rZ   r[   r®  "  sX   

ÿþÿþ


r®  r©  c                 C  sb   t | ƒrt|  ¡ ddd�j ||¡j | j¡} t|  ¡ ƒ}t	dt
 |¡ƒ}tj| d|› �d�} | S )a  
    Take a string-like that is object dtype and coerce to a fixed size string type.

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

    Returns
    -------
    np.ndarray[fixed-length-string]
    Fr  )rª  r$  rj   ÚSr¦  )rt   r1   r´  r`   Úencoder¹  rô  ru  r    rÜ  Ú
libwritersÚmax_len_string_arrayrV   r³  )r©  r]   rŸ   Úensuredrý  rZ   rZ   r[   r/  q  s   

ýr/  c                 C  s¬   | j }tj|  ¡ td�} t| ƒrEt t| ƒ¡}d|› �}t	| d t
ƒr9t| dd�jj||dd�}| ¡ } d| j_n| j|dd�jtdd�} |d	u rKd
}t | |¡ |  |¡S )a*  
    Inverse of _convert_string_array.

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

    Returns
    -------
    np.ndarray[object]
        Decoded data.
    r¦  ÚUr   Fr°  r  )rŸ   r$  TNr.  )ru  rV   r³  r´  r  rt   r5  r6  r    rU   rþ  r1   r`   rX   r8  ÚflagsÚ	writeabler·  Ú!string_array_replace_from_nan_reprô  )r©  r¡   r]   rŸ   ru  rý  r$  ÚserrZ   rZ   r[   r»  �  s    
ÿ

r»  r0  c                 C  s6   t |tƒsJ t|ƒƒ‚t|ƒrt|||ƒ}|| ƒ} | S ra   )rU   r`   rð   Ú_need_convertÚ_get_converter)r~  r0  r]   rŸ   ÚconvrZ   rZ   r[   r+  º  s
   r+  c                   sH   ˆdkrdd„ S dˆv r‡fdd„S ˆdkr‡ ‡fdd„S t dˆ› �ƒ‚)Nr¡  c                 S  s   t j| dd�S )Nr(  r¦  ©rV   r³  ©rD  rZ   rZ   r[   r¥   Ä  ó    z _get_converter.<locals>.<lambda>c                   s   t j| ˆ d�S )Nr¦  r@  rA  r{  rZ   r[   r¥   Æ  rB  r@  c                   s   t | d ˆ ˆd�S )Nr²  )r»  rA  r¼  rZ   r[   r¥   È  s    ÿzinvalid kind )rµ   )r�  r]   rŸ   rZ   )r]   rŸ   r�  r[   r>  Â  s   r>  c                 C  s   | dv sd| v r
dS dS )N)r¡  r@  r¡  TFrZ   r{  rZ   rZ   r[   r=  Ï  s   r=  rÍ  úSequence[int]c                 C  sl   t |tƒst|ƒdk rtdƒ‚|d dkr4|d dkr4|d dkr4t d| ¡}|r4| ¡ d }d|› �} | S )	zö
    Prior to 0.10.1, we named values blocks like: values_block_0 an the
    name values_0, adjust the given name if necessary.

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

    Returns
    -------
    str
    é   z6Version is incorrect, expected sequence of 3 integers.r   rj   rË  rÌ  zvalues_block_(\d+)Úvalues_)rU   r`   rt   rµ   r  r  r¾   )rf   rÍ  r|  ÚgrprZ   rZ   r[   rŽ  Õ  s   $
rŽ  Ú	dtype_strc                 C  sÚ   t | ƒ} |  d¡rd}|S |  d¡rd}|S |  d¡rd}|S |  d¡r(d}|S |  d¡r1| }|S |  d¡r:d	}|S |  d
¡rCd
}|S |  d¡rLd}|S |  d¡rUd}|S | dkr]d}|S | dkred}|S td| › d�ƒ‚)zA
    Find the "kind" string describing the given dtype name.
    )r@  rþ  r@  r0  r—  )ri   r‹  r+  r¡  Ú	timedeltar¤  r–   r_  rŽ  r  r`   zcannot interpret dtype of [rB  )r\   rž  rµ   )rG  r�  rZ   rZ   r[   rw  î  sF   

è
ê
ì
î
ð
ò
ô
öùûþrw  c                 C  sv   t | tƒr| j} t | jtƒrd| jj› d�}n| jj}| jjdv r*t 	|  
d¡¡} nt | tƒr2| j} t 	| ¡} | |fS )zJ
    Convert the passed data into a storable form and a dtype string.
    r-  rB  ÚmMr  )rU   r6   r  r$  r'   r7  rf   r�  rV   r³  r5  r/   r6  )r©  rx  rZ   rZ   r[   rv    s   


rv  c                   @  s:   e Zd ZdZ			ddd
d„Zdd„ Zdd„ Zdd„ ZdS )r�  zæ
    Carries out a selection operation on a tables.Table object.

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

    Nr{   r  r­   r“   r®   r_   r    c                 C  sV  || _ || _|| _|| _d | _d | _d | _d | _t|ƒrŒt	t
ƒ�d tj|dd�}|dv r}t |¡}|jtjkrV| j| j}}|d u rDd}|d u rL| j j}t ||¡| | _n't|jjtjƒr}| jd urj|| jk  ¡ sv| jd urz|| jk ¡ rzt
dƒ‚|| _W d   ƒ n1 s‡w   Y  | jd u r§|  |¡| _| jd ur©| j ¡ \| _| _d S d S d S )NFr+  )r+  Úbooleanr   z3where must have index locations >= start and < stop)r{   ru   r­   r®   Ú	conditionrØ  ÚtermsrP  r#   r   rµ   r   r2  rV   r³  r$  Úbool_r0  rî  Ú
issubclassrð   r+  r¶  ÚgenerateÚevaluate)rÜ   r{   ru   r­   r®   ÚinferredrZ   rZ   r[   rÝ   6  sF   

ÿ€î

ûzSelection.__init__c              
   C  sr   |du rdS | j  ¡ }z
t||| j jd�W S  ty8 } zd | ¡ ¡}td|› d|› d�ƒ}t|ƒ|‚d}~ww )z'where can be a : dict,list,tuple,stringN)r‚  r]   r  z-                The passed where expression: a*  
                            contains an invalid variable reference
                            all of the variable references must be a reference to
                            an axis (e.g. 'index' or 'columns'), or a data_column
                            The currently defined references are: z
                )	r{   r‚  r:   r]   Ú	NameErrorr	  r  r   rµ   )rÜ   ru   rŒ  rf  Úqkeysr  rZ   rZ   r[   rO  c  s"   
ÿûÿ
	€ózSelection.generatec                 C  sX   | j dur| jjj| j  ¡ | j| jd�S | jdur!| jj | j¡S | jjj| j| jd�S )ú(
        generate the selection
        Nr  )	rK  r{   Ú
read_wherer—   r­   r®   rP  r8  r(  rà   rZ   rZ   r[   rÁ   z  s   
ÿ
zSelection.selectc                 C  s”   | j | j}}| jj}|du rd}n|dk r||7 }|du r!|}n|dk r)||7 }| jdur<| jjj| j ¡ ||dd�S | jdurD| jS t 	||¡S )rT  Nr   T)r­   r®   r  )
r­   r®   r{   r0  rK  Úget_where_listr—   rP  rV   rî  )rÜ   r­   r®   r0  rZ   rZ   r[   rÞ  †  s"   
ÿ
zSelection.select_coordsrå  )r{   r  r­   r“   r®   r“   r_   r    )rñ   rè  ré  rê  rÝ   rO  rÁ   rÞ  rZ   rZ   rZ   r[   r�  *  s    û-r�  )r]   r^   r_   r`   )rh   ri   )r‹   NNFNTNNNNrƒ   rT   )rŒ   r�   rŽ   r`   r�   r�   r‘   r`   r’   r“   r”   r^   r•   r–   r—   r^   r˜   r–   r™   rš   r›   rœ   r�   rž   rŸ   r`   r]   r`   r_   r    )	Nr«   rƒ   NNNNFN)rŒ   r�   r‘   r`   rŸ   r`   ru   r¬   r­   r“   r®   r“   r¯   r°   r±   r–   r²   r“   )rÈ   rJ   rÉ   rJ   r_   r–   ra   )rÒ  r+   rK  rM   rÙ  r-   r_   r+   )rõ  r   r_   r!  rä  )r~  r$  rõ  r!  r£  r–   r_   r,   )r~  r$  rõ  r    r£  r–   r_   r  )r~  r$  rõ  r&  r£  r–   r_   r'  )
rf   r`   r˜   r-   r]   r`   rŸ   r`   r_   rñ  )r�  r`   r]   r`   rŸ   r`   r_   r$  )rf   r`   rø  rL   r¯   r	  )r©  r  r]   r`   rŸ   r`   r_   r  )r~  r  r0  r`   r]   r`   rŸ   r`   )r�  r`   r]   r`   rŸ   r`   )r�  r`   r_   r–   )rf   r`   rÍ  rC  r_   r`   )rG  r`   r_   r`   )r©  rL   )»rê  Ú
__future__r   Ú
contextlibr   rª  rî  r   r   rQ  r¹   r  Útextwrapr   Útypingr   r   r	   r
   r   r   r   rT  ÚnumpyrV   Úpandas._configr   r   r   r   Úpandas._libsr   r   r5  Úpandas._libs.libr   Úpandas._libs.tslibsr   Úpandas.compatr   Úpandas.compat._optionalr   Úpandas.compat.pickle_compatr   Úpandas.errorsr   r   r   r   r   Úpandas.util._decoratorsr   Úpandas.util._exceptionsr   Úpandas.core.dtypes.commonr    r!   r"   r#   r$   r%   Úpandas.core.dtypes.dtypesr&   r'   r(   r)   Úpandas.core.dtypes.missingr*   r  r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   Úpandas.core.arraysr6   r7   r8   Úpandas.core.arrays.string_r9   Úpandas.core.commonÚcoreÚcommonrc  Ú pandas.core.computation.pytablesr:   r;   Úpandas.core.constructionr<   r  r=   Úpandas.core.indexes.apir>   Úpandas.core.internalsr?   r@   Úpandas.io.commonrA   Úpandas.io.formats.printingrB   rC   Úcollections.abcrD   rE   rF   ÚtypesrG   r…   rH   rI   rJ   Úpandas._typingrK   rL   rM   rN   rO   rP   rQ   rR   rS   rÛ  rb   r\   rd   rg   rl   rv   rw   rë  rx   ry   r²  rx  r~   r   Úconfig_prefixÚregister_optionÚis_boolÚis_one_of_factoryr„   r‰   rŠ   rª   rÇ   r¿   r©   r3  rñ  rg  rl  rÁ  rÅ  rÆ  rí  rÃ  r>  rÄ  r  rË  rF  rÉ  rÇ  rÈ  rÆ  rÊ  r«  r  r/  r  r$  r®  r/  r»  r+  r>  r=  rŽ  rw  rv  r�  rZ   rZ   rZ   r[   Ú<module>   sB   $	 4(


üþ
ñ:ö 
#           (p  8   -   2g       x dz1C,ÿ
ÿÿ
'
@

O

*




#