a
    j=ic3+                  	   @   s  d dl Z d dlZd dlZd dlmZ d dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZ d dlZd dlmZ d dlm  mZ dd ej D Zejdejdg dg d	g g d
dejdg d ddgejdg ddd Zejdejdg dg d	g g d
dejdg d ddgejdddgdd Zejddddiejfdi ej fdi ej!fgdd Z"ejdddddejddifdi ej d d!ifdi ej!i fgd"d# Z#d$d% Z$d&d' Z%d(d) Z&d*d+ Z'd,d- Z(d.d/ Z)ejdejdg dg d	g g d
dejdg d ddgejdg dd0d1 Z*ejdejdg dg d	g g d
dejdg d ddgejdg dd2d3 Z+ejd4d5e
j,fd6ej-fgd7d8 Z.d9d: Z/d;d< Z0d=d> Z1d?d@ Z2dS )A    N)Path)is_platform_windowsc                 C   s   i | ]\}}||qS  r   ).0keyvaluer   r   q/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/pandas/tests/io/test_compression.py
<dictcomp>   s   r	   objd   g~Ϛ?g9DܜJ?g>D)?g.4i(@g33333@g̤AXYZcolumnsr   namemethod)	to_pickleto_jsonto_csvc                 C   s   |dkrddd}t  X}t| |||d tj|}t| ||d d tj|}||ksdJ W d    n1 sx0    Y  d S )Ntarw:gzr   modecompressiontmensure_cleangetattrospathgetsize)r
   r   compression_onlyr%   compressed_sizeuncompressed_sizer   r   r   test_compression_size   s    

r*   r   r   c              	   C   s  t  t}tj||dkrdnd|d,}t| ||j |jjrDJ W d    n1 sX0    Y  tj	|}W d    n1 s0    Y  t  t}tj|dd d,}t| ||j |jjrJ W d    n1 s0    Y  tj	|}||ksJ W d    n1 s0    Y  d S )Nr   r   wr   )
r!   r"   icom
get_handler#   handleclosedr$   r%   r&   )r
   r   r'   r%   handlesr(   r)   r   r   r   test_compression_size_fh1   s     
**
*r1   z'write_method, write_kwargs, read_methodindexFr   c                 C   s   t jg dg dgg dd}t| }td| 2}t|| |fi | |||d}W d    n1 sl0    Y  t|| d S )N)g      ?r   )g333333@      r   r   
compressedr   )pd	DataFrame_compression_to_extensionr!   r"   r#   assert_frame_equal)write_methodwrite_kwargsread_methodr'   input	extensionr%   outputr   r   r   ,test_dataframe_compression_defaults_to_inferN   s    *rA   z1write_method,write_kwargs,read_method,read_kwargsT)r2   headersqueezetypZseriesc           
      C   s   t jg ddd}t| }td| l}t|| |fi | d|v rr| }|d= ||fd|i|d}	n||fd|i|}	W d    n1 s0    Y  tj|	|dd	 d S )
N)r   r4   
   r   r   r6   rC   r   r   F)Zcheck_names)	r7   Seriesr9   r!   r"   r#   copyrC   Zassert_series_equal)
r;   r<   r=   Zread_kwargsr'   r>   r?   r%   kwargsr@   r   r   r   )test_series_compression_defaults_to_inferb   s    2rJ   c              
   C   s   t jdg dg dg g dd}t z}tj|d| dJ}tt  |j|j	| d W d    n1 sn0    Y  W d    n1 s0    Y  W d    n1 s0    Y  d S )Nr   r   r   r   r   r+   r   )
r7   r8   r!   r"   r,   r-   Zassert_produces_warningRuntimeWarningr   r.   )r'   dfr%   r0   r   r   r   test_compression_warning}   s    
rM   c              	   C   s   t  }t  n}t|dd*}|j|d| d |d W d   n1 sN0    Y  t |tj|d| d W d   n1 s0    Y  t	
 }|j|d| d |d t |tj|d| d dS )z?
    Binary file handles support compression.

    GH22555
    wb)r   )r   r   r   N)Z	index_colr   )r!   makeDataFramer"   openr   seekr:   r7   read_csvioBytesIO)r'   rL   r%   filer   r   r   test_compression_binary   s    
("
rV   c                  C   s   t  } ddd}t  V}t|}| j||d td | }| j||d || ksbJ W d   n1 sv0    Y  dS )z
    Gzip should create reproducible archives with mtime.

    Note: Archives created with different filenames will still be different!

    GH 28103
    gzip   r   mtimer   r5   N)r!   rO   r"   r   r   timesleep
read_bytes)rL   compression_optionsr%   r@   r   r   r   #test_gzip_reproducibility_file_name   s    


r_   c                  C   sh   t  } ddd}t }| j||dd | }td t }| j||dd || ksdJ dS )zL
    Gzip should create reproducible archives with mtime.

    GH 28103
    rW   rX   rY   rN   )r   r   r5   N)r!   rO   rS   rT   r   getvaluer[   r\   )rL   r^   bufferr@   r   r   r   %test_gzip_reproducibility_file_object   s    

rb   c                  C   s&   t d} tjtjd| gtjd dS )z6Tests if import pandas works when lzma is not present.zT        import sys
        sys.modules['lzma'] = None
        import pandas
        -cstderrNtextwrapdedent
subprocesscheck_outputsys
executablePIPEcoder   r   r   test_with_missing_lzma   s    rp   c                  C   s&   t d} tjtjd| gtjd dS )z\Tests if RuntimeError is hit when calling lzma without
    having the module available.
    z
        import sys
        import pytest
        sys.modules['lzma'] = None
        import pandas as pd
        df = pd.DataFrame()
        with pytest.raises(RuntimeError, match='lzma module'):
            df.to_csv('foo.csv', compression='xz')
        rc   rd   Nrf   rn   r   r   r   test_with_missing_lzma_runtime   s    rq   c                 C   sz   t  ^}t| ||dd tj|}t| ||dddd tj|}||k sXJ W d    n1 sl0    Y  d S )NrW   r   rX   r   compresslevelr    )r
   r   r%   Zcompressed_size_defaultZcompressed_size_fastr   r   r   test_gzip_compression_level   s    
rt   c                 C   sD   t  (}t| ||dddd W d   n1 s60    Y  dS )zGH33196 bzip needs file size > 100k to show a size difference between
    compression levels, so here we just check if the call works when
    compression is passed as a dict.
    bz2rX   rr   r   N)r!   r"   r#   )r
   r   r%   r   r   r   test_bzip_compression_level   s    
rv   zsuffix,archive.zipz.tarc              	   C   sz   t j| dZ}||d}|  tjtdd t| W d    n1 sN0    Y  W d    n1 sl0    Y  d S )Nfilenamer+   zZero files foundmatch)r!   r"   closepytestraises
ValueErrorr7   rR   )suffixarchiver%   rU   r   r   r   test_empty_archive_zip  s
    
r   c               	   C   s   t jddt} t| d}|dd |dd |  tjtdd t	
|  W d    n1 sh0    Y  W d    n1 s0    Y  d S )	Nrw   rx   r+   a.csvzfoo,barb.csvz Multiple files found in ZIP filerz   )r!   r"   zipfileZipFilewritestrr|   r}   r~   r   r7   rR   )r%   rU   r   r   r   test_ambiguous_archive_zip#  s    r   c               	   C   s@  t   } tj| d}t|d}|d W d    n1 sD0    Y  tj| d}t|d}|d W d    n1 s0    Y  tj| d}t|d(}|	|d |	|d W d    n1 s0    Y  t
jtdd t| W d    n1 s0    Y  W d    n1 s20    Y  d S )Nr   r+   zfoo,bar
r   zarchive.tarz#Multiple files found in TAR archiverz   )r!   Zensure_clean_dirr$   r%   joinrP   writetarfileTarFileaddr}   r~   r   r7   rR   )dirZcsvAPathaZcsvBPathbZtarpathr   r   r   r   test_ambiguous_archive_tar-  s    ((*r   c               
   C   s   t jdd} tjddggddgdj| dd	d
dd t| }tj|d\}|	 }t
|dksjJ ||d  d}t rd}nd}||ksJ W d    n1 s0    Y  W d    n1 s0    Y  W d    n1 s0    Y  d S )Nz.foorx   12Zfoobarr   r   r   r   F)r   r2   )fileobjrX   r   utf8zfoo,bar
1,2
zfoo,bar
1,2
)r!   r"   r7   r8   r   rW   rP   r   r   
getmemberslenextractfilereaddecoder   )rU   Zuncompressedr   memberscontentexpectedr   r   r   !test_tar_gz_to_different_filename?  s     r   c               	   C   sZ   t  >} tj| dd W d    n1 s.0    Y  W d    n1 sL0    Y  d S )Nr+   )r   r   )rS   rT   r,   Z_BytesTarFile)ra   r   r   r   test_tar_no_error_on_closeS  s    
r   )3rW   rS   r$   pathlibr   ri   rk   r   rg   r[   r   r}   Zpandas.compatr   Zpandasr7   Zpandas._testingZ_testingr!   Zpandas.io.commoncommonr,   Z_extension_to_compressionitemsr9   markZparametrizer8   rG   r*   r1   rR   	read_jsonZread_picklerA   rJ   rM   rV   r_   rb   rp   rq   rt   rv   r   r   r   r   r   r   r   r   r   r   r   <module>   s   








	

