1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
U
­ý°dˆã    @sddlmZddlZddlZddlZddlZddlZddlm    Z    m
Z
m Z m Z m Z mZddlmZddlmZddlmZejdd„ƒZe d¡ej d    d
d d d dg¡dd„ƒƒZeeedœdd„Ze d¡ej dddg¡dd„ƒƒZ e d¡e d¡dd„ƒƒZ!e "d¡dd„ƒZ#dS)é)ÚBytesION)Ú    DataFrameÚ
date_rangeÚread_csvÚ
read_excelÚ    read_jsonÚ read_parquet)Ú_compression_to_extension)Ú_test_decoratorscsBddl}tƒ‰dd„ˆ_G‡fdd„d|jƒ}|jd|dd    ˆS)
z"Emulate GCS using a binary buffer.rNcSsdS)NT©r r r úOd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/io/test_gcs.pyÚ<lambda>ózgcs_buffer.<locals>.<lambda>cs$eZdZe‡fdd„ƒZdd„ZdS)z%gcs_buffer.<locals>.MockGCSFileSystemcsˆ d¡ˆS)Nr)Úseek)ÚargsÚkwargs©Ú
gcs_bufferr r Úopens
z*gcs_buffer.<locals>.MockGCSFileSystem.openc[s |ddœgS)NÚfile)ÚnameÚtyper )ÚselfÚpathrr r r Úls$sz(gcs_buffer.<locals>.MockGCSFileSystem.lsN)Ú__name__Ú
__module__Ú __qualname__Ú staticmethodrrr rr r ÚMockGCSFileSystemsrZgsT)Úclobber)ÚfsspecrÚcloseÚAbstractFileSystemZregister_implementation)Ú monkeypatchr!rr rr rs 
 rZgcsfsÚformatÚcsvÚjsonÚparquetÚexcelÚmarkdowncCsútddgdtjgddgtdddd    œƒ}d
|›}|d krZ|j|d d t|dgdd}n|dkr‚d}| |¡t|dgdd}nh|dkr¤| |¡t    |dgd}nF|dkrÊt
  d¡|  |¡t |ƒ}n |dkrêt
  d¡| |¡|}t ||¡dS)zE
    Test that many to/read functions support GCS.
 
    GH 33987
    ééç@ÚtÚsú
2018-06-18é©Zperiods©ÚintÚfloatÚstrÚdtzgs://test/test.r&T)Úindexr7r)Z parse_datesÚ    index_colr)zgs://test/test.xlsxr')Z convert_datesr(Zpyarrowr*ÚtabulateN)rÚnpÚnanrÚto_csvrZto_excelrÚto_jsonrÚpytestZ importorskipÚ
to_parquetrZ to_markdownÚtmÚassert_frame_equal)rr%Údf1rZdf2r r r Útest_to_read_gcs.s6    
üÿ    
 
 
 
 
 
 
 
rD)ÚresultÚexpectedÚ compressionc
Cs(|dkrjt t|ƒ¡L}t t|ƒ¡2}t| ¡| ¡ƒD]\}}|j|jks:t‚q:W5QRXW5QRXnº|dkrtjt|ƒdŠ}tjt|ƒdn}t|     ¡|     ¡ƒD]T\}    }
| 
|    ¡} | 
|
¡} | dk| dkksÚt‚| dk    rª| dk    rª|   ¡|   ¡ksªt‚qªW5QRXW5QRXn||ks$t‚dS)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
    ÚzipÚtar)ÚfileobjN) ÚzipfileÚZipFilerrHÚinfolistÚCRCÚAssertionErrorÚtarfilerÚ
getmembersÚ extractfileÚread) rErFrGÚexpÚresZres_infoZexp_infoZtar_expZtar_resZ tar_res_infoZ tar_exp_infoZ actual_fileZ expected_filer r r Úassert_equal_zip_safeXs,ÿ(
ÿÿ 
 
,rVÚencodingzutf-8Úcp1251c Csît ¡}d|i}|dkr d|d<tƒ}|j|||ddd}|j|||d| ¡}| ¡}t|||ƒt|d    ||d
}    t ||    ¡t|}
d |d<|d |
›7}|j|||d| ¡}| ¡}t|||ƒt|d    d |d
}    t ||    ¡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Úgzipr+ÚmtimeÚwb)rGrWÚmodeúgs://test/test.csv)rGrWr)r9rGrWZinferÚ.N)    rAZ makeDataFramerr=ÚgetvaluerVrrBr    ) rZcompression_onlyrWZdfrGÚbufferZpath_gcsrUrFZread_dfZfile_extr r r Ú$test_to_csv_compression_encoding_gcsws6     ÿ  rbÚ fastparquetcsjddlm}tddgdtjgddgtdd    d
d œƒ}G‡fd d „d |ƒ}| d|¡|jddddddS)zCRegression test for writing to a not-yet-existent GCS Parquet file.r)r#r+r,r-r.r/r0r1r2r3cseZdZd‡fdd„    ZdS)z7test_to_parquet_gcs_new_file.<locals>.MockGCSFileSystemÚrcs d|kr t‚ttj ˆd¡|ƒS)NÚwz test.parquet)ÚFileNotFoundErrorrÚosrÚjoin)rrr]r©Útmpdirr r r³sz<test_to_parquet_gcs_new_file.<locals>.MockGCSFileSystem.openN)rd)rrrrr rir r r²srzgcsfs.GCSFileSystemr^TrcN)r8ZenginerG)r!r#rr;r<rÚsetattrr@)r$rjr#rCrr rir Útest_to_parquet_gcs_new_file£s  
üÿ     ÿrlc    Cs"t t¡tdƒW5QRXdS)Nr^)rAZexternal_error_raisedÚ ImportErrorrr r r r Útest_gcs_not_present_exception¾s rn)$ÚiorrgrPrKÚnumpyr;r?ZpandasrrrrrrZpandas._testingZ_testingrAZ pandas.tests.io.test_compressionr    Z pandas.utilr
ÚtdZfixturerZ
skip_if_noÚmarkZ parametrizerDÚbytesr6rVrbrlZskip_if_installedrnr r r r Ú<module>s.     
 ( *