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
U
­ý°dÍLã@sšddlZddlZddlZddlmZddlZddlmZm    Z    m
Z
m Z m Z m Z mZmZddlmZddlmZejdd„ƒZejdd„ƒZGd    d
„d
ƒZdS) éN)Úis_categorical_dtype)Ú CategoricalÚCategoricalIndexÚ    DataFrameÚIndexÚIntervalÚSeriesÚ    TimedeltaÚ    Timestamp)ÚCategoricalDtypecCs0tdtjdddittdƒttdƒƒddd    S)
NÚAéÚint64©ÚdtypeÚaabbcaÚcabÚB©rÚname©Úindex©rÚnpÚarangerÚlistÚCDT©rrú]d:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/indexing/test_categorical.pyÚdfs  ÿürcCs0tdtjdddittdƒttdƒƒddd    S)
Nr r rrrÚcaberrrrrrrrÚdf2!s  ÿür!c@s¨eZdZdd„Zdd„Zdd„Zdd„Zd    d
„Zd d „Zd d„Z    dd„Z
dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zej d'd(d)d*gd+d,d-gd.d/d0gd1d2d3gfd4d5„ejDƒd6d5„ejDƒejd(d7d0ged8ed(d9ƒed9d:ƒed:d;ƒge d<d(d(ƒe d<d)d(ƒe d<d*d(ƒge!d(d=ƒe!d)d=ƒe!d*d>ƒgfd?d5„ej"Dƒe#j$ %d(d9d:d;g¡je#j&d@d*dAje#j'dBd*dCjf•¡dDdE„ƒZ(dFdG„Z)dHS)IÚTestCategoricalIndexc    Cs(ttdƒƒ}|jd}ttdƒdd |¡}|j|ks:t‚tdddd    git|ƒd
}t     
||¡|  ¡}d |jd<ttd ƒdd |¡}|j|ks–t‚tdd d d ddd git|ƒd
}t     
||¡t j tdd|jdW5QRX|  ¡}|  ¡}|j t¡|_d|jd<d|jd<t     
||¡dS)NrÚaZaaar©rr rééréréééz^'d'$©ÚmatchÚdé
)rrÚlocrÚastyperÚAssertionErrorrrÚtmÚassert_frame_equalÚcopyÚpytestÚraisesÚKeyErrorrÚobject)ÚselfrrÚresultZbidxÚexpectedZbidx2r!rrrÚtest_loc_scalar,s2 
 
ÿü 
 
z$TestCategoricalIndex.test_loc_scalarc    Cs¼d|jd<| ¡}d|jd<ttdƒdd}tdddd    d
d dd git|ƒd }t ||¡| ¡}d|jd<tddd    d
d dtjgtjtjtjtjtjtjdgdœt|ƒd }t ||¡dS)Nr'r#r.)r-r Zaabbcadrr$r r(r)r*g$@r)r-ÚC)r r=)    r/r4rrrr2r3rÚnan)r9rZdf3Zbidx3Z    expected3Zdf4rrrÚ,test_loc_setitem_with_expansion_non_categoryLs(
 
ÿü 
þûzATestCategoricalIndex.test_loc_setitem_with_expansion_non_categoryc    Cs(tjtdd|jdW5QRXdS)Nz^1$r+r%©r5r6r7r/)r9rrrrÚ$test_loc_getitem_scalar_non_categoryhsz9TestCategoricalIndex.test_loc_getitem_scalar_non_categorycCsPttddddgƒƒ}|ddd…}tjddddgtjd}t | ¡|¡tdt     d¡d 
d    ¡iƒ}t j |j d
d d d dgd|d<tdtd
d ƒgddgdd}|jd}t ||¡tdt     dd¡ 
d    ¡it     dd¡ 
d    ¡d}t j |j d
d d d dgd|d<|jdd…}t ||¡tdtd
d ƒgddgdd}|jd}t ||¡dS)Nr%r(r)r*éÿÿÿÿrÚvalueédrréé2éK)ZbinsÚDé r.©rrér'ré    é)rrrÚarrayrr2Zassert_numpy_array_equalZ    __array__rrr0ÚpdZcutrCrÚilocÚassert_series_equalr3r/)r9ÚcatÚreverseÚexprr;r:rrrÚ test_slicingls&
 þ 
z!TestCategoricalIndex.test_slicingcCsðtdddddddgdddgd}tddddd    d
d gƒ}d d dddddg}t||dœ|d}tddgdddgd}tddgƒ}ddg}t||dœ|d}t||dd}    tddgddgddd}
d} |jd d…dd…f} t | |¡t| djƒsôt    ‚|jd dd…f} t 
| |
¡t | dt ƒs&t    ‚|jdd…df}t 
||    ¡t|jƒsTt    ‚|jd}|| kslt    ‚|j dd…dd…f} t | |¡t| djƒs¢t    ‚|j ddd…f} t 
| |
¡t | dt ƒsÔt    ‚|j dd…df}t 
||    ¡t|jƒst    ‚|j d}|| kst    ‚|j d|jdf}|| ks<t    ‚|jd}|| ksTt    ‚|jd}|| kslt    ‚|jd g}||ddk}t ||¡||ddk}t ||¡|jd}|| ksÈt    ‚|jd } t 
| |
¡t | dt ƒsòt    ‚|jtd dƒ} t | |¡t| djƒs"t    ‚|jd dg} t | |¡t| djƒsPt    ‚|jdd…df}t 
||    ¡t|jƒs~t    ‚|jdd…tdd ƒf} t | |¡t| djƒs¶t    ‚|jdd…dd gf} t | |¡t| djƒsìt    ‚dS)Nr#ÚcÚb©Ú
categoriesÚhÚiÚjÚkÚlÚmÚnr%r(r)r*r&r é©ÚcatsÚvaluesrrcrJrdr8)rrrr)r(r)r\rc)rrrrrPr2r3rrr1rQÚ
isinstanceÚstrr/ÚcolumnsZiatÚatÚslice)r9rcÚidxrdrZcats2Zidx2Zvalues2Zexp_dfZexp_colZexp_rowZexp_valZres_dfZres_rowZres_colZres_valZ    exp_fancyZ    res_fancyrrrÚtest_slicing_and_getting_ops…s†ÿ    
 
 
 
 
 
      z1TestCategoricalIndex.test_slicing_and_getting_opscCsztdddddddgdddgd}tddddd    d
d gƒ}d d d d dddg}t||dœ|d}|jd d…dd…f}ttddgdddgdd d gdœddgd}t ||¡|jd d…dd…fj}tddgddgƒ}t ||¡|j    dd…df}ttdddgdddgddddgdd}t ||¡|j    dd…|j
dd …f}tdtdddgdddgdidddgd}t ||¡dS)Nr#rWrVrXrZr[r\r]r^r_r`r%r(r)r*r&rbrÚcategoryrrcrdrJr) rrrrPr2r3ZdtypesrrQr/rg)r9rcrjrdrr:r;rrrÚtest_slicing_doc_examplesþs>ÿþû  ý þz.TestCategoricalIndex.test_slicing_doc_examplescCs4|jddg}|jddddg}tj||dddS)    NrVr#r*rr%r&T©Zcheck_index_type)r/rPr2r3)r9rr:r;rrrÚ test_loc_getitem_listlike_labels$sz5TestCategoricalIndex.test_loc_getitem_listlike_labelsc    Cs4tjtt d¡d|jdddgW5QRXdS)Nú['e'] not in indexr+r#rWÚe©r5r6r7ÚreÚescaper/©r9r!rrrÚ)test_loc_getitem_listlike_unused_category*sz>TestCategoricalIndex.test_loc_getitem_listlike_unused_categoryc    Cs(tjtdd|jdW5QRXdS)Nz^'e'$r+rqr@rurrrÚ&test_loc_getitem_label_unused_category0sz;TestCategoricalIndex.test_loc_getitem_label_unused_categoryc    Cs2tjtt d¡d|jddgW5QRXdS)Nz['d'] not in indexr+r#r-rrrurrrÚtest_loc_getitem_non_category5sz2TestCategoricalIndex.test_loc_getitem_non_categorycCsd| ¡}d|jd<|jdddg}ttdƒtdƒdd}td    d
d d d ddgi|d}t ||¡dS)Nr'rqr#rWZaaabber r)rYrr rr%r&r(r)r)r4r/rrrr2r3)r9r!rr:Ú    exp_indexr;rrrÚ0test_loc_setitem_expansion_label_unused_category:s 
zETestCategoricalIndex.test_loc_setitem_expansion_label_unused_categoryc    Csútdddgƒ}tdddgddd    gd
œ|d }|jddg}tddg|jd }tddgddgd
œ|d }tj||d d|jdddg}tdddg|jd }tdddgdddgd
œ|d }tj||d dtjtt     
d¡d|jddgW5QRXdS)Nr#rWrVr%r(r)r*r&r ©r rrrXTrnú['x'] not in indexr+Úx) rrr/rYr2r3r5r6r7rsrt)r9rrÚresryrTrrrÚtest_loc_listlike_dtypesCsz-TestCategoricalIndex.test_loc_listlike_dtypesc    Csøtdddgƒ}tdddgdddgd    œ|d
}|jddg}tdddgdddgd    œtdddgƒd
}tj||d d |jdddg}tdddddgdddddgd    œtdddddgƒd
}tj||d d tjtt     d ¡d|jddgW5QRXdS)Nr#rWr%r(r)r*r&r r{rTrnr|r+r})
rrr/r2r3r5r6r7rsrt©r9rrr~rTrrrÚ8test_loc_listlike_dtypes_duplicated_categories_and_codesZs  ÿþzMTestCategoricalIndex.test_loc_listlike_dtypes_duplicated_categories_and_codesc    Cstddddgtdƒd}tdddd    gd
d d d gdœ|d}|jddg}tdddgd
d d gdœtdddgtdƒdd}tj||dd|jdddg}tdddddgd
d d
d d gdœtdddddgtdƒdd}tj||ddtjtt     
d¡d|jddgW5QRXdS)Nr#rWrVÚabcderXr%r(r)r*r&r rarMr{rTrnr|r+r}) rrrr/r2r3r5r6r7rsrtr€rrrÚ(test_loc_listlike_dtypes_unused_categoryqs "þþz=TestCategoricalIndex.test_loc_listlike_dtypes_unused_categoryc    Cstddddgtdƒd}tdddd    gd
d d d gdœ|d}tjtdd|jdW5QRXtjtt d¡d|jddgW5QRXdS)Nr#rWrVr‚rXr%r(r)r*r&r rarMr{rrqr+rp)    rrrr5r6r7r/rsrt)r9rrrrrÚ9test_loc_getitem_listlike_unused_category_raises_keyerrorˆs "zNTestCategoricalIndex.test_loc_getitem_listlike_unused_category_raises_keyerrorcCs`ttj dd¡tdƒtdƒd}| ¡}t|jƒ|_t|jƒ|_t    |j
ddd…f|jdd}t   |j
ddd…f|¡t    |j
dd…df|jdd}t   |j
dd…df|¡ttdƒdd    d
gd }t|j
dd    gdd…f|j|d }t   |j
dd    gdd…f|¡ttd ƒdddgd }t|j
dd…ddgf|j|d}t   |j
dd…ddgf|¡dS)Nr)ÚABCZXYZ©rrgr rJÚXZABrr=rX©rgrZXYÚYÚZ)rrÚrandomÚrandnrr4rrrgrr/r2rQr3)r9rÚcdfÚexpectryÚ exp_columnsrrrÚtest_ix_categorical_index”s   ""z.TestCategoricalIndex.test_ix_categorical_indexcCslttj dd¡tdƒtdƒd}| ¡}t|jƒ|_t|jƒ|_ttdƒddgd}t|j    ddd…f|j|d    }t
  |j    ddd…f|¡ttd
ƒd d gd}t|j    dd…d f|j|d}t
  |j    dd…d f|¡t|j    ddgdd…f|jttd ƒƒd    }t
  |j    ddgdd…f|¡t|j    dd…d d gf|jttdƒƒd}t
  |j    dd…d d gf|¡dS)Nr)ZABAZXYXr†ZAAr rrXrˆZXXr‡r‰ZAABZXXY) rrr‹rŒrr4rrrgr/r2r3)r9rrryrŽrrrrÚ$test_ix_categorical_index_non_unique©s,   
ý
ýz9TestCategoricalIndex.test_ix_categorical_index_non_uniquec    CsZd}tjt|d|jdd…W5QRX|jdd…}|jddd    g}t ||¡dS)
NzRcannot do slice indexing on CategoricalIndex with these indexers \[1\] of type intr+r%r&rWrVr(r)r*)r5r6Ú    TypeErrorr/rPr2r3)r9rÚmsgr:r;rrrÚtest_loc_sliceÆsÿz#TestCategoricalIndex.test_loc_slicecCs|tddgddgddggtddd    gƒd
}|d }|jddksBt‚|jddksTt‚|jd dksft‚|jd dksxt‚dS) Nr%r(r)r*r&r r rr=rr)rr%)rrr/r1rh)r9rÚsrrrÚ&test_loc_and_at_with_categorical_indexÓs ÿz;TestCategoricalIndex.test_loc_and_at_with_categorical_indexÚ
idx_valuesr%r(r)rBéþÿÿÿéýÿÿÿçø?ç@ç @gø¿gÀg Àccs"|]}tjdddg|dVqdS©r%r(r)rN©rrN©Ú.0rrrrÚ    <genexpr>észTestCategoricalIndex.<genexpr>ccs"|]}tjdddg|dVqdS)ršr›rœrNrž)r Zdtyprrrr¡ësrWrr*r rLiãr-rHccs"|]}tjdddg|dVqdSr)rOrNrŸrrrr¡ósz
2019-01-01)ÚperiodsZ1d)Ústartr¢cCsŒt||d}tddddgi|d}t|d|dƒ}|j|d}tdgdg|dd    }t ||¡|j|dd
…}tddg|dd
…dgd }t ||¡|j|}tddg|dd
…dgd }t ||¡| ¡}d |j|d<tdd ddgi|d}t ||¡| ¡}d d g|j|dd
…df<tdd d dgi|d}t ||¡| ¡}d d g|j|df<tdd d dgi|d}t ||¡dS)N)Úorderedr ZfooÚbarZbazrrr%rJr(r†ZquxZqux2)    rrrir/rr2rQr3r4)r9r—r¤Zcat_idxrÚslr:r;rrrÚ+test_loc_getitem_with_non_string_categoriesàs0   
   z@TestCategoricalIndex.test_loc_getitem_with_non_string_categoriescCs‚tddtjgƒ}ttdƒ|d}|tjdks2t‚|jtjdksFt‚t|ƒ}|jtjdfdksft‚|jtjddks~t‚dS)Nr rr)rr(r)rrr>rÚranger1r/r)r9ÚciZserrrrrÚ!test_getitem_categorical_with_nan!sz6TestCategoricalIndex.test_getitem_categorical_with_nanN)*Ú__name__Ú
__module__Ú __qualname__r<r?rArUrkrmrorvrwrxrzrrrƒr„rr‘r”r–r5ÚmarkZ parametrizer2ZALL_INT_NUMPY_DTYPESZFLOAT_NUMPY_DTYPESrrNr8rr
r    ZALL_INT_EA_DTYPESrOZ IntervalIndexZ from_breaksZ
date_rangeZtimedelta_ranger§rªrrrrr"+sR y&       û ñëþ
'r")rsÚnumpyrr5Zpandas.core.dtypes.commonrZpandasrOrrrrrrr    r
Zpandas._testingZ_testingr2Zpandas.api.typesr rZfixturerr!r"rrrrÚ<module>s (