
    o[we#.              	       N   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 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$ej        j%        d"             Z&ej        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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, Z/d- Z0d. Z1dS )/    N)Path)is_platform_windows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         @lib/python3.11/site-packages/pandas/tests/io/test_compression.py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_fhr/   -   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          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	DataFramer   r   r   assert_frame_equal)	write_methodwrite_kwargsread_methodr#   compression_to_extensioninput	extensionr!   outputs	            r&   ,test_dataframe_compression_defaults_to_inferr@   J   s     L,,,4oooNNNE()9:I		1	2	2 Ad$|$$T::\:::T/?@@@A A A A A A A A A A A A A A A &%(((((s   %A//A36A3z1write_method,write_kwargs,read_method,read_kwargsT)r0   headersqueezetypseriesc                    t          j        g dd          }||         }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   r3   
   r
   r   r5   rB   r   r   F)check_names)r6   Seriesr   r   r   copyrB   assert_series_equal)r9   r:   r;   read_kwargsr#   r<   r=   r>   r!   kwargsr?   s              r&   )test_series_compression_defaults_to_inferrN   ^   sU   " Innn3///E()9: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   r)   r   )
r6   r7   r   r   r*   r+   assert_produces_warningRuntimeWarningr   r,   )r#   dfr!   r.   s       r&   test_compression_warningrS   ~   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   seekr8   r6   read_csvioBytesIO)r#   rR   r!   files       r&   test_compression_binaryr^      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   皙?N)r   rW   r   r   r   timesleep
read_bytes)rR   compression_optionsr!   r?   s       r&   #test_gzip_reproducibility_file_nameri      s    
			B%+a88 
		 +dDzz
		$$7	888
3""
		$$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
    r`   ra   rb   rU   )r   r   rd   N)r   rW   r[   r\   r   getvaluere   rf   )rR   rh   bufferr?   s       r&   %test_gzip_reproducibility_file_objectrm      s     
			B%+a88 Z\\FIIf"5DIAAA__FJsOOOZ\\FIIf"5DIAAAV__&&&&&&&&    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Qrn   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')
        rp   rq   Nrs   r{   s    r&   test_with_missing_lzma_runtimer      sC    
 ?	
 
D S^T48QQQQQQrn   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 )Nr`   r   ra   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           t          j                            |          } t          | |          |ddd           t          j                            |          }||k     sJ |dk    rt          j        |d           d d d            d S # 1 swxY w Y   d S )Nxzr   ra   )r   presetr   )r   r   r   r    r!   r"   r6   rZ   r   s        r&   test_xz_compression_level_readr     s    
		 0dVTt4444"$'//$"7"7VT$!/L/LMMMM!wt44&)=====XK$////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0s   BB==CC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.
    bz2ra   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filenamer)   zZero files foundmatch)r   r   pytestraises
ValueErrorr6   rZ   )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   r)   a.csvzfoo,barb.csvz Multiple files found in ZIP filer   )
r   r   zipfileZipFilewritestrr   r   r   r6   rZ   )r!   r]   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                 b   | dz  }t          |dd          5 }|                    d           d d d            n# 1 swxY w Y   | dz  }t          |d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   r)   zutf-8)encodingzfoo,bar
r   zarchive.tarz#Multiple files found in TAR archiver   )
rX   writetarfileTarFileaddr   r   r   r6   rZ   )tmp_pathcsvAPathacsvBPathbtarpathr   s          r&   test_ambiguous_archive_tarr   E  s,   '!H	hg	.	.	. !	              '!H	hg	.	.	. !	               &G	#	&	& ##'"""'"""# # # # # # # # # # # # # # # 
z)N	O	O	O  
G                 sC   :>>A>>BB#-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   r0   )fileobjra   r   utf8zfoo,bar
1,2
zfoo,bar
1,2
)r   r   r6   r7   r   r`   rX   r   r   
getmemberslenextractfilereaddecoder   )r]   uncompressedr   memberscontentexpecteds         r&   !test_tar_gz_to_different_filenamer   V  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 )Nr)   )r   r   )r[   r\   r*   _BytesTarFile)rl   s    r&   test_tar_no_error_on_closer   j  s    	 S999 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 s.   A9A=	A =	AAA)2r`   r[   r    pathlibr   rv   rx   r   rt   re   r   r   pandas.compatr   pandasr6   pandas._testing_testingr   pandas.io.commoncommonr*   markparametrizer7   rI   r'   r/   rZ   	read_jsonread_pickler@   rN   rS   r^   ri   rm   
single_cpur}   r   r   r   r   r   r   r   r   r   r   r    rn   r&   <module>r      sJ    				 				           



      - - - - - -                    	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"."- = = =0
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0 0 GF	 	0 	1113Q3Q3QRR#OO	
 	
 	
 		#6666SAAA	 	 #E#E#EFFV V GF	 	V 	!	!       "+ + +(    rn   