zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
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
U
­ý°d¡"ã
@sºdZddlmZddlZddlZddlZddlmZddl    Z
ddl    m Z m Z m Z ddlmZej d¡Zej d¡Zeej dd    eƒd    d    eƒd
œg¡d d „ƒƒZeej dd d    idd    ig¡dd„ƒƒZedd„ƒZedd„ƒZeejjdd„ƒƒZdd„Zedd„ƒZedd„ƒZdd„Zej dd d!g¡ej d"d#d d$gd#d$d gd#d d$d%gd$d d#gg¡d&d'„ƒƒZ d(d)„Z!d*d+„Z"ed,d-„ƒZ#d.d/„Z$d0d1„Z%ej d2d3d4d5d6g¡d7d8„ƒZ&d9d:„Z'dS);zW
Tests dtype specification during parsing
for all of the parsers defined in parsers.py
é)ÚStringION)ÚCategoricalDtype)Ú CategoricalÚ    DataFrameÚ    TimestampZ pyarrow_xfailZ pyarrow_skipÚdtypeÚcategory©ÚaÚbÚccCsX|}d}ttdddgƒtdddgƒtdddgƒdœƒ}|jt|ƒ|d    }t ||¡dS)
Núa,b,c
1,a,3.4
1,a,3.4
2,b,4.5Ú1Ú2r
r ú3.4ú4.5r    ©r©rrÚread_csvrÚtmÚassert_frame_equal©Ú all_parsersrÚparserÚdataÚexpectedÚactual©rúed:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/io/parser/dtypes/test_categorical.pyÚtest_categorical_dtypes    ýÿrr écCsP|}d}tdddgtdddgƒdddgdœƒ}|jt|ƒ|d    }t ||¡dS)
Nr r ér
r g333333 @g@r    rrrrrrÚtest_categorical_dtype_single4s ÿr"cCsX|}d}ttdddgƒtdddgƒtdddgƒdœƒ}|jt|ƒd    d
}t ||¡dS) Nza,b,c
1,b,3.4
1,b,3.4
2,a,4.5rrr r
rrr    rrr©rrrrrrrrÚtest_categorical_dtype_unsortedDs   ýÿr$cCsZ|}d}ttdddgƒtdtjdgƒtdddgƒdœƒ}|jt|ƒd    d
}t ||¡dS) Nza,b,c
1,b,3.4
1,nan,3.4
2,a,4.5rrr r
rrr    rr)rrÚnpÚnanrrrrr#rrrÚtest_categorical_dtype_missingWs  ýÿr'cCs€|}t dd„tdƒDƒ¡}tdt|ddiƒ}|jtdd |¡ƒd    d
}|djj    t |j
jj ¡dd|d<t   ||¡dS) NcSsg|] }t|ƒ‘qSr)Ústr)Ú.0ÚirrrÚ
<listcomp>oszCtest_categorical_dtype_high_cardinality_numeric.<locals>.<listcomp>ir
T)Úorderedza
Ú
rr)r%ÚsortÚrangerrrrÚjoinÚcatZreorder_categoriesr
Ú
categoriesrrr#rrrÚ/test_categorical_dtype_high_cardinality_numericjs
ÿ
r3cCsVtj |d¡}|}d}d}|j|||d}| t¡}|j|||dd}t ||¡dS)Nz utf16_ex.txtzutf-16ú    )ÚsepÚencodingr)r5r6r)ÚosÚpathr0rÚapplyrrr)rÚ csv_dir_pathÚpthrr6r5rrrrrÚtest_categorical_dtype_utf16ys
r<c    CsŒ|}d}tddgtddgƒdœƒtddgtddgƒdœddgd    g}|jt|ƒdd
idd &}t||ƒD]\}}t ||¡qhW5QRXdS) Núa,b
1,a
1,b
1,b
2,cr r
r ©r
r r!r é©Úindexr©rÚ    chunksize)rrrrÚziprr)rrrÚ    expectedsÚactualsrrrrrÚ1test_categorical_dtype_chunksize_infer_categories‡s þÿrGc        Cs¦|}d}dddg}tddgtddg|ddœƒtddgtddg|ddœdd    gd
g}t|ƒ}|jt|ƒd|idd &}t||ƒD]\}}t ||¡q‚W5QRXdS) Nr=r
r r r ©r2r>r!r?r@rB)rrrrrrDrr)    rrrZcatsrErrFrrrrrÚ4test_categorical_dtype_chunksize_explicit_categories›s
þþrIcCs\tj |d¡}|}d}|j|d|d}t|dƒ|d<|j|d|ddid}t ||¡dS)Nzunicode_series.csvzlatin-1)Úheaderr6r r)rJr6r)r7r8r0rrrr)rr:r;rr6rrrrrÚtest_categorical_dtype_latin1²srKr,FTr2r
r ÚdcCsb|}d}tddddgtddddg||ddœƒ}dt||di}|jt|ƒ|d    }t ||¡dS)
Nr=r r!r
r r )r2r,r>r)rrrrrrr)rr2r,rrrrÚresultrrrÚtest_categorical_category_dtype¿s
 
ÿþÿ    rNcCsh|}d}tdddgƒ}tddddgtddddgdddgddœƒ}|jt|ƒd|id    }t ||¡dS)
Nr=r r r
r r!rHr>r©rrrrrrr)rrrrrrMrrrÚ(test_categorical_category_dtype_unsortedÙs
þÿrPcCsT|}dtdddgƒi}d}tdtddddgƒiƒ}|jt|ƒ|d}t ||¡dS)Nr r r!r?z    b
1
1
2
3rrO©rrrrrrMrrrÚ test_categorical_coerces_numericìs rRcCs`|}tjdddgdd}dt|ƒi}d}tdt|djƒiƒ}|jt|ƒ|d}t     ||¡dS)Nz
2017-01-01z
2018-01-01z
2019-01-01)Úfreqr z"b
2017-01-01
2018-01-01
2019-01-01r)
ÚpdZ DatetimeIndexrrrr2rrrr)rrZdtirrrrMrrrÚ!test_categorical_coerces_datetime÷s rUcCsV|}dttdƒgƒi}d}tdttdƒgdƒiƒ}|jt|ƒ|d}t ||¡dS)Nr Z2014zb
2014-01-01
2014-01-01r!r)rrrrrrrrrQrrrÚ"test_categorical_coerces_timestamps rVcCsX|}dtt dddg¡ƒi}d}tdt|djƒiƒ}|jt|ƒ|d}t     ||¡dS)Nr Z1HZ2HZ3Hz
b
1H
2H
3Hr)
rrTZ to_timedeltarrr2rrrrrQrrrÚ"test_categorical_coerces_timedeltas rWrzb
True
False
NA
Falsezb
true
false
NA
falsezb
TRUE
FALSE
NA
FALSEzb
True
False
NA
FALSEcCsN|}dtddgƒi}tdtddddgƒiƒ}|jt|ƒ|d}t ||¡dS)Nr FTrrO)rrrrrrMrrrÚ&test_categorical_dtype_coerces_booleans
rXcCsZ|}dtddddgƒi}d}tdttdƒ|ddiƒ}|jt|ƒ|d}t ||¡dS)Nr r
rLÚez    b
d
a
c
dZdacdr)rrrÚlistrrrrrQrrrÚ&test_categorical_unexpected_categories-s r[)(Ú__doc__Úiorr7Únumpyr%ZpytestZpandas.core.dtypes.dtypesrZpandasrTrrrZpandas._testingZ_testingrÚmarkZ usefixturesZ xfail_pyarrowZ skip_pyarrowZ parametrizerr"r$r'Zslowr3r<rGrIrKrNrPrRrUrVrWrXr[rrrrÚ<module>sr      ýþ  
 
 
 
 $þ  
  üþ