o
    %je!                  	   @   s  d dl Z d dlmZ d dlZd dlZd dlZd dlmZm	Z	m
Z
mZmZmZmZmZ d dlmZ d dlmZmZ ejjgZdd Zdd	 Zd
d Zdd Zdd Zdd Zejdedddddee dgdd Z!dd Z"dd Z#dd  Z$ejd!d"d#g d$d%gd&d' Z%dS )(    N)BytesIO)CategoricalIndex	DataFrameHDFStoreIndex
MultiIndex_testing
date_rangeread_hdf)ensure_clean_store)Term_maybe_adjust_namec              	   C   s  t dtdd ttdtdtdd tdD tdd	}t| Y}|	d
| d}t
jt|d |jd
dgd W d    n1 sGw   Y  d}t
jt|d |jd
dgd W d    n1 shw   Y  W d    d S W d    d S 1 sw   Y  d S )N皙?x         ABCDZdtypec                 S      g | ]}d | qS zi- .0ir   r   e/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/pandas/tests/io/pytables/test_errors.py
<listcomp>        z,test_pass_spec_to_storer.<locals>.<listcomp>r   columnsindexdfzqcannot pass a column specification when reading a Fixed format store. this store must be selected in its entiretymatchA)r   zucannot pass a where specification when reading from a Fixed format store. this store must be selected in its entiretyz	columns=Awhere)r   nparangereshaper   listobjectranger   putpytestraises	TypeErrorselect)
setup_pathr!   storemsgr   r   r   test_pass_spec_to_storer   s(   
"r5   c              	   C   s   t dg di}t dg ditdddd}t| >}|jd|d	d
 td}tjt|d |jd|d	dd W d    n1 sCw   Y  W d    d S W d    d S 1 s[w   Y  d S )Na)         )r         z1/1/2000r9   periods)r    frametableformatz3incompatible kind in col [integer - datetime64[ns]]r"   T)rA   append)	r   r	   r   r-   reescaper.   r/   r0   )r2   Zdf1df2r3   r4   r   r   r   $test_table_index_incompatible_dtypes3   s   

"rF   c              
   C   s  t | f}dtdddfg}|D ]Q\}}tdtdd ttdt	d	td
d t
dD t	d	d}|||< td| d}tjt|d |d| | W d    n1 s]w   Y  qW d    n1 smw   Y  tdtdd ttdt	d	tdd t
dD t	d	d}d|d< d|d< tddd|d< | }t | ;}dtdtdg}tjt|d |d| W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Ndatei  r7   r8   r   r   r   r   r   c                 S   r   r   r   r   r   r   r   r   G   r   z;test_unimplemented_dtypes_table_columns.<locals>.<listcomp>r   r   [z&] is not implemented as a table columnr"   Zdf1_c                 S   r   r   r   r   r   r   r   r   R   r   fooZobj1barobj2Z	datetime1|zjCannot serialize the column [datetime1]
because its data contents are not [string] but [date] object dtypez+[date] is not implemented as a table columnZdf_unimplemented)r   datetimerG   r   r'   r(   r)   r   r*   r+   r,   rC   rD   r.   r/   r0   rB   Z_consolidatejoin)r2   r3   Zdtypesnfr!   r4   r   r   r   'test_unimplemented_dtypes_table_columns>   sN   

	"rQ   c              	   C   s0  t |}ttjddttdtdt	ddddd	}d
|d< d|j
|jdd df< |jd|dd td}tjt|d t  W d    n1 sPw   Y  td}tjt|d |dd W d    n1 srw   Y  d}tjt|d |dd W d    n1 sw   Y  W d    n1 sw   Y  | | }ttjddtdt	dddd	}|j|dddd t|ddd t|ddd | | }ttjddtdt	dddd	}|j|ddd  d!}tjt|d t|ddd W d    d S 1 sw   Y  d S )"Nr8   )
   r   r   r   z
2000-01-01rR   B)r=   freqr   rI   stringrJ   r   r   r!   r?   r@   z:__init__() missing 1 required positional argument: 'where'r"   zWcannot process expression [df.index[3]], [2000-01-06 00:00:00] is not a valid conditionzdf.index[3]zinvalid syntaxzindex>Z20130101r<   dfqT)keyrA   Zdata_columnsz0index>Timestamp('20130104') & columns=['A', 'B']r%   z
A>0 or C>0)rW   rA   a  The passed where expression: A>0 or C>0\n\s*contains an invalid variable reference\n\s*all of the variable references must be a reference to\n\s*an axis \(e.g. 'index' or 'columns'\), or a data_column\n\s*The currently defined references are: index,columns\n)r   r   r'   randomdefault_rngstandard_normalr   r*   r+   r	   locr    r-   rC   rD   r.   r/   r0   r   
ValueErrorr1   SyntaxErrorto_hdfr
   )tmp_pathr2   r3   r!   r4   pathrV   r   r   r   test_invalid_termsh   s\   



$ra   c           
   
   C   s  t tjdd}t dtjddi}t dtjddi}t dtjddi}t ddtftjddi}t| <}d}||| ||||fD ]$}t	d	}	t
jt|	d
 ||| W d    n1 stw   Y  qUW d    d S 1 sw   Y  d S )Nr8   )rR   r7   r6   rR   r7   r8   )1r8   rc   Zdf_diff_valerrorz?cannot match existing table structure for [0] on appending datar"   )r   r'   rX   rY   rZ   r+   r   rB   rC   rD   r.   r/   r\   )
r2   r!   rE   Zdf3Zdf4Zdf5r3   namedr4   r   r   r   7test_append_with_diff_col_name_types_raises_value_error   s$    
"rf   c              	   C   s   t tjddtdtdd}t| 2}d}tjt	|d |j
|dd	d
 W d    n1 s4w   Y  W d    d S W d    d S 1 sLw   Y  d S )Nr8   r   r:   abcdABCDEr    r   z)complib only supports \[.*\] compression.r"   r!   Zfoolib)rW   Zcomplib)r   r'   rX   rY   r*   tmZensure_cleanr.   r/   r\   r^   )r2   r!   r`   r4   r   r   r   test_invalid_complib   s   "rl   idxZ2019Dr9   UTC)rT   r=   tzabcc                 C   sh   t | | g}td|dgd}|| }tjtdd |j|dd W d    d S 1 s-w   Y  d S )Nr   r6   rj   zSaving a MultiIndexr"   r!   rW   )r   Zfrom_arraysr   r.   r/   NotImplementedErrorr^   )rm   r_   r2   mir!   r`   r   r   r   &test_to_hdf_multiindex_extension_dtype   s   	"ru   c                 C   sL   | ddd}d}t jt|d t| W d    d S 1 sw   Y  d S )Niodataz"legacy_hdf/incompatible_dataset.h5z_Dataset\(s\) incompatible with Pandas data types, not table, or no datasets found in HDF5 file.r"   )r.   r/   r\   r
   )datapathZ	data_pathmessager   r   r   test_unsuppored_hdf_file_error   s   
"rz   c                 C   s   t tjddtdtdd}||  }d}tjt|d t|d W d    n1 s/w   Y  |j	|d	d
 t
|dd}|  d}tjt|d t|d	 W d    d S 1 s_w   Y  d S )Nr8   rg   rh   ri   rj   zFile [\S]* does not existr"   rW   r!   rr   r)modez&The HDFStore must be open for reading.)r   r'   rX   rY   r*   r.   r/   OSErrorr
   r^   r   close)r2   r_   r!   r`   r4   r3   r   r   r   test_read_hdf_errors   s"   "r   c                  C   sF   d} t jt| d ttdd W d    d S 1 sw   Y  d S )Nz5Support for generic buffers has not been implemented.r"       r!   )r.   r/   rs   r
   r   )r4   r   r   r   #test_read_hdf_generic_buffer_errors   s   "r   bad_versionrb   )r7   Z12Z123c                 C   sD   d}t jt|d td| d W d    d S 1 sw   Y  d S )Nz5Version is incorrect, expected sequence of 3 integersr"   Zvalues_block_0)version)r.   r/   r\   r   )r   r4   r   r   r   )test_maybe_adjust_name_bad_version_raises   s   "r   )&rM   rv   r   rC   numpyr'   r.   Zpandasr   r   r   r   r   r   rk   r	   r
   Zpandas.tests.io.pytables.commonr   Zpandas.io.pytablesr   r   markZ
single_cpuZ
pytestmarkr5   rF   rQ   ra   rf   rl   Zparametrizer*   ru   rz   r   r   r   r   r   r   r   <module>   s6    (

*>

	