zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
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
U
¬ý°dr3ã@sâddlZddlZddlZddlmZmZmZmZm    Z    m
Z
m Z m Z m Z mZmZddlmZddlmmZGdd„dƒZGdd„dƒZGdd„dƒZej d    d
d g¡d d „ƒZej d    d
d g¡dd„ƒZejdd„ƒZdd„Z dS)éN) ÚNAÚ CategoricalÚCategoricalIndexÚIndexÚIntervalÚ IntervalIndexÚNaTÚ PeriodIndexÚSeriesÚ    TimedeltaÚ    Timestampc
@seZdZdd„Zdd„Zej deddgƒeddgddgdg¡d    d
„ƒZ    ej deddgddd gdeddgddd gdeddgdgdeddgdgdg¡d d „ƒZ
ej deddgƒeddgddgddeddgddd gddg¡dd„ƒZ dd„Z dd„Z dS)Ú!TestCategoricalIndexingWithFactorcCs„|ddkst‚|ddks t‚|dddg}t |jtjdddgtjd¡|t |¡dk}t |jtjdddgtjd¡dS)NrÚaéÿÿÿÿÚcéé©Údtype)ÚAssertionErrorÚtmÚassert_numpy_array_equalÚ_codesÚnpÚarrayÚint8Zasarray)ÚselfÚfactorZsubf©rúdd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/arrays/categorical/test_indexing.pyÚ test_getitems  z.TestCategoricalIndexingWithFactor.test_getitemc    Cs–| ¡}d|d<|ddks t‚d|d<|ddks8t‚| ¡}tjt|ƒdd}d|d<d|d<d||<tddddddddgdd    }t ||¡dS)
NÚbrrrÚboolrTr©Úordered)ÚcopyrrÚzerosÚlenrrÚassert_categorical_equal)rrrÚindexerÚexpectedrrrÚ test_setitem"sz.TestCategoricalIndexingWithFactor.test_setitemÚotherr!r©Ú
categoriescCsRtddgddgd}t ddg¡}||||<tddgddgd}t ||¡dS)Nrr!r-TF)rrrrr()rr,ÚtargetÚmaskr*rrrÚtest_setitem_same_but_unordered4s
 zATestCategoricalIndexingWithFactor.test_setitem_same_but_unorderedrc    CsPtddgddgd}t ddg¡}d}tjt|d||||<W5QRXdS)Nrr!r-TFúCCannot set a Categorical with another, without identical categories©Úmatch©rrrÚpytestÚraisesÚ    TypeError©rr,r/r0ÚmsgrrrÚ'test_setitem_different_unordered_raises@s
zITestCategoricalIndexingWithFactor.test_setitem_different_unordered_raisesT©r.r$c    CsRtddgddgdd}t ddg¡}d}tjt|d||||<W5QRXdS)Nrr!Tr<Fr2r3r5r9rrrÚ test_setitem_same_ordered_raisesQs
 
zBTestCategoricalIndexingWithFactor.test_setitem_same_ordered_raisescCs.tdddgƒ}|d|d<|ddks*t‚dS)N)rr)rrrr)rr©rÚcatrrrÚtest_setitem_tupleas z4TestCategoricalIndexingWithFactor.test_setitem_tuplecCs„tj d¡ttjjdddd tj¡ƒ dg¡}t dg¡ tj    ¡}d||<|j
t dg¡ tj    ¡}t   |tjdgdd    ¡dS)
NrrééðI©Úsizeiüÿÿ順rr) rÚrandomÚseedrÚrandintÚastyperZadd_categoriesrÚint64Úcodesrr)rr?r)ÚresultrrrÚtest_setitem_listlikeis ÿþz7TestCategoricalIndexingWithFactor.test_setitem_listlikeN)Ú__name__Ú
__module__Ú __qualname__r r+r6ÚmarkÚ parametrizerr1r;r=r@rMrrrrr s4
þ
üþ    
 
ýþ
r c@s,eZdZdd„Zdd„Zdd„Zej dde    j
e e e j
d    d
d d d dg ¡dd„ƒZej dddddgddgg¡dd„ƒZej dddddgddddgddddgddddgg¡ej dddgddgddgddgg¡ej deeg¡ej ddddg¡dd „ƒƒƒƒZd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„ZdS)+ÚTestCategoricalIndexingcCs^tdddddddgƒ}|d}|dks*t‚|dd…}tddgddddgd}t ||¡dS)Nrr!rÚdérAr-)rrrr()rr?Zslicedr*rrrÚtest_getitem_slicezs   z*TestCategoricalIndexing.test_getitem_slicecCsntj d¡ttjjdddd tj¡ƒ}|jt dg¡ tj    ¡}|t dg¡ tj    ¡j}t
  ||¡dS)NrrrArBrCrE) rrFrGrrHrIrrKrrJrr)rrrLr*rrrÚtest_getitem_listlikeƒs
 z-TestCategoricalIndexing.test_getitem_listlikec
Csftddddddgdd}t|ƒ}t|ƒtjddddddgtjd    }tdddgdd}t |j|¡t     |j
|¡tddddddgdd}t|d
d }t|ƒtjddddddgtjd    }tdddgdd}t |j|¡t     |j
|¡td d dddddgdd}t|d
d }    tjdddddddgtjd    }tdddddd d gdd}t |    j|¡t     |    j
|¡dS)Nz2014-01z2014-02z2014-03ÚM©ÚfreqrrrrTr#z2013-12z2013-11z2013-10z2013-09z2013-08z2013-07z2013-05érAérU) r    rÚstrrrrrrrÚassert_index_equalr.)
rZidx1Zcat1Zexp_arrZexp_idxZidx2Zcat2Zexp_idx2Zidx3Zcat3rrrÚtest_periodindexŒs\ÿÿ ù    ö ù    ö z(TestCategoricalIndexing.test_periodindexÚnull_valNrZnatZNATÚnanÚNaNZNANcCsDtdd|gdd}tdddgdd}|dtks4t‚t ||¡dS)    Nz
2022-04-06z
2022-04-07ÚDrYrz    period[D]rr)r    rrrr^)rr`rLr*rrrÚtest_periodindex_on_null_types¿sz6TestCategoricalIndexing.test_periodindex_on_null_typesÚnew_categoriesrrrUr\c    Cs<tddddgƒ}d}tjt|d| |¡W5QRXdS)Nrr!rzKnew categories need to have the same number of items as the old categories!r3)rr6r7Ú
ValueErrorZrename_categories)rrer?r:rrrÚ/test_categories_assignments_wrong_length_raisesÊs
ÿzGTestCategoricalIndexing.test_categories_assignments_wrong_length_raisesÚ
idx_valuesÚ
key_valuesrAÚ    key_classrÚcategoryÚkeyc CsŒ||tddƒd}|dkr |j}t||d}| |¡\}}| |¡\}    }
t ||    ¡t ||
¡| ¡ |¡} | ¡ |¡} t | | ¡dS)NrrAr-rlr)ÚrangerrZget_indexer_non_uniquerrÚuniqueZ get_indexer) rrhrirjrrlÚidxr*Zexp_missrLZres_missZ
exp_uniqueZ
res_uniquerrrÚtest_get_indexer_non_uniqueÕs       z3TestCategoricalIndexing.test_get_indexer_non_uniquecCsˆttddgƒƒ}| ddg¡}ttddgddgdƒ}t ||¡ttddgƒƒ}| ddg¡}ttddgddgdƒ}t ||¡dS)Nrr!TFr-)r
rÚwhererÚassert_series_equal©rÚserrLr*rrrÚtest_where_unobserved_nanïs z1TestCategoricalIndexing.test_where_unobserved_nancCs\ttdddgddddgdƒ}|jdddgdd}ttdddg|jjdƒ}t ||¡dS)    Nrr!rrTr-TF)r,)r
rrqr?r.rrrrsrrrÚ test_where_unobserved_categoriesûsz8TestCategoricalIndexing.test_where_unobserved_categoriescCsrttdddgddddgdƒ}tdddgddddgd}| dddg|¡}ttdddg|jdƒ}t ||¡dS)    Nrr!rrTr-TFr)r
rrqrrrr)rrtr,rLr*rrrÚtest_where_other_categoricals
z4TestCategoricalIndexing.test_where_other_categoricalc    CsFttdddgƒƒ}d}tjt|d| dddgd¡W5QRXdS)    Nrr!rz3Cannot setitem on a Categorical with a new categoryr3TFrT©r
rr6r7r8rq)rrtr:rrrÚtest_where_new_category_raisessz6TestCategoricalIndexing.test_where_new_category_raisesc    Cslttdddgddddgddƒ}tdddgddddgdd}tjtdd| dd    dg|¡W5QRXdS)
Nrr!rrTTr<zwithout identical categoriesr3Frx)rrtr,rrrÚ!test_where_ordered_differs_rasiessÿ
ÿz9TestCategoricalIndexing.test_where_ordered_differs_rasies)rNrOrPrVrWr_r6rQrRrrarrÚmathrdrgrrrprurvrwryrzrrrrrSys.        3þ
 
 
*ÿ$ rSc    @sfeZdZdd„Zejjdeddƒdfdedd    ƒd
fd edƒd
fe    dƒd
fge
d d d„ƒZ dd„Z dS)Ú TestContainsc    Cs¨ttdƒtdƒd}d|ks t‚d|ks,t‚tj|ks:t‚tjtdddg|ksXt‚W5QRXd    |ksnt‚d|kszt‚ttdƒtjgtdƒd}tj|ks¤t‚dS)
NZaabbcaZcabr-r!Úzzunhashable type: 'list'r3rr)rÚlistrrrar6r7r8r>rrrÚ test_containss    zTestContains.test_containszitem, expectedrrT)çø?Tgà?r€F)rF)ÚidscCs*tt tdƒ¡ƒ}||k}||ks&t‚dS)NrU)rrZ from_breaksrmr)rÚitemr*r?rLrrrÚtest_contains_interval+sz#TestContains.test_contains_intervalc    Cshtdddgƒ}d|kst‚tjtdddg|kW5QRXtjtddddg|kW5QRXdS)NrrrUrzunhashable typer3r!)rrr6r7r8r>rrrÚtest_contains_list=s  zTestContains.test_contains_listN) rNrOrPrr6rQrRrr r r]rƒr„rrrrr|s  
 
úö
r|ÚindexTFcCsZttdƒƒ}tdddgƒ}|r&t|ƒ}t |¡s4t‚||}|| d¡}t     ||¡dS)NrUTFÚobject)
r
rmrrÚcomZis_bool_indexerrrIrrr©r…rtrorLr*rrrÚtest_mask_with_booleanJs r‰cCsLttdƒƒ}tdddgƒ}|r&t|ƒ}||}|| d¡}t ||¡dS)NrUTF)r
rmrrZfillnarrrrˆrrrÚ*test_mask_with_boolean_na_treated_as_falseWs rŠc    cs6ddd„}| ¡}| td|¡dVW5QRXdS)z¡
    Monkeypatch Categorical.__array__ to ensure no implicit conversion.
 
    Raises
    ------
    ValueError
        When Categorical.__array__ is called.
    NcSs tdƒ‚dS)NzI cannot be converted.)rf)rrrrrrrsz(non_coercible_categorical.<locals>.arrayZ    __array__)N)ÚcontextÚsetattrr)Z monkeypatchrÚmrrrÚnon_coercible_categoricales
 
rŽcCs0tdddgƒ}t|ƒ}|jd}|dks,t‚dS)Nrr!rr)rr
Úatr)ZarrrtrLrrrÚtest_series_atzs
r)!r{Únumpyrr6Zpandasrrrrrrrr    r
r r Zpandas._testingZ_testingrZpandas.core.commonÚcoreÚcommonr‡r rSr|rQrRr‰rŠZfixturerŽrrrrrÚ<module>s 4 b!1