
    d*              	       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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c mZ d ej                                        D             Zej                            d ej        dg dg dgz  g d	
           ej        dg dz  d          g          ej                            dg d          d                         Zej                            d ej        dg dg dgz  g d	
           ej        dg dz  d          g          ej                            dddg          d                         Zej                            ddddiej        fdi ej         fdi ej!        fg          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             Z#d Z$d  Z%d! Z&d" Z'd# Z(d$ Z)ej                            d ej        dg dg dgz  g d	
           ej        dg dz  d          g          ej                            dg d          d%                         Z*ej                            d ej        dg dg dgz  g d	
           ej        dg dz  d          g          ej                            dg d          d&                         Z+ej                            d'd(e
j,        fd)ej-        fg          d*             Z.d+ Z/d, Z0d- Z1d. Z2dS )/    N)Path)is_platform_windowsc                     i | ]\  }}||	S  r   ).0keyvalues      \/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/pandas/tests/io/test_compression.py
<dictcomp>r      s+       3E3      objd   g~Ϛ?g9DܜJ?g>D)?g.4i(@g33333@g̤AXYZcolumnsr   namemethod)	to_pickleto_jsonto_csvc                 n   |dk    rddd}t          j                    5 } t          | |          ||           t          j                            |          } t          | |          |d            t          j                            |          }||k    sJ 	 d d d            d S # 1 swxY w Y   d S )Ntarw:gzr   modecompressiontmensure_cleangetattrospathgetsize)r   r   compression_onlyr)   compressed_sizeuncompressed_sizes         r
   test_compression_sizer.      s    5  &+V<<			 3dVT/?@@@@'//$//VTt4444GOOD11 ?222223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3s   A=B**B.1B.r   r   c                    t          j                    5 }t          j        ||dk    rdnd|          5 } t	          | |          |j                   |j        j        rJ 	 d d d            n# 1 swxY w Y   t          j        	                    |          }d d d            n# 1 swxY w Y   t          j                    5 }t          j        |dd           5 } t	          | |          |j                   |j        j        rJ 	 d d d            n# 1 swxY w Y   t          j        	                    |          }||k    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr   r   wr"   )
r%   r&   icom
get_handler'   handleclosedr(   r)   r*   )r   r   r+   r)   handlesr,   r-   s          r
   test_compression_size_fhr6   1   s`    
		 0d_&%//FFS(
 
 
 	-  GC  000~,,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- '//$//0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
		 3d_T3D999 	-W GC  000~,,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- GOOD11 ?222223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3sj    B$-A."B$.A2	2B$5A2	6"B$$B(+B(E-DED	ED	*EEEz'write_method, write_kwargs, read_methodindexFr   c                 ,   t          j        g dg dgg d          }t          |         }t          j        d|z             5 } t          ||           |fi |  |||          }d d d            n# 1 swxY w Y   t          j        ||           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)   outputs           r
   ,test_dataframe_compression_defaults_to_inferrG   N   s     L,,,4oooNNNE)*:;I		1	2	2 Ad$|$$T::\:::T/?@@@A A A A A A A A A A A A A A A &%(((((s   %A44A8;A8z1write_method,write_kwargs,read_method,read_kwargsT)r7   headersqueezetypseriesc                    t          j        g dd          }t          |         }t          j        d|z             5 } t          ||           |fi | d|v r6|                                }|d=  ||fd|i|                    d          }	n ||fd|i|}	d d d            n# 1 swxY w Y   t          j        |	|d	           d S )
N)r   r:   
   r   r   r<   rI   r#   r   F)check_names)	r=   Seriesr?   r%   r&   r'   copyrI   assert_series_equal)
rA   rB   rC   read_kwargsr+   rD   rE   r)   kwargsrF   s
             r
   )test_series_compression_defaults_to_inferrU   b   sU    Innn3///E)*:;I		1	2	2 	Td$|$$T::\:::## %%''Fy! [NN3CNvNNVV FF ![SS3CS{SSF	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 65e<<<<<<s   AB&&B*-B*c                    t          j        dg dg dgz  g d          }t          j                    5 }t	          j        |d|           5 }t          j        t                    5  |                    |j	        |            d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   r   r   r   r   r0   r"   )
r=   r>   r%   r&   r1   r2   assert_produces_warningRuntimeWarningr   r3   )r+   dfr)   r5   s       r
   test_compression_warningrZ   }   s    
---/M/M/MNN
 
 
B 
		 Hd_T34DEEE 	H+N;; H H		'.6F	GGGH H H H H H H H H H H H H H H	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	HH H H H H H H H H H H H H H H H H HsY   B?B''BB'BB'BB'B?'B+	+B?.B+	/B??CCc           	      V   t          j                    }t          j                    5 }t          |d          5 }|                    |d|            |                    d           ddd           n# 1 swxY w Y   t          j        |t          j        |d|                      ddd           n# 1 swxY w Y   t          j
                    }|                    |d|            |                    d           t          j        |t          j        |d|                      dS )z?
    Binary file handles support compression.

    GH22555
    wb)r!   )r!   r#   r   N)	index_colr#   )r%   makeDataFramer&   openr   seekr@   r=   read_csvioBytesIO)r+   rY   r)   files       r
   test_compression_binaryre      s    
			B 
		 
d$T""" 	dIId3CIDDDIIaLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	DA;KLLL	
 	
 	
	
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 :<<DIId+;I<<<IIaLLL
BK7GHHH    s4   B4.A3'B43A7	7B4:A7	;-B44B8;B8c                     t          j                    } ddd}t          j                    5 }t          |          }|                     ||           t          j        d           |                                }|                     ||           ||                                k    sJ 	 ddd           dS # 1 swxY w 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"   r;   N)r%   r^   r&   r   r   timesleep
read_bytes)rY   compression_optionsr)   rF   s       r
   #test_gzip_reproducibility_file_namero      s    
			B%+a88 
		 +dDzz
		$$7	888
1""
		$$7	888*******+ + + + + + + + + + + + + + + + + +s   B B::B>B>c                  f   t          j                    } ddd}t          j                    }|                     ||d           |                                }t          j        d           t          j                    }|                     ||d           ||                                k    sJ dS )zL
    Gzip should create reproducible archives with mtime.

    GH 28103
    rg   rh   ri   r\   )r#   r!   r;   N)r%   r^   rb   rc   r   getvaluerk   rl   )rY   rn   bufferrF   s       r
   %test_gzip_reproducibility_file_objectrs      s     
			B%+a88 Z\\FIIf"5DIAAA__FJqMMMZ\\FIIf"5DIAAAV__&&&&&&&&r   c                      t          j        d          } t          j        t          j        d| gt          j                   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codes    r
   test_with_missing_lzmar      sC     ?	 D S^T48QQQQQQr   c                      t          j        d          } t          j        t          j        d| gt          j                   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')
        ru   rv   Nrx   r   s    r
   test_with_missing_lzma_runtimer      sC     ?	
 
D S^T48QQQQQQr   c                 ^   t          j                    5 } t          | |          |d           t          j                            |          } t          | |          |ddd           t          j                            |          }||k     sJ 	 d d d            d S # 1 swxY w Y   d S )Nrg   r"   rh   r   compresslevelr$   )r   r   r)   compressed_size_defaultcompressed_size_fasts        r
   test_gzip_compression_levelr      s     
		 >dVTv6666"$'//$"7"7VT&ST/U/UVVVV!wt44&)======> > > > > > > > > > > > > > > > > >s   B B""B&)B&c                     t          j                    5 } t          | |          |ddd           ddd           dS # 1 swxY w 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.
    bz2rh   r   r"   N)r%   r&   r'   )r   r   r)   s      r
   test_bzip_compression_levelr      s      
		 VdVT%RS/T/TUUUUV V V V V V V V V V V V V V V V V Vs   A  AAzsuffix,archive.zipz.tarc                 :   t          j        |           5 } ||d          5  	 d d d            n# 1 swxY w Y   t          j        t          d          5  t          j        |           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nfilenamer0   zZero files foundmatch)r%   r&   pytestraises
ValueErrorr=   ra   )suffixarchiver)   s      r
   test_empty_archive_zipr     s]    
&	)	)	) TWT3 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	]:-?@@@ 	 	K	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 sP   B1B5	B5	BA8,B8A<	<B?A<	 BBBc                     t          j        d          5 } t          j        | d          5 }|                    dd           |                    dd           d d d            n# 1 swxY w Y   t          j        t          d          5  t          j	        |            d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )	Nr   r   r0   a.csvzfoo,barb.csvz Multiple files found in ZIP filer   )
r%   r&   zipfileZipFilewritestrr   r   r   r=   ra   )r)   rd   s     r
   test_ambiguous_archive_zipr   #  s   	&	)	)	) T_T3'' 	.4MM'9---MM'9---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. ]:-OPPP 	 	K	 	 	 	 	 	 	 	 	 	 	 	 	 	 		                 sX   C-A%C%A)	)C,A)	-CB, C,B0	0C3B0	4CCCc                 Z   | dz  }t          |d          5 }|                    d           d d d            n# 1 swxY w Y   | dz  }t          |d          5 }|                    d           d d d            n# 1 swxY w Y   | dz  }t          j        |d          5 }|                    |d           |                    |d           d d d            n# 1 swxY w Y   t          j        t          d          5  t          j	        |           d d d            d S # 1 swxY w Y   d S )Nr   r0   zfoo,bar
r   zarchive.tarz#Multiple files found in TAR archiver   )
r_   writetarfileTarFileaddr   r   r   r=   ra   )tmp_pathcsvAPathacsvBPathbtarpathr   s          r
   test_ambiguous_archive_tarr   ,  s"   '!H	h		 	              '!H	h		 	               &G	#	&	& ##'"""'"""# # # # # # # # # # # # # # # 
z)N	O	O	O  
G                 sB   8<<A::A>A>-CCC>D  D$'D$c                     t          j        d          5 } t          j        ddggddg                              | dd	d
d           t          j        |           5 }t          j        |          5 }|	                                }t          |          dk    sJ |                    |d                                                                       d          }t                      rd}nd}||k    sJ 	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nz.foor   12foobarr   r   r   r    F)r#   r7   )fileobjrh   r   utf8zfoo,bar
1,2
zfoo,bar
1,2
)r%   r&   r=   r>   r   rg   r_   r   r   
getmemberslenextractfilereaddecoder   )rd   uncompressedr   memberscontentexpecteds         r
   !test_tar_gz_to_different_filenamer   =  s   	&	)	)	) +T
3ZLEN	
 	
 	
 &eV#D#DE&
R
R
RYt__ 	+666 
+'!,,..7||q((((!--gaj99>>@@GGOO&(( 03HH/H(*****
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	++ + + + + + + + + + + + + + + + + +s[   A	D6D5BD;DDDDDD6D"	"D6%D"	&D66D:=D:c                      t          j                    5 } t          j        | d          5  	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr0   )r   r!   )rb   rc   r1   _BytesTarFile)rr   s    r
   test_tar_no_error_on_closer   Q  s    	 S999 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 s.   A9A=	A =	AAA)3rg   rb   r(   pathlibr   r{   r}   r   ry   rk   r   r   pandas.compatr   pandasr=   pandas._testing_testingr%   pandas.io.commoncommonr1   extension_to_compressionitemsr?   markparametrizer>   rP   r.   r6   ra   	read_jsonread_picklerG   rU   rZ   re   ro   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   <module>r      s    				 				           



      - - - - - -                    !%!>!D!D!F!F   
 	1113Q3Q3QRR#OO	
 	
 	
 		#6666SAAA	 	 #E#E#EFF	3 	3 GF	 		3 	1113Q3Q3QRR#OO	
 	
 	
 		#6666SAAA	 	 Hi#8993 3 :9	 	3$ -	GU#R[1	B%	b".) 	) 	) 	) 7	Ud33R[9dBST	Buh&78	b"."- = = =&
H 
H 
H  4+ + +*' ' '&
R 
R 
RR R R$ 	1113Q3Q3QRR#OO	
 	
 	
 		#6666SAAA	 	 #E#E#EFF> > GF	 	> 	1113Q3Q3QRR#OO	
 	
 	
 		#6666SAAA	 	 #E#E#EFFV V GF	 	V 	!	!       "+ + +(    r   