zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
U
­ý°dZã @s dZddlZddlZddlmZddlmZmZmZddl    Z    ddl
Z
ddl m Z ddl Z ddlZddlZddlmZddlmmZddlZddlmZddlmmZGdd„dƒZeee gZ zdd    l!m"Z#e  $e#¡Wne%k
ròYnXe
j& 'e
j& (e)¡¡Z*Gd
d „d ƒZ+ej,d d „ƒZ-Gdd„dƒZ.dd„Z/ej0 1dddg¡ej0 1dddg¡dd„ƒƒZ2dd„Z3ej0 1deddfeddfg¡d d!„ƒZ4ej0 1d"dd#d$g¡ej0 1dddg¡d%d&„ƒƒZ5d'd(„Z6d)d*„Z7d+d,„Z8d-d.„Z9ej0 1d/ej:ej;ej<ej=ej>ej?ej@ejAejBg    ¡d0d1„ƒZCdS)2z0
Tests for the pandas.io.common functionalities
éN)Úpartial)ÚBytesIOÚStringIOÚUnsupportedOperation)ÚPath)Úis_platform_windowsc@s&eZdZdZddœdd„Zdd„ZdS)Ú CustomFSPathz%For testing fspath on unknown objectsN)ÚreturncCs
||_dS©N©Úpath)Úselfr ©rúRd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/io/test_common.pyÚ__init__ szCustomFSPath.__init__cCs|jSr
r ©r rrrÚ
__fspath__#szCustomFSPath.__fspath__)Ú__name__Ú
__module__Ú __qualname__Ú__doc__rrrrrrrsr)Úlocalc@s"eZdZdZdd„Zdd„Zdd„Ze d¡d    d
„ƒZ    d d „Z
d d„Z e j  de¡dd„ƒZe j  deeeg¡dd„ƒZdd„Zdd„Ze d¡dd„ƒZdd„Ze j  dejdedfejded fejd!ed"fejded#fej d$ed%fej!ded&fej"ded'fej#ded(fej$ded)fg    ¡d*d+„ƒZ%e j  d,ej&j'dedfej&j(ded-fej&j)d!ed"fej&j*ded#fej&j+ded.fej&j,ded&fej&j-ded(fej&j.ded)fg¡d/d0„ƒZ/e j  dejdedfej0dedfejded fejd!ed"fejded#fej d$ed%fej!ded&fej"ded'fej#ded(fej$ded)fg
¡d1d2„ƒZ1e j  d3ejdd4fej0dd4fejdd5fejd!d6fejdd7fej d$d8fej!dd9fej"dd:fej#dd;fej$dd<fg
¡d=d>„ƒZ2e j  d?d@idfdAdBdCidCfdDidfdEidfdFidfdGidfdHidfdIdJe 3dK¡idfg¡dLdM„ƒZ4dNdO„Z5dPS)QÚTestCommonIOCapabilitiesziindex,A,B,C,D
foo,2,3,4,5
bar,7,8,9,10
baz,12,13,14,15
qux,12,13,14,15
foo2,12,13,14,15
bar2,12,13,14,15
cCsBd}t |¡}||kst‚tj |¡s*t‚tj |¡|ks>t‚dS)Nz
~/sometest)ÚicomÚ _expand_userÚAssertionErrorÚosr ÚisabsÚ
expanduser©r ÚfilenameZ expanded_namerrrÚtest_expand_user?s
 
 z)TestCommonIOCapabilities.test_expand_usercCs2d}t |¡}||kst‚tj |¡|ks.t‚dS)Nz/somefolder/sometest)rrrrr rrrrrÚtest_expand_user_normal_pathGs
 z5TestCommonIOCapabilities.test_expand_user_normal_pathcCsBt tdƒ¡}|dkst‚t tdƒ¡}|tj dd¡ks>t‚dS)NÚ.zfoo//barÚfooÚbar)rÚstringify_pathrrrr Újoin)r Úrel_pathZredundant_pathrrrÚtest_stringify_path_pathlibNs z4TestCommonIOCapabilities.test_stringify_path_pathlibzpy.pathcCs8tj dd¡}tj |¡}t|ƒ}t |¡|ks4t‚dS)Nr$r%)rr r'ÚabspathÚ    LocalPathrr&r)r r Úabs_pathZlpathrrrÚtest_stringify_path_localpathTs z6TestCommonIOCapabilities.test_stringify_path_localpathcCs"tdƒ}t |¡}|dkst‚dS)Nú foo/bar.csv)rrr&r)r ÚpÚresultrrrÚtest_stringify_path_fspath[s
z3TestCommonIOCapabilities.test_stringify_path_fspathc
CsTt d¡}t ¡8}|jd|›dd}|t |¡ks<t‚W5QRXW5QRXdS)NÚfsspeczfile://Úwb©Úmode)ÚpytestÚ importorskipÚtmÚ ensure_cleanÚopenrr&r)r r2r Z
fsspec_objrrrÚ!test_stringify_file_and_path_like`s
 
z:TestCommonIOCapabilities.test_stringify_file_and_path_likeÚ    path_typecCs2|\}}|d|ƒ}tj|dd}||ks.t‚dS)Nr.Zinfer)Ú compression)rZinfer_compressionr)r Zcompression_formatr<Ú    extensionÚexpectedr r=rrrÚ test_infer_compression_from_pathgs z9TestCommonIOCapabilities.test_infer_compression_from_pathc
Csztjt ¡d`}|dt|ƒjdƒ}t |d¡2}t|jjƒ ¡sJt    ‚t
j   |¡|jjksbt    ‚W5QRXW5QRXdS)N)Údirz~/z    /sometestÚw) ÚtempfileÚTemporaryDirectoryrÚhomeÚnamerÚ
get_handleÚhandleÚ is_absoluterrr r)r r<Útmpr ÚhandlesrrrÚtest_get_handle_with_pathns
z2TestCommonIOCapabilities.test_get_handle_with_pathc
CsPtƒ6}t |d¡}|j|ks$t‚W5QRX|jr8t‚W5QRX|jsLt‚dS)NÚr)rrrGrHrÚclosed)r Z input_bufferrKrrrÚtest_get_handle_with_bufferws
z4TestCommonIOCapabilities.test_get_handle_with_bufferc    Cs”d}tjt|ƒdddr}d}d}|j |¡}t|ƒ|ks>t‚t|ƒ|krjt|j ¡ƒdks`t‚||7}qt||7}q"|| d¡ks†t‚W5QRXdS)    Nõ&a,b,c
1,2,3
©,®,®
Look,a snake,🐍ÚrbF©Úis_textóérúutf-8)rrGrrHÚreadÚlenrÚencode)r ÚdatarKr0Ú    chunksizeÚchunkrrrÚ)test_bytesiowrapper_returns_correct_bytess  
zBTestCommonIOCapabilities.test_bytesiowrapper_returns_correct_bytesÚpyarrowc    Cs‚ddlm}d}t dddgddd    gd
dd gd œ¡}t|ƒ}tj|d dd,}| |j¡     ¡}t
  ||¡|j rtt ‚W5QRXdS)Nr)ÚcsvrPÚ1õ©ZLookÚ2õ®za snakeÚ3u🐍©ÚaÚbÚcrQFrR)r^r_ÚpdÚ    DataFramerrrGÚread_csvrHZ    to_pandasr8Úassert_frame_equalrNr)r r_rZr?ÚsrKÚdfrrrÚtest_get_handle_pyarrow_compat–s ÿ z7TestCommonIOCapabilities.test_get_handle_pyarrow_compatc    Cs¦tjt|jƒdd}tj|dd}W5QRXt t|jƒ¡}t ||¡tjt|jƒdd>}t|ƒ}t ||jdg¡t t |¡|jdd…¡W5QRXdS)Né)r[T)Z ignore_indexr)    rirkrÚdata1Úconcatr8rlÚnextZiloc)r Úreaderr0r?ÚitÚfirstrrrÚ test_iterator¨s z&TestCommonIOCapabilities.test_iteratorz#reader, module, error_class, fn_extrr_ÚtxtZxlrdZxlsxÚfeatherÚtablesÚh5ZdtaZsas7bdatÚjsonÚpicklecCsÊt |¡tj tdd|¡}d|›d}d|›d}d}d}    d    |›d
|›d}
d |›d} d |›d} d |›} tj|d|›d|›d|›d|    ›d|
›d| ›d| ›d| ›dd||ƒW5QRXdS)NrZúdoes_not_exist.úFile (b')?.+does_not_exist\.ú'? does not existú:\[Errno 2\] No such file or directory: '.+does_not_exist\.ú'zExpected object or valueú7path_or_buf needs to be a string file path or file-likeú#\[Errno 2\] File .+does_not_exist\.ú$ does not exist: '.+does_not_exist\.õ<\[Errno 2\] æ²¡æœ‰é‚£ä¸ªæ–‡ä»¶æˆ–目录: '.+does_not_exist\.ú?\[Errno 2\] File o directory non esistente: '.+does_not_exist\.ú+Failed to open local file.+does_not_exist\.ú(ú|ú)©Úmatch)r6r7rr r'ÚHEREÚraises)r rtÚmoduleÚ error_classÚfn_extr Úmsg1Úmsg2Úmsg3Úmsg4Úmsg5Úmsg6Úmsg7Úmsg8rrrÚtest_read_non_existent´s"
  ÿ 
ÿ
4þz/TestCommonIOCapabilities.test_read_non_existentz#method, module, error_class, fn_extÚhtmlZparquetc    Cslt |¡t dddgdddgdddgdœ¡}tj tddd    |¡}tj|d
d |||ƒW5QRXdS) NrpééérUrerZZmissing_folderr~z@Cannot save file into a non-existent directory: .*missing_folderrŒ)    r6r7rirjrr r'rŽr)r Úmethodrr‘r’Z dummy_framer rrrÚ#test_write_missing_parent_directoryÚs
$þz<TestCommonIOCapabilities.test_write_missing_parent_directorycCsÚt |¡tj dd|¡}| tddd„¡d|›d}d|›d    }d
}    d }
d |›d |›d    } d|›d    } d|›d    } d|›}tj|d|›d|›d|    ›d|
›d| ›d| ›d| ›d|›dd||ƒW5QRXdS)Nú~r~rcSstj d|¡S)Nr$)rr r')ÚxrrrÚ<lambda>
rTzJTestCommonIOCapabilities.test_read_expands_user_home_dir.<locals>.<lambda>rr€rr‚z0Unexpected character found when decoding 'false'rƒr„r…r†r‡rˆr‰rŠr‹rŒ)r6r7rr r'Úsetattrrr)r rtrr‘r’Z monkeypatchr r“r”r•r–r—r˜r™ršrrrÚtest_read_expands_user_home_dirõs$
  ÿ 
ÿ
4þz8TestCommonIOCapabilities.test_read_expands_user_home_dirzreader, module, path)ÚiorZr_ziris.csv)r§rZZ fixed_widthzfixed_width_format.txt)r§rZÚexcelz
test1.xlsx)r§rZryzfeather-0_3_1.feather)r§rZZ
legacy_hdfzdatetimetz_object.h5)r§rZZstatazstata10_115.dta)r§ZsasrZztest1.sas7bdat)r§r|rZztsframe_v012.json)r§rZr}zcategorical.0.25.0.picklecCsRt |¡||Ž}t|ƒ}||ƒ}||ƒ}| d¡rBt ||¡n t ||¡dS)Nz.pickle)r6r7rÚendswithr8Zassert_categorical_equalrl)r rtrr ÚdatapathÚmypathr0r?rrrÚtest_read_fspath_all s 
 
z-TestCommonIOCapabilities.test_read_fspath_allz"writer_name, writer_kwargs, moduleÚto_csvÚto_excelÚengineZopenpyxlÚ
to_featherÚto_htmlÚto_jsonÚto_latexÚ    to_pickleÚto_stataZ
time_stampz2019-01-01 00:00c Cs
|dkrt d¡t d¡}t d¡}t dddgi¡}|Ä}|´}t |¡t|ƒ}    t||ƒ}
|
|f|Ž|
|    f|Žt|dƒj} t|dƒT} |d    krÂtj    | f|Ž} tj    | f|Ž}t 
| |¡n|   ¡} |   ¡}| |ksÞt ‚W5QRXW5QRXW5QRXW5QRXdS)
N)r³Zjinja2ÚstringÚfspathÚArprrQr®) r6r7r8r9rirjrÚgetattrr:Ú
read_excelrlrWr)r Z writer_nameZ writer_kwargsrÚp1Úp2rnr¶r·r«ÚwriterZf_strZf_pathr0r?rrrÚtest_write_fspath_allMs&
 
 
 
 
  z.TestCommonIOCapabilities.test_write_fspath_allc    
Cs t d¡t dddgi¡}t d¡}t d¡}|V}|F}t|ƒ}|j|dd|j|ddtj|dd}tj|dd}W5QRXW5QRXt     ||¡dS)    Nrzr¸rprr¶r·r%)Úkey)
r6r7rirjr8r9rZto_hdfÚread_hdfrl)    r rnr»r¼r¶r·r«r0r?rrrÚtest_write_fspath_hdf5ts
 
 
 "z/TestCommonIOCapabilities.test_write_fspath_hdf5N)6rrrrqr!r"r)ÚtdZ
skip_if_nor-r1r;r6ÚmarkÚ parametrizeÚ
path_typesr@ÚstrrrrLrOr]rorwrirkÚFileNotFoundErrorÚread_fwfrºÚ read_featherÚOSErrorrÀÚ
read_stataÚread_sasÚ    read_jsonÚ read_pickler›rjr­r±r®r°Z
to_parquetrµr²r´r¡Z
read_tabler¦r¬Ú to_datetimer¾rÁrrrrr5sÈ    
 
 
 
          ÷þ
øþ
          öþ
 
 
ý
ýý
 
 
ýêþ
 øþ
rcCs|ddddƒS)Nr§rZr_z test_mmap.csvr)rªrrrÚ    mmap_file‰srÐc@sXeZdZdd„Zdd„Zdd„Zdd„Zej     d    d
d g¡ej     d d dg¡dd„ƒƒZ
dS)ÚTestMMapWrapperc    Cs”tdƒ}dd„|_tƒr"d}t}n
d}tj}tj||dt     |d¡W5QRXt
|ƒ}W5QRXd}tjt |dt     |d¡W5QRXdS)    NzI am not a filecSsdS)Néÿÿÿÿrrrrrr¤‘rTz;TestMMapWrapper.test_constructor_bad_file.<locals>.<lambda>zThe parameter is incorrectz
[Errno 22]rŒTzI/O operation on closed file) rÚfilenorrÊÚmmapÚerrorr6rrZ_maybe_memory_mapr:Ú
ValueError)r rÐZnon_fileÚmsgÚerrÚtargetrrrÚtest_constructor_bad_files
 
 
z)TestMMapWrapper.test_constructor_bad_filec Cs t|ƒŽ}| ¡}tj|ddddh}|j}t|jjtjƒs@t‚|D] }t    |ƒ}| 
¡| 
¡ksDt‚qDt j t ddt    |ƒW5QRXW5QRXW5QRXdS)NrMT)rSÚ
memory_mapz^$rŒ)r:Ú    readlinesrrGrHÚ
isinstanceÚbufferrÔrrsÚstripr6rÚ StopIteration)r rÐrÙÚlinesÚwrappersÚwrapperÚlineZ    next_linerrrÚ    test_next¥s 
ÿzTestMMapWrapper.test_nextc
CsRt ¡@}t ¡}| |¡tjtddtj|ddW5QRXW5QRXdS)NzUnknown enginerŒZpyt)r¯)    r8r9Ú makeDataFramer­r6rrÖrirk©r r rnrrrÚtest_unknown_engine¶s
 
 
z#TestMMapWrapper.test_unknown_enginec    CsDt ¡2}t ¡}|j|ddt |tj|dd¡W5QRXdS)z\
        'encoding' shouldn't be passed to 'open' in binary mode.
 
        GH 35058
        zw+br4r©Z    index_colN)r8r9rær­rlrirkrçrrrÚtest_binary_mode½s
z TestMMapWrapper.test_binary_modeÚencodingzutf-16zutf-32Ú compression_Úbz2Úxzc
Cstt ¡}t ¡Z}t t¡|j|||dW5QRXd}tjt|dt    j
|||dW5QRXW5QRXdS)zš
        bz2 and xz do not write the byte order mark (BOM) for utf-16/32.
 
        https://stackoverflow.com/questions/55171439
 
        GH 35681
        )r=rëz&UTF-\d+ stream does not start with BOMrŒN) r8rær9Zassert_produces_warningÚUnicodeWarningr­r6rÚ UnicodeErrorrirk)r rërìrnr r×rrrÚtest_warning_missing_utf_bomÈs
 
 z,TestMMapWrapper.test_warning_missing_utf_bomN) rrrrÚrårèrêr6rÃrÄrñrrrrrюs rÑcCs‚t d¡st‚t d¡st‚t d¡r*t‚t d¡r8t‚t d¡rFt‚t d¡rTt‚t d¡rbt‚t d¡rpt‚t d    ¡s~t‚dS)
Nzgcs://pandas/somethingelse.comzgs://pandas/somethingelse.comzhttp://pandas/somethingelse.comzrandom:pandas/somethingelse.comz /local/pathzrelative/local/pathzthis is not fsspec://urlz({'url': 'gs://pandas/somethingelse.com'}z#RFC-3986+compliant.spec://something)rZ is_fsspec_urlrrrrrÚtest_is_fsspec_urlÝsròrërVÚformatr_r|c
Csšt ¡}t ¡t}tj|d|d}t|d|›ƒ|ƒW5QRXtj|d|d(}|dkrltj|dd}n
t |¡}W5QRXW5QRXt     ||¡dS)NrB)r5rëÚto_rMr_rré)
r8rær9Úcodecsr:r¹rirkrÍrl)rërór?r rHrnrrrÚtest_codecs_encodingìs
röc Cs¤t ¡}t ¡~}t|dƒ*}t d¡|ƒ}| |¡W5QRXW5QRXt|dƒ.}t d¡|ƒ}tj    |dd}W5QRXW5QRXW5QRXt 
||¡dS)Nr3rVrQrré) r8rær9r:rõÚ    getwriterr­Ú    getreaderrirkrl)r?r rHÚencodedrnrrrÚtest_codecs_get_writer_readerüs
  ,rúzio_class,mode,msgÚtz*a bytes-like object is required, not 'str'rgz%string argument expected, got 'bytes'c
CsLt ¡}|ƒ4}tjt|d|j|d|›dW5QRXW5QRXdS)NrŒrBr4)r8rær6rÚ    TypeErrorr­)Zio_classr5r×r?rÞrrrÚtest_explicit_encoding    s rýÚencoding_errorsÚstrictÚreplacec
Csd}d}|dkr<d|d|dd|}ttjdd}n.d    |dd
|d |d }ttjd d}t ¡†}t|ƒ}| |¡|dkr¶tj    t
|d|||dW5QRXn>|||d}|j |d}    tj |    |    gi|    dgd}
t  ||
¡W5QRXdS)Nz'utf-8' codec can't decode byteóär_ó,ó
rrrés{"s": {"s":"s"}}Úindex)ZorientrrŒ)rþ©Úerrors)r)rrirkrÍr8r9rÚ write_bytesr6rÚUnicodeDecodeErrorÚdecoderjrl) rþrór×Z bad_encodingÚcontentrtr ÚfilernÚdecodedr?rrrÚtest_encoding_errorss<ÿþýüûúÿ    
 
  r c
CsBt ¡0}tjtddtj|dddW5QRXW5QRXdS)Nzunknown error handler namerŒrBÚbadr)r8r9r6rÚ LookupErrorrrGr rrrÚtest_bad_encdoing_errors=s
rc    Cs8tjtdd }t d¡|jtjks*t‚W5QRXdS)Nz \[Errno 2\]rŒZ doesnt_exist)r6rrÇrirkÚerrnoÚENOENTr)rØrrrÚtest_errno_attributeDs
rc
Cs@tjtdd(tƒ}tj|dddW5QRXW5QRXdS)NrÓrŒrQT)rÛ)r6rrrrrG)rÞrrrÚtest_fail_mmapKsrc CsdGdd„dƒ}tjtdd>tƒ,}t |d¡}|j |ƒ¡W5QRXW5QRXW5QRXdS)Nc@seZdZdd„ZdS)z&test_close_on_error.<locals>.TestErrorcSs tdƒ‚dS)NÚtest)rÊrrrrÚcloseTsz,test_close_on_error.<locals>.TestError.closeN)rrrrrrrrÚ    TestErrorSsrrrŒrQ)r6rrÊrrrGZcreated_handlesÚappend)rrÞrKrrrÚtest_close_on_errorQs
rrtc    Cs"tƒ}t ||¡W5QRXdSr
)rr}Údump)rtrÞrrrÚtest_pickle_reader]sr)DrrõrÚ    functoolsrr§rrrrÔrÚpathlibrr}rCr6Z pandas.compatrZpandas.util._test_decoratorsÚutilZ_test_decoratorsrÂZpandasriZpandas._testingZ_testingr8Zpandas.io.commonÚcommonrrrÆrÅZpy.pathrr+rÚ ImportErrorr r*ÚdirnameÚ__file__rŽrZfixturerÐrÑròrÃrÄrörúrýr rrrrrkrÈrºrÉrÀrËrÌrÍrÎrrrrrÚ<module>s|    
 V
O  þþ
 
 ! ÷þ