o
    ҷh                  	   @   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 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
MultiIndex_testing
date_rangeread_hdf)ensure_clean_store)Term_maybe_adjust_namec              	   C   s   t  }t| Y}|d| d}tjt|d |jddgd W d    n1 s+w   Y  d}tjt|d |jddgd W d    n1 sLw   Y  W d    d S W d    d S 1 sdw   Y  d S )	Ndfzqcannot pass a column specification when reading a Fixed format store. this store must be selected in its entiretymatchA)columnszucannot pass a where specification when reading from a Fixed format store. this store must be selected in its entiretyz	columns=Awhere)tmmakeDataFramer
   putpytestraises	TypeErrorselect)
setup_pathr   storemsg r   W/var/www/html/venv/lib/python3.10/site-packages/pandas/tests/io/pytables/test_errors.pytest_pass_spec_to_storer   s    
"r    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)         )         z1/1/2000r$   periods)indexframetableformatz/incompatible kind in col [integer - datetime64]r   T)r.   append)	r   r   r
   r   reescaper   r   r   )r   df1df2r   r   r   r   r   $test_table_index_incompatible_dtypes.   s   

"r4   c              
   C   s`  t | J}dtdddfg}|D ]5\}}t }|||< td| d}tjt	|d |
d| | W d    n1 sAw   Y  qW d    n1 sQw   Y  t }d	|d
< d|d< tddd|d< | }t | 3}td}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  r"   r#   [z&] is not implemented as a table columnr   df1_fooobj1barobj2	datetime1zjCannot serialize the column [datetime1]
because its data contents are not [string] but [date] object dtypedf_unimplemented)r
   datetimer5   r   r   r0   r1   r   r   r   r/   _consolidate)r   r   dtypesnfr   r   r   r   r   'test_unimplemented_dtypes_table_columns9   s6   

"rC   c              	   C   s  t |}t }d|d< d|j|jdd df< |jd|dd td	}tj	t
|d
 t  W d    n1 s;w   Y  td}tj	t|d
 |dd W d    n1 s]w   Y  d}tj	t|d
 |dd W d    n1 s|w   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 sw   Y  d S )Nr8   stringr:   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>r#   )
   r%   ABCD20130101rE   r(   )r   r*   dfqT)r.   data_columnsz0index>Timestamp('20130104') & columns=['A', 'B']r   z
A>0 or C>0a  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   makeTimeDataFramelocr*   r   r0   r1   r   r   r   r   
ValueErrorr   SyntaxErrorr   nprandomdefault_rngstandard_normallistr   to_hdfr	   )tmp_pathr   r   r   r   pathrH   r   r   r   test_invalid_termsV   sT   



"rV   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 )Nr#   )rE   r"   r!   rE   r"   r#   )1r#   rX   df_diff_valerrorz?cannot match existing table structure for [0] on appending datar   )r   rN   rO   rP   rQ   objectr
   r/   r0   r1   r   r   rL   )
r   r   r3   df3df4df5r   namedr   r   r   r   7test_append_with_diff_col_name_types_raises_value_error   s$    
"r`   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 )Nr#   r%   r&   abcdABCDEr*   r   z)complib only supports \[.*\] compression.r   r   foolib)complib)r   rN   rO   rP   rR   r   ensure_cleanr   r   rL   rS   )r   r   rU   r   r   r   r   test_invalid_complib   s   "rh   idx2019Dr$   UTC)freqr)   tzabcc                 C   sf   t | | g}td|dgd}|| }tjtdd ||d W d    d S 1 s,w   Y  d S )Nr   r!   rd   zSaving a MultiIndexr   r   )r   from_arraysr   r   r   NotImplementedErrorrS   )ri   rT   r   mir   rU   r   r   r   &test_to_hdf_multiindex_extension_dtype   s   	"rs   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   rL   r	   )datapath	data_pathmessager   r   r   test_unsuppored_hdf_file_error   s   
"ry   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  |	|d	 t
|d
d}|  d}tjt|d t|d	 W d    d S 1 s^w   Y  d S )Nr#   ra   rb   rc   rd   zFile [\S]* does not existr   keyr   r)modez&The HDFStore must be open for reading.)r   rN   rO   rP   rR   r   r   OSErrorr	   rS   r   close)r   rT   r   rU   r   r   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   rq   r	   r   )r   r   r   r   #test_read_hdf_generic_buffer_errors   s   "r   bad_versionrW   )r"   12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   values_block_0)version)r   r   rL   r   )r   r   r   r   r   )test_maybe_adjust_name_bad_version_raises   s   "r   )%r>   rt   r   r0   numpyrN   r   pandasr   r   r   r   r   r   r   r	   pandas.tests.io.pytables.commonr
   pandas.io.pytablesr   r   mark
single_cpu
pytestmarkr    r4   rC   rV   r`   rh   parametrizerR   rs   ry   r   r   r   r   r   r   r   <module>   s6    $	:

	