B
    Z0dV              	   @   s  d dl Z d dlmZ d dlZd dlm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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)catch_warnings)CategoricalIndex	DataFrameHDFStore
MultiIndex_testing
date_rangeread_hdf)ensure_clean_pathensure_clean_store)Term_maybe_adjust_namec          
   C   s   t  }t| n}|d| d}tjt|d |jddgd W d Q R X d}tjt|d |jddgd W d Q R X W d Q R X 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   V/var/www/html/venv/lib/python3.7/site-packages/pandas/tests/io/pytables/test_errors.pytest_pass_spec_to_storer   s    
r    c          
   C   s   t ddddgi}t ddddgitddd	d
}t| L}|jd|dd td}tjt|d |jd|ddd W d Q R X W d Q R X d S )Na                  z1/1/2000)periods)indexframetable)formatz/incompatible kind in col [integer - datetime64])r   T)r,   append)	r   r	   r   r   reescaper   r   r   )r   Zdf1df2r   r   r   r   r   $test_table_index_incompatible_dtypes3   s    

r1   c             C   s
  t | z}dtdddfg}x^|D ]V\}}t }|||< td| d}tjt	|d |
d| | W d Q R X q$W W d Q R X t }d	|d
< d|d< tddd|d< | jdd}t | 6}td}tjt	|d |
d| W d Q R X W d Q R X d S )Ndatei  r"   r#   [z&] is not implemented as a table column)r   Zdf1_fooZobj1barobj2Z	datetime1T)datetimezjCannot serialize the column [datetime1]
because its data contents are not [string] but [date] object dtypeZdf_unimplemented)r   r7   r2   r   r   r.   r/   r   r   r   r-   Z_consolidate_convert)r   r   Zdtypesnfr   r   r   r   r   'test_unimplemented_dtypes_table_columns>   s$    
*
r;   c             C   s  t | }tdd t }d|d< d|j|jdd df< |jd|d	d
 td}t	j
t|d t  W d Q R X td}t	j
t|d |dd W d Q R X d}t	j
t|d |dd W d Q R X W d Q R X W d Q R X t| X}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 W d Q R X t| f}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 Q R X W d Q R X d S )NT)recordr4   stringr5   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ABCDZ20130101)r(   )r   r)   dfq)r,   Z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   r   ZmakeTimeDataFramelocr)   r   r.   r/   r   r   r   r   
ValueErrorr   SyntaxErrorr   r   nprandomrandnlistr	   to_hdfr
   )r   r   r   r   pathr?   r   r   r   test_invalid_terms]   sD    
*

rI   c       
      C   s   t tjdd}t dtjdi}t dtjdi}t dtjdi}t ddtftjdi}t| h}dtd }||| xD||||fD ]4}t	
d	}	tjt|	d
 ||| W d Q R X qW W d Q R X d S )Nr>   r"   r!   )r"   r#   )1r#   rJ   r#   Zdf_z?cannot match existing table structure for [0] on appending data)r   )r   rC   rD   rE   objectr   r   Zrandsr-   r.   r/   r   r   rA   )
r   r   r0   Zdf3Zdf4Zdf5r   namedr   r   r   r   7test_append_with_diff_col_name_types_raises_value_error   s    
rN   c          
   C   sh   t tjddtdtdd}t| 4}d}tjt	|d |j
|dd	d
 W d Q R X W d Q R X d S )Nr%   r&   abcdABCDE)r)   r   z)complib only supports \[.*\] compression.)r   r   Zfoolib)Zcomplib)r   rC   rD   randrF   r   Zensure_cleanr   r   rA   rG   )r   r   rH   r   r   r   r   test_invalid_complib   s
     rR   idxZ2019Dr$   UTC)freqr(   tzabcc          
   C   s\   t | | g}td|dgd}t|,}tjtdd ||d W d Q R X W d Q R X d S )Nr   r!   )r)   r   zSaving a MultiIndex)r   r   )r   Zfrom_arraysr   r   r   r   NotImplementedErrorrG   )rS   r   mir   rH   r   r   r   &test_to_hdf_multiindex_extension_dtype   s
    	
r[   c          	   C   s6   | ddd}d}t jt|d t| W d Q R X 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   rA   r
   )ZdatapathZ	data_pathmessager   r   r   test_unsuppored_hdf_file_error   s    r_   c          
   C   s   t tjddtdtdd}t| v}d}tjt|d t	|d W d Q R X |
|d	 t|d
d}|  d}tjt|d t	|d	 W d Q R X W d Q R X d S )Nr%   r&   rO   rP   )r)   r   zFile [\S]* does not exist)r   keyr   r)modez&The HDFStore must be open for reading.)r   rC   rD   rQ   rF   r   r   r   IOErrorr
   rG   r   close)r   r   rH   r   r   r   r   r   test_read_hdf_errors   s     
re   c           	   C   s0   d} t jt| d ttdd W d Q R X d S )Nz5Support for generic buffers has not been implemented.)r       r   )r   r   rY   r
   r   )r   r   r   r   #test_read_hdf_generic_buffer_errors   s    rg   bad_version)r"   r#   )r"   Z12Z123c          	   C   s.   d}t jt|d td| d W d Q R X d S )Nz5Version is incorrect, expected sequence of 3 integers)r   Zvalues_block_0)version)r   r   rA   r   )rh   r   r   r   r   )test_maybe_adjust_name_bad_version_raises   s    rj   )(r7   r\   r   r.   warningsr   numpyrC   r   Zpandasr   r   r   r   r   r   r	   r
   Zpandas.tests.io.pytables.commonr   r   Zpandas.io.pytablesr   r   markZsingleZ
pytestmarkr    r1   r;   rI   rN   rR   ZparametrizerF   r[   r_   re   rg   rj   r   r   r   r   <module>   s.   $	@