B
    Z0dUE                 @   s  d dl Z d dlZd dlmZmZ d dlZd dlZd dlm	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mZ d dlmZ dZejjZdd	 Zd
d Z dd Z!dd Z"dd Z#dd Z$dd Z%dd Z&dd Z'ej(ddd Z)dd Z*ej+dd ej,d!ej-d"gd#d$ Z.d%d& Z/ej+d'ej0ej1e2d(d)gd*d+ Z3d,d- Z4d.d/ Z5ej+dd ej,d!ej-d"gd0d1 Z6d@d2d3Z7dAd4d5Z8dBd6d7Z9d8d9 Z:d:d; Z;d<d= Z<d>d? Z=dS )C    N)catch_warningssimplefilter)	Timestamp)	DataFrameIndex
MultiIndexSeries_testingbdate_rangeread_hdf)_maybe_removeensure_clean_pathensure_clean_store)_test_decoratorsZbloscc          	      s   t    fdd}t  }t ||d| t  }t ||d| t  }t ||d| ttdtdd}|j	 dd	d
 t
 ddgd}t ||jdk | W d Q R X d S )Nc                s   |j  | f| t | S )N)to_hdfr   )keyobjkwargs)path Z/var/www/html/venv/lib/python3.7/site-packages/pandas/tests/io/pytables/test_round_trip.py	roundtrip'   s    z'test_conv_read_write.<locals>.roundtripZseriesZstring_seriesframe   )ABtableT)appendzindex>2)where   )tmZensure_cleanmakeTimeSeriesassert_series_equalmakeStringSeriesmakeDataFrameassert_frame_equalr   ranger   r   index)
setup_pathr   odfresultr   )r   r   test_conv_read_write$   s    
r,   c          	   C   sd   t dtjddditjdddd}t| .}|jd|dgd |d}t|| W d Q R X d S )Nad   
   )size)r'   r*   )Zdata_columns)r   r    Zrands_arrayr   r   selectr%   )r(   r*   storer+   r   r   r   test_long_strings;   s    "

r3   c          
   C   sz  t | }t }|jd d j|dddd |jdd  j|dddd tt|d| |jd d j|dddd |jdd  j|dddd tt|d| W d Q R X t | }t }|jd d j|ddd |jdd  j|dddd tt|d| |jd d j|dddd |jdd  j|ddd tt|d| W d Q R X t | }t }|j|dddd tt|d| |j|ddd	d tt|d| |j|ddd tt|d| ||d tt|d| W d Q R X t| ^}t }t|d |j	d|jd d ddd |j	d|jdd  ddd t|
d| t|d |j	d|jd d ddd |j	d|jdd  ddd t|
d| t|d |j	d|jd d ddd |j	d|jdd  ddd t|
d| t|d |j	d|jd d ddd |j	d|jdd  dd d t|
d| W d Q R X t | }t }d
}tjt|d |j|ddd	d W d Q R X tjt|d |j|dddd W d Q R X d}tjt|d |j|dddd W d Q R X tjt|d |j|dddd W d Q R X W d Q R X d}d| d}tjt|d t|d W d Q R X d S )Nr/   r*   Tr   )r   formatF)r   ZfixedfzCan only append to Tables)matchz)invalid HDFStore format specified \[foo\]foo zFile z does not exist)r   r    r$   Zilocr   r%   r   r   r   r   r1   pytestraises
ValueError	TypeErrorFileNotFoundError)r(   r   r*   r2   msgr   r   r   test_apiI   sx    







&r?   c          
   C   s   t | r}t |d< |d}|d }t|| |d}|d }t|| tjtdd |d W d Q R X W d Q R X d S )Nr-   z/az'No object named b in the file')r6   b)r   r    r!   getr"   r9   r:   KeyError)r(   r2   leftrightr   r   r   test_get   s    


rE   c             C   s$   t tjdd}t|tj|  d S )N2   r.   )r   nprandomrandn_check_roundtripr    r%   )r(   r*   r   r   r   test_put_integer   s    rK   c             C   s  t | }tddddgidd}|d| t|j|d j tddddgidd}|d	| t|j|d	 j td
}tj	t
|d |d	| W d Q R X ttjdgdgdggdddgd}|d| t|j|d j |jd dksttdd dD }d|d< d|d< |d d|d< |d dk|d< td|d< td|d< |d| |dj }dd  |jD |_tdddddddddd!	}| }| }t|| W d Q R X d S )"Nr-      r      Zf8)dtypeZdf_f8i8Zdf_i8zinvalid combination of [values_axes] on appending data [name->values_block_0,cname->values_block_0,dtype->float64,kind->float,shape->(1, 3)] vs current table [name->values_block_0,cname->values_block_0,dtype->int64,kind->integer,shape->None])r6   Zf4r   )columnsZdf_f4r   float32c             S   s"   i | ]}t tjd |d|qS )r   )rN   )r   rG   rH   randint).0cr   r   r   
<dictcomp>   s   z6test_table_values_dtypes_roundtrip.<locals>.<dictcomp>)rQ   float64int32int64int16int8r7   stringg      ?Zfloat322boolZ20130101Ztime1Z20130102Ztime2Zdf_mixed_dtypes1c             S   s   g | ]}t |qS r   )str)rS   ir   r   r   
<listcomp>   s    z6test_table_values_dtypes_roundtrip.<locals>.<listcomp>)	rQ   rV   rW   r\   rY   rZ   rX   objectzdatetime64[ns])r   r   r   r    r"   Zdtypesreescaper9   r:   r;   rG   arrayAssertionErrorZastyper   r1   Zvalue_countsr'   r   Z
sort_index)r(   r2   df1df2r>   r+   expectedr   r   r   "test_table_values_dtypes_roundtrip   sP    $

rh   c             C   s   t  }t|t j| d t  }t|t j| d t|jt|jtd}t|t j| d t|j	tt
j|jtdtd}t|t j| dd d S )N)r   )rN   F)r   check_index_type)r    r#   rJ   r"   r!   r   r'   r   r`   valuesrG   Zasarray)r(   stsZts2Zts3r   r   r   test_series  s     rm   c             C   s4   t jd}tt jd|d}t|tj| d d S )Nr/   )r'   )r   )rG   rH   rI   r   rJ   r    r"   )r(   r'   rk   r   r   r   test_float_index  s    rn   c          	   C   sl   t d}dddg}t jdd}t|||d}tdd	$ td
tj	j
 t|tj| d W d Q R X d S )Nr/   )g        g      ?)g       @g      @)g      @g      @   )rM   r/   )r'   rP   T)recordignore)r   )rG   ZarangerH   rI   Zreshaper   r   r   pderrorsPerformanceWarningrJ   r    r%   )r(   colidxdataZDFr   r   r   test_tuple_index  s    

rx   z(ignore::pandas.errors.PerformanceWarningc          	   C   s  t dd tjd}dd }W d Q R X t dd" t|ddg}t||| d W d Q R X t dd( t|tj dg}t||| d W d Q R X t dd" t|ddg}t||| d W d Q R X t dd( t|tj d	g}t||| d W d Q R X t dd t|ddg}t||| d t|tj dg}t||| d t|ddg}t||| d t|tj d	g}t||| d t|d
dg}t||| d t|ddg}t||| d t|ddg}t||| d t|tdddtdddg}t||| d W d Q R X d S )NT)rp   r   c             S   s   t j| |ddS )NT)ri   )r    r"   )lrr   r   r   <lambda>,      z"test_index_types.<locals>.<lambda>r   y)r   r-   gGz?r@   rL   g{Gz?r   i  )	r   rG   rH   rI   r   rJ   datetimetodaydate)r(   rj   funcZserr   r   r   test_index_types'  sB     r   c             C   sZ   t dd}ttjt||d}yt|tj| d W n t	k
rT   t
d Y nX d S )Nz1/1/1940z1/1/1960)r'   )r   z'known failure on some windows platforms)r
   r   rG   rH   rI   lenrJ   r    r"   OverflowErrorr9   skip)r(   Zdrrl   r   r   r   test_timeseries_preepochZ  s    
r   compressionFT)Zmarksc          	   C   s   t  }tj|jd< tj|jd< t|t j|| d t|t j|| d t  }t|t j|| d t	|8}tj
t||d< ||d< |d }|j stW d Q R X t|d d t j|d d S )N)r   r   )r   rM   )r   r   r7   r*   r   )r   )r    r$   rG   nanrj   _check_roundtrip_tabler%   rJ   ZmakeTimeDataFramer   rH   rI   r   Z_mgrZis_consolidatedrd   )r   r(   r*   Ztdfr2   reconsr   r   r   
test_framed  s     
r   c             C   s   t td}t dtd}t }tdddgd}tdd	d
gd}t|tj| d t|tj| d t|tj| d t|tj| d t|tj| d d S )N)rN   Zmyseries)namerN   r-   r@   rT   )r'   der5   )rP   )r   )r   r`   r   rJ   r    r"   r%   )r(   s0s1Zdf0re   rf   r   r   r   test_empty_series_frame  s    
r   rN   zm8[ns]zM8[ns]c             C   s   t | d}t|tj|d d S )N)rN   )r   )r   rJ   r    r"   )rN   r(   rk   r   r   r   test_empty_series  s    
r   c             C   sB   dd t ddD }ttjt|d|d}t|tj| d d S )Nc             S   s   g | ]}|  qS r   )r   )rS   xr   r   r   r_     s    z,test_can_serialize_dates.<locals>.<listcomp>z1/1/2000z	1/30/2000   )r'   )r   )	r
   r   rG   rH   rI   r   rJ   r    r%   )r(   rngr   r   r   r   test_can_serialize_dates  s    r   c             C   s   t ddddgdddggdddd	d	d
d
dddg
dd	d
dd	d	d
dd	d
g
gddgd}ttjdd|dddgd}t|tj| d t|jtj| d t|d tj	| d t
| "}||d< |d }t|| W d Q R X d S )Nr7   barZbazZquxonetwothreer   rL   r   rM   )Zlevelscodesnamesr/   r   r   C)r'   rP   )r   r   )r   r   rG   rH   rI   rJ   r    r%   Tr"   r   )r(   r'   r   r2   r   r   r   r   test_store_hierarchical  s    .
r   c          	   C   s   dd }| }| }t |tj|d t |tj|d t|6}||d< t|d | ||d< t|d | W d Q R X t |d tj|| d t |d tj|| d t |d tj|| d d S )	Nc              S   sP   t  } d| d< d| d< | d dk| d< | d dk| d	< d
| d< d| d< |  S )Nr7   obj1r   obj2r   r   bool1r   Zbool2rL   int1r   Zint2)r    r$   Z_consolidate)r*   r   r   r   	_make_one  s    z#test_store_mixed.<locals>._make_one)r   r   r   )r   r   r   r   )rJ   r    r%   r   r"   )r   r(   r   re   rf   r2   r   r   r   test_store_mixed  s2    

r   c          	   K   sL   i }|rt |d< t|df|$}| |d< |d }||| f| W d Q R X d S )Ncomplibwr   )_default_compressorr   )r   
comparatorr   r   r   optionsr2   	retrievedr   r   r   rJ     s    rJ   c       
   	   K   sn   i }|r|pt |d< t|df|B}||d< |d }|||f| ||d< |d }	||	|f| W d Q R X d S )Nr   r   r   )r   r   )
selfr   r   r   r   r   r   r2   r   Zagainr   r   r   _check_double_roundtrip  s    r   c          	   C   sP   i }|rt |d< t|df|(}|jd| dd |d }|||  W d Q R X d S )Nr   r   r   r   )r4   )r   r   put)r   r   r   r   r   r2   r   r   r   r   r     s    r   c          	   C   sV   ddg}t dd: tdtjj ttjt	||}t
|tj| d W d Q R X d S )Nu   σu   σσT)rp   rq   )r   )r   r   rr   rs   rt   r   rG   rH   rI   r   rJ   r    r"   )r(   Zunicode_valuesrk   r   r   r   test_unicode_index
  s
    r   c          	   C   s   d}t d|gi}t| .}|jd|ddd |d}t|| W d Q R X t d|gddgd	}t| .}|jd|ddd |d}t|| W d Q R X d S )
Nu   Δr   r*   r   zutf-8)r4   encodingr-   r@   )r   r   )r   r   r   rA   r    r%   )r(   charr*   r2   r+   r   r   r   test_unicode_longer_encoded  s    



r   c             C   sP   t dddgdddgddd	gd
}t }|jd d |d< t|tj| d d S )NrL   r   rM   g      ?g       @g      @r-   r@   rT   )r-   r@   rT   r   )r   )r   r    r!   r'   rJ   r%   )r(   r*   rl   r   r   r   test_store_datetime_mixed%  s    "r   c          	   C   sp   t ddgddgd}t| H}|j|ddd t|d}t|| ||sTt||sbtW d Q R X d S )	NrL   r   r   r}   )r   r   r*   r   )r4   )r   r   r   r   r    r%   equalsrd   )r(   r*   r   otherr   r   r   test_round_trip_equals-  s    

r   )F)F)F)>r~   ra   warningsr   r   numpyrG   r9   Zpandas._libs.tslibsr   Zpandasrr   r   r   r   r   r	   r    r
   r   Zpandas.tests.io.pytables.commonr   r   r   Zpandas.utilr   tdr   markZsingleZ
pytestmarkr,   r3   r?   rE   rK   rh   rm   rn   rx   filterwarningsr   r   ZparametrizeparamZskip_if_windows_python_3r   r   rX   rV   r`   r   r   r   r   rJ   r   r   r   r   r   r   r   r   r   r   <module>   sJ   $	aA3
 !$ .


