
    d                     2   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m	Z	m
Z
mZmZmZmZ d dlmZ d dlmZ d dlmZ ej        d             Z ej        d          ej                            dg d	          d
                         ZdededefdZ ej        d          ej                            dddg          d                         Z  ej        d           ej        d          d                         Z! ej"        d          d             Z#dS )    )BytesION)	DataFrame
date_rangeread_csv
read_excel	read_jsonread_parquet)_compression_to_extension)_test_decoratorsc                     ddl }t                      d _         G fdd|j                  }|                    d|d           S )	z"Emulate GCS using a binary buffer.r   Nc                      dS )NT r       T/var/www/html/t/fyr/venv311/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)fsspecr   closeAbstractFileSystemregister_implementation)monkeypatchr(   r%   r   s      @r   r   r      s|     MMMJ#|J4 4 4 4 4 4 4F5 4 4 4 ""4):D"IIIr   gcsfs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          }np|dk    r9t          j        d           |                    |           t          |          }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.r/   T)indexrB   r   )parse_dates	index_colr2   zgs://test/test.xlsxr0   )convert_datesr1   pyarrowr3   tabulateN)r   npnanr   to_csvr   to_excelr   to_jsonr   pytestimportorskip
to_parquetr	   to_markdowntmassert_frame_equal)r   r.   df1r   df2s        r   test_to_read_gcsrV   .   s    q626]:\1555		
 	
 C &V%%D

4t
$$$t$1===	7		$TD6Q???	6		DTF333	9		I&&&t4  	:		J'''#s#####r   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   r[   infolistCRCtarfiler   
getmembersextractfileread)rW   rX   rY   expresres_infoexp_infotar_exptar_restar_res_infotar_exp_infoactual_fileexpected_files                r   assert_equal_zip_saferp   X   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encodingzutf-8cp1251c                    t          j                    }d|i}|dk    rd|d<   t                      }|                    |||d           d}|                    |||           |                                 }|                                }t          |||           t          |d	||
          }	t          j        ||	           t          |         }
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)
    methodgzipr5   mtimewb)rY   rq   modegs://test/test.csv)rY   rq   r   )rE   rY   rq   infer.N)	rR   makeDataFramer   rK   getvaluerp   r   rS   r
   )r   compression_onlyrq   dfrY   bufferpath_gcsrg   rX   read_dffile_exts              r   $test_to_csv_compression_encoding_gcsr   w   s}    
			B -.K6!! GYYFIIf+tILLL $HIIhK(ICCC




C  H#x)9:::A+;h  G "g&&& ))9:H#KHHIIhK(ICCC




C  H#x)9:::x1'HUUUG"g&&&&&r   fastparquetc           	          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.r   )r*   r5   r6   r7   r8   r9   r:   r;   r<   r>   c                       e Zd Zd fd	ZdS )7test_to_parquet_gcs_new_file.<locals>.MockGCSFileSystemrc                 v    d|vrt           t          t          j                            d          |          S )Nwztest.parquet)FileNotFoundErrorr   osr   join)r   r   rx   r   tmpdirs       r   r   z<test_to_parquet_gcs_new_file.<locals>.MockGCSFileSystem.open   s2    $''V^<<dCCCr   N)r   )r!   r"   r#   r   )r   s   r   r%   r      s;        	D 	D 	D 	D 	D 	D 	D 	Dr   r%   zgcsfs.GCSFileSystemry   Tr   N)rC   enginerY   )r(   r*   r   rI   rJ   r   setattrrP   )r,   r   r*   rT   r%   s    `   r   test_to_parquet_gcs_new_filer      s     *)))))
q626]:\1555		
 	
 CD D D D D D D. D D D -/@AAANNDD      r   c                      t          j        t                    5  t          d           d d d            d S # 1 swxY w Y   d S )Nry   )rR   external_error_raisedImportErrorr   r   r   r   test_gcs_not_present_exceptionr      s    		!+	.	. ' '%&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 's   7;;)$ior   r   rb   r^   numpyrI   rN   pandasr   r   r   r   r   r	   pandas._testing_testingrR    pandas.tests.io.test_compressionr
   pandas.utilr   tdfixturer   
skip_if_nomarkparametrizerV   bytesrA   rp   r   r   skip_if_installedr   r   r   r   <module>r      s          				                             F F F F F F . . . . . .   . w#R#R#RSS%$ %$ TS %$P"% "5 "s " " " "> wgx%899'' '' :9 ''T }w   2 g' ' ' ' 'r   