a
    Pf                   	   @   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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| }|	d
| d}t
jt|d  |jd
dgd W d    n1 s0    Y  d}t
jt|d  |jd
dgd W d    n1 s0    Y  W d    n1 s0    Y  d S )N皙?x         ABCDZdtypec                 S   s   g | ]}d | qS zi- .0ir   r   ]/var/www/ai-form-bot/venv/lib/python3.9/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    
.r4   c              	   C   s   t dg di}t dg ditdddd}t| j}|jd|d	d
 td}tjt|d" |jd|d	dd W d    n1 s0    Y  W d    n1 s0    Y  d S )Na)         )r         z1/1/2000r8   periods)r   frametableformatz3incompatible kind in col [integer - datetime64[ns]]r!   T)r@   append)	r   r	   r   r,   reescaper-   r.   r/   )r1   Zdf1df2r2   r3   r   r   r   $test_table_index_incompatible_dtypes3   s    

rE   c              
   C   s  t | }dtdddfg}|D ]\}}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    q"1 s0    Y  q"W d    n1 s0    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 | V}td}tjt|d |d| W d    n1 s0    Y  W d    n1 s0    Y  d S )Ndatei  r6   r7   r   r   r   r   r   c                 S   s   g | ]}d | qS 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   s   g | ]}d | qS r   r   r   r   r   r   r   R   r   fooZobj1barobj2Z	datetime1zjCannot serialize the column [datetime1]
because its data contents are not [string] but [date] object dtypeZdf_unimplemented)r   datetimerF   r   r&   r'   r(   r   r)   r*   r+   rB   rC   r-   r.   r/   rA   Z_consolidate)r1   r2   Zdtypesnfr    r3   r   r   r   'test_unimplemented_dtypes_table_columns>   s6    
P
rN   c              	   C   s4  t |4}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 s0    Y  td}tjt|d |dd W d    n1 s0    Y  d}tjt|d |dd W d    n1 s&0    Y  W d    n1 sF0    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    n1 s&0    Y  d S )"Nr7   )
   r   r   r   z
2000-01-01rO   B)r<   freqr   rH   stringrI   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)keyr@   Zdata_columnsz0index>Timestamp('20130104') & columns=['A', 'B']r$   z
A>0 or C>0)rT   r@   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,   rB   rC   r-   r.   r/   r   
ValueErrorr0   SyntaxErrorto_hdfr
   )tmp_pathr1   r2   r    r3   pathrS   r   r   r   test_invalid_termsc   sP    
$*L

r^   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| v}d}||| ||||fD ]H}t	d	}	t
jt|	d
 ||| W d    q1 s0    Y  qW d    n1 s
0    Y  d S )Nr7   )rO   r6   r5   rO   r6   r7   )1r7   r`   Zdf_diff_valerrorz?cannot match existing table structure for [0] on appending datar!   )r   r&   rU   rV   rW   r*   r   rA   rB   rC   r-   r.   rY   )
r1   r    rD   Zdf3Zdf4Zdf5r2   namedr3   r   r   r   7test_append_with_diff_col_name_types_raises_value_error   s     
rc   c              	   C   s   t tjddtdtdd}t| R}d}tjt	|d  |j
|dd	d
 W d    n1 sh0    Y  W d    n1 s0    Y  d S )Nr7   r   r9   abcdABCDEr   r   z)complib only supports \[.*\] compression.r!   r    Zfoolib)rT   Zcomplib)r   r&   rU   rV   r)   tmZensure_cleanr-   r.   rY   r[   )r1   r    r]   r3   r   r   r   test_invalid_complib   s    ri   idxZ2019Dr8   UTC)rQ   r<   tzabcc                 C   sf   t | | g}td|dgd}|| }tjtdd |j|dd W d    n1 sX0    Y  d S )Nr   r5   rg   zSaving a MultiIndexr!   r    rT   )r   Zfrom_arraysr   r-   r.   NotImplementedErrorr[   )rj   r\   r1   mir    r]   r   r   r   &test_to_hdf_multiindex_extension_dtype   s
    	rr   c                 C   sJ   | ddd}d}t jt|d t| W d    n1 s<0    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.   rY   r
   )datapathZ	data_pathmessager   r   r   test_unsuppored_hdf_file_error   s
    rw   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^0    Y  |j	|d	d
 t
|dd}|  d}tjt|d t|d	 W d    n1 s0    Y  d S )Nr7   rd   re   rf   rg   zFile [\S]* does not existr!   rT   r    ro   r)modez&The HDFStore must be open for reading.)r   r&   rU   rV   r)   r-   r.   OSErrorr
   r[   r   close)r1   r\   r    r]   r3   r2   r   r   r   test_read_hdf_errors   s    (r|   c                  C   sD   d} t jt| d ttdd W d    n1 s60    Y  d S )Nz5Support for generic buffers has not been implemented.r!   r   r    )r-   r.   rp   r
   r   )r3   r   r   r   #test_read_hdf_generic_buffer_errors   s    r}   bad_versionr_   )r6   Z12Z123c                 C   sB   d}t jt|d td| d W d    n1 s40    Y  d S )Nz5Version is incorrect, expected sequence of 3 integersr!   Zvalues_block_0)version)r-   r.   rY   r   )r~   r3   r   r   r   )test_maybe_adjust_name_bad_version_raises   s    r   )&rK   rs   r   rB   numpyr&   r-   Zpandasr   r   r   r   r   r   rh   r	   r
   Zpandas.tests.io.pytables.commonr   Zpandas.io.pytablesr   r   markZ
single_cpuZ
pytestmarkr4   rE   rN   r^   rc   ri   Zparametrizer)   rr   rw   r|   r}   r   r   r   r   r   <module>   s4   (
%>

	