
    Eg                        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	m
Z
mZmZmZmZmZmZ d dlmZ d dlmZ ej                            d          Zej        d             Zej        j        ej                            dg d          d	                         Zd
edede fdZ!ej                            dddg          d             Z"d Z# ej$        d          d             Z%dS )    )BytesION)	DataFrameIndex
date_rangeread_csv
read_excel	read_jsonread_parquet)_test_decoratorsz=ignore:Passing a BlockManager to DataFrame:DeprecationWarningc                      t          j        d           t          j        d          } t                      d _         G fdd| j                  }|                     d|d           S )	z"Emulate GCS using a binary buffer.gcsfsfsspecc                      dS )NT r       M/var/www/sysmax/venv/lib/python3.11/site-packages/pandas/tests/io/test_gcs.py<lambda>zgcs_buffer.<locals>.<lambda>"   s    t r   c                   0    e Zd Ze fd            Zd ZdS )%gcs_buffer.<locals>.MockGCSFileSystemc                  2                         d           S )Nr   )seek)argskwargs
gcs_buffers     r   openz*gcs_buffer.<locals>.MockGCSFileSystem.open%   s    OOAr   c                     |ddgS )Nfile)nametyper   )selfpathr   s      r   lsz(gcs_buffer.<locals>.MockGCSFileSystem.ls*   s    !62233r   N)__name__
__module____qualname__staticmethodr   r"   )r   s   r   MockGCSFileSystemr   $   sG        		 	 	 	 
		4 	4 	4 	4 	4r   r'   gsT)clobber)pytestimportorskipr   closeAbstractFileSystemregister_implementation)r   r'   r   s     @r   r   r      s         **FJ#|J4 4 4 4 4 4 4F5 4 4 4 ""4):D"IIIr   format)csvjsonparquetexcelmarkdownc           	        
 t          ddgdt          j        gddgt          dd          d	          }d
| }|dk    r,|                    |d           t          |dgd          }n]|dk    r,d}|                    |           t          |dgd          }n+|dk    r(|                    |           t          |dg          }n|dk    rt          j        d           t          j        d          
 G 
fdd
j                  }|                                5 }|                    
d|           |                    |           t!          |          }ddd           n# 1 swxY w Y   |                                }	|	j        dk    sJ n1|dk    r+t          j        d           |                    |           |}t)          j        ||           dS )zE
    Test that many to/read functions support GCS.

    GH 33987
                 @ts
2018-06-18   periodsintfloatstrdtzgs://test/test.r0   T)indexrC   r   )parse_dates	index_colr3   zgs://test/test.xlsxr1   )convert_datesr2   pyarrowz
pyarrow.fsc                   *    e Zd Ze fd            ZdS )(test_to_read_gcs.<locals>.MockFileSystemc                     t          d           t          j        |                     dd                                                                                    }                    |          S )NzUsing pyarrow filesystemzgs:// )printpathlibPathreplaceabsoluteas_uriLocalFileSystem)r!   to_localpa_fss     r   from_uriz1test_to_read_gcs.<locals>.MockFileSystem.from_uriX   s[    0111"<Wb(A(ABBKKMMTTVV,,X666r   N)r#   r$   r%   r&   rV   )rU   s   r   MockFileSystemrJ   W   s8        7 7 7 7 \7 7 7r   rW   
FileSystemNz2Using pyarrow filesystem
Using pyarrow filesystem
r4   tabulate)r   npnanr   to_csvr   to_excelr   to_jsonr	   r*   r+   rX   contextsetattr
to_parquetr
   
readouterroutto_markdowntmassert_frame_equal)r   r/   monkeypatchcapsysdf1r!   df2rW   mcapturedrU   s             @r   test_to_read_gcsrm   5   sl    q626]:\1555		
 	
 C &V%%D

4t
$$$t$1===	7		$TD6Q???	6		DTF333	9		I&&&#L11	7 	7 	7 	7 	7 	7 	7U- 	7 	7 	7   "" 	%aIIe\>:::NN4   t$$C	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% $$&&|UUUUUU	:		J'''#s#####s   #<E++E/2E/resultexpectedcompressionc                    |dk    rt          j        t          |                     5 }t          j        t          |                    5 }t          |                                |                                          D ]\  }}|j        |j        k    s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 |dk    rt          j        t          |                     5 }t          j        t          |                    5 }t          |                                |                                          D ]k\  }	}
|	                    |	          }|	                    |
          }|du |du k    sJ |.|,|
                                |
                                k    sJ l	 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 | |k    sJ dS )a  
    For zip compression, only compare the CRC-32 checksum of the file contents
    to avoid checking the time-dependent last-modified timestamp which
    in some CI builds is off-by-one

    See https://en.wikipedia.org/wiki/ZIP_(file_format)#File_headers
    zipNtar)fileobj)zipfileZipFiler   rr   infolistCRCtarfiler   
getmembersextractfileread)rn   ro   rp   expresres_infoexp_infotar_exptar_restar_res_infotar_exp_infoactual_fileexpected_files                r   assert_equal_zip_safer   l   s5    e_WV__-- 	4goH7
 7
 	4&)#,,..#,,..&I&I 4 4"(|x|333334	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4
 
		\'&//222 
	Fgw|H%%@
 @
 @
 
	F.1""$$g&8&8&:&:/ / F F*l &11,?? ' 3 3L A A#t+$1FGGGG*}/H&++--1C1C1E1EEEEEF
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F 
	F !!!!!!sm   "B<
AB$B<$B(	(B<+B(	,B<<C C 2#GB!G7GG	G
G	GG"Gencodingutf-8cp1251c           
         t          dt          j        d                              d          z  t	          t          d          t                    t	          d t          d          D             t                              }d	|i}|d
k    rd|d<   t                      }|	                    |||d           d}|	                    |||           | 
                                }|
                                }	t          ||	|           t          |d||          }
t          j        ||
           ||         }d|d	<   |d| z  }|	                    |||           | 
                                }|
                                }	t          ||	|           t          |dd|          }
t          j        ||
           dS )z
    Compression and encoding should with GCS.

    GH 35677 (to_csv, compression), GH 26124 (to_csv, encoding), and
    GH 32392 (read_csv, encoding)
    g?x   )      ABCD)dtypec                     g | ]}d | S )zi-r   ).0is     r   
<listcomp>z8test_to_csv_compression_encoding_gcs.<locals>.<listcomp>   s    111!X!XX111r   r   )columnsrD   methodgzipr6   mtimewb)rp   r   modegs://test/test.csv)rp   r   r   )rF   rp   r   infer.N)r   rZ   arangereshaper   listobjectranger   r\   getvaluer   r   re   rf   )r   compression_onlyr   compression_to_extensiondfrp   bufferpath_gcsr~   ro   read_dffile_exts               r   $test_to_csv_compression_encoding_gcsr      s    
binn$$W---d6ll&11111uRyy111@@@
 
 
B -.K6!! GYYFIIf+tILLL $HIIhK(ICCC




C  H#x)9:::A+;h  G "g&&& ((89H#KHHIIhK(ICCC




C  H#x)9:::x1'HUUUG"g&&&&&r   c           	      H   t          j        d           t          j        d           ddlm} t	          ddgdt
          j        gdd	gt          d
d          d          } G fdd|          }|                     d|           |	                    dddd           dS )zCRegression test for writing to a not-yet-existent GCS Parquet file.fastparquetr   r   )r-   r6   r7   r8   r9   r:   r;   r<   r=   r?   c                       e Zd Zd fd	ZdS )7test_to_parquet_gcs_new_file.<locals>.MockGCSFileSystemrc                 z    d|vrt           t          t          j                            d          |d          S )Nwztest.parquetr   )r   )FileNotFoundErrorr   osr!   join)r    r!   r   r   tmpdirs       r   r   z<test_to_parquet_gcs_new_file.<locals>.MockGCSFileSystem.open   s7    $''V^<<dWUUUUr   N)r   )r#   r$   r%   r   )r   s   r   r'   r      s;        	V 	V 	V 	V 	V 	V 	V 	Vr   r'   zgcsfs.GCSFileSystemr   TN)rD   enginerp   )
r*   r+   r   r-   r   rZ   r[   r   r`   ra   )rg   r   r-   ri   r'   s    `   r   test_to_parquet_gcs_new_filer      s    
&&&
   ))))))
q626]:\1555		
 	
 CV V V V V V V. V V V -/@AAANNDD      r   r   c                      t          j        t                    5  t          d           d d d            d S # 1 swxY w Y   d S )Nr   )re   external_error_raisedImportErrorr   r   r   r   test_gcs_not_present_exceptionr      s    		!+	.	. ' '%&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 's   7;;)&ior   r   rN   ry   ru   numpyrZ   r*   pandasr   r   r   r   r   r	   r
   pandas._testing_testingre   pandas.utilr   tdmarkfilterwarnings
pytestmarkfixturer   
single_cpuparametrizerm   bytesrB   r   r   r   skip_if_installedr   r   r   r   <module>r      s         				                                . . . . . .[''C 

   2 #R#R#RSS2$ 2$ TS 2$j"% "5 "s " " " "> gx%899-' -' :9-'`  8 g' ' ' ' 'r   