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
U
¬ý°dê=ã@sdddlZddlZddlZddlZddlmZmZmZm    Z    ddl
m Z Gdd„dƒZ Gdd„dƒZdS)éN)Ú CategoricalÚ    DataFrameÚSeriesÚ
date_rangec@seZdZdd„Zdd„ZdS)ÚTestCategoricalOpsWithFactorc    Cs,tddddddddgdd}t ||¡dS)NÚaÚbÚcT©Úordered)rÚtmÚassert_categorical_equal)ÚselfÚfactor©rúed:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/arrays/categorical/test_operators.pyÚ test_categories_none_comparisonssz=TestCategoricalOpsWithFactor.test_categories_none_comparisonsc    Cs||dk}|t |¡dk}t ||¡||dk}|t |¡dk}t ||¡||dk}|t |¡dk}t ||¡||dk}|t |¡dk}t ||¡||dk}|t |¡dk}t ||¡||dk}|t |¡dk}t ||¡t|ƒ}|tj |¡}||k}t |¡t |¡k}t ||¡|dk}tjt|ƒt    d}t ||¡t
dddgdddgdd}t
dddgdddgdd}t
dddgdd}t
dddg|j dd}    ||k}
t  dd    d    g¡} t |
| ¡||k}
t  d    d    dg¡} t |
| ¡||    k} t  d    d    dg¡} t | | ¡d
}t jt|d ||kW5QRXt
dddgddddgd }t jt|d ||kW5QRX| d    ¡}||k ¡r¨t‚t jt|d ||kW5QRXtdddgƒ}d }t jt|d ||kW5QRXt jt|d ||kW5QRXt jt|d ||kW5QRXt jt|d ||kW5QRXt  dddg¡}t jt|d ||kW5QRXt jt|d ||kW5QRXt
tdƒtdƒdd}t  dd    d    g¡} |dk} t | | ¡|t  d¡k} t | | ¡dS)Nrr    rÚd©ZdtypeT©Ú
categoriesr r
Fú>Categoricals can only be compared if 'categories' are the same©Úmatch©rúMCannot compare a Categorical for op __gt__ with type <class 'numpy\.ndarray'>ÚabcÚcba)ÚnpZasarrayr r ÚlenÚrandomZ permutationÚassert_numpy_array_equalÚzerosÚboolrrÚarrayÚpytestÚraisesÚ    TypeErrorZ set_orderedÚanyÚAssertionErrorrÚlist)rrÚresultÚexpectedÚnÚotherÚcat_revÚ cat_rev_baseÚcatÚcat_baseÚres_revÚexp_revÚresÚexpÚmsgZ cat_rev_base2Z cat_unorderdÚsrrrrÚtest_comparisonss–              ÿ   
ÿ z-TestCategoricalOpsWithFactor.test_comparisonsN)Ú__name__Ú
__module__Ú __qualname__rr9rrrrrsrc    @seZdZdd„Zdd„Zdd„Zdd„Zd    d
„Zd d „Zd d„Z    dd„Z
e j   dedƒedƒedƒfdddgdddgdddgfg¡dd„ƒZe j   ddd„dd„g¡dd„ƒZd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Ze j   d*d+d,d-d.g¡d/d0„ƒZd1d2„Zd3S)4ÚTestCategoricalOpscCszddddg}t|ƒ}t|ƒ}||jk}tddddggƒ}t ||¡|ddd…|jk}tddddggƒ}t ||¡dS)NrréTéÿÿÿÿF)rrÚTr Zassert_frame_equal)rÚdatar1Údfr+r,rrrÚtest_compare_frameƒs 
 z%TestCategoricalOps.test_compare_framec    CsH|}tddddgƒ}t|ƒ}d}tjt|d|||ƒW5QRXdS)Nrrr>z5Unable to coerce to Series, length must be 1: given 4r)rrr%r&Ú
ValueError)rZ comparison_opÚopr1rBr7rrrÚtest_compare_frame_raises’s z,TestCategoricalOps.test_compare_frame_raisescCsXttddddd}t ||dkt dddg¡¡t |d|kt dddg¡¡dS)Nz
2014-01-01é)ZperiodsTr
rF)rrr r!rr$)rZdt_catrrrÚ$test_datetime_categorical_comparison›s z7TestCategoricalOps.test_datetime_categorical_comparisoncCsVtdddgdd}t ||dkt dddg¡¡t |d|kt dddg¡¡dS)Nér>rGTr
rF)rr r!rr$)rr1rrrÚ&test_reflected_comparison_with_scalars s z9TestCategoricalOps.test_reflected_comparison_with_scalarsc    CsÚtdddgdd}d}tjt|d|dkW5QRXtjt|d|dkW5QRXtjt|dd|kW5QRXtjt|dd|kW5QRXt |dkt d    d    d    g¡¡t |dkt dddg¡¡dS)
NrIr>rGTr
z1Invalid comparison between dtype=category and intréF)rr%r&r'r r!rr$)rr1r7rrrÚ$test_comparison_with_unknown_scalars¦sz7TestCategoricalOps.test_comparison_with_unknown_scalarscCsˆttjddddgtdƒ}|dk}tjddddgtd}t ||¡|dk}tjddddgtd}t ||¡|dk}t ||¡dS)NZfoo)rrIrGrTF)rrr$Úobjectr#r r!)rr1r+r,rrrÚtest_comparison_with_tuple¹s  z-TestCategoricalOps.test_comparison_with_tuplec    Csrtddddgdddgdd}d}t ¡&t dt¡tt |¡|ƒ|ƒ}W5QRXt||ƒ|ƒ}t     ||¡dS©NrIr>rGTrÚignore©
rÚwarningsÚcatch_warningsÚ simplefilterÚRuntimeWarningÚgetattrrr$r r!)rÚcompare_operators_no_eq_ner1Úscalarr,ÚactualrrrÚ9test_comparison_of_ordered_categorical_with_nan_to_scalarÇs
 zLTestCategoricalOps.test_comparison_of_ordered_categorical_with_nan_to_scalarc    CsŠtddddgdddgdd}tddddgdddgdd}t ¡&t dt¡tt |¡|ƒdƒ}W5QRXt||ƒ|ƒ}t     ||¡dSrOrQ)rrWr1r.r,rYrrrÚ;test_comparison_of_ordered_categorical_with_nan_to_listlike×s
 zNTestCategoricalOps.test_comparison_of_ordered_categorical_with_nan_to_listlikezdata,reverse,baserrÚbbbrIr>rGc    Cs|tt||ddƒ}tt||ddƒ}tt|ddƒ}tt||jjddƒ}t|ƒ}t |¡}    ||k}
tdddgƒ} t |
| ¡||k}
tdddgƒ} t |
| ¡||k} tdddgƒ} t | | ¡|d}||k} tdddgƒ} |j|k}t | | ¡t     | j|¡||k}
tdddgƒ} |j|k}t |
| ¡t     |
j|¡d}t
j t |d||kW5QRXd}t
j t |d||kW5QRXt
j t |d||kW5QRXt
j t |d||    kW5QRXt
j t |d||    kW5QRXt
j t |d||kW5QRXt
j t |d||kW5QRXt
j t |d|    |kW5QRXt
j t |d|    |kW5QRXdS)    NTrr
FrIrrr) rrr1rrr$r Zassert_series_equalÚvaluesr!r%r&r')rrAÚreverseÚbaser/r0r1r2r8rr3r4r5r6rXZexp2Zexp_rev2r7rrrr9æsbÿ
 
 
 ÿz#TestCategoricalOps.test_comparisonsÚctorcOs
t||ŽS©N)r©ÚargsÚkwargsrrrÚ<lambda>.ózTestCategoricalOps.<lambda>cOstt||ŽƒSra)rrrbrrrre/rfcCs|ddgddgdd}|ddgddgdd}||k ¡s<t‚|ddgddgdd}|ddgddgdd}||k ¡sxt‚|ddgddgdd}|ddgddgdd}||k ¡s´t‚|ddgddgdd}|ddgddgdd}||k}t t |¡t ddg¡¡dS)NrrFrT)Úallr)r r!rr$)rr`Úc1Úc2r+rrrÚ$test_unordered_different_order_equal+s    z7TestCategoricalOps.test_unordered_different_order_equalc    CsRtddgddgdd}tddgddgdd}tjtdd||kW5QRXdS)NrrFrr    z!Categoricals can only be comparedr©rr%r&r')rrhrirrrÚ*test_unordered_different_categories_raisesEsz=TestCategoricalOps.test_unordered_different_categories_raisesc    CsHtgddgd}tgdgd}d}tjt|d||kW5QRXdS)Nrrrz?Categoricals can only be compared if 'categories' are the same.rrk)rrhrir7rrrÚtest_compare_different_lengthsLs
z1TestCategoricalOps.test_compare_different_lengthscCs6tdgddgd}tdgddgd}| |¡r2t‚dS)Nrrr)rÚequalsr))rrrrrrÚ&test_compare_unordered_different_orderTsz9TestCategoricalOps.test_compare_unordered_different_orderc
Csötdtj ddd¡iƒ}dd„tdddƒDƒ}t||ƒ}|jdgdd    }tj|j    tdd
dƒd |d |d <dD]<\}}d|›d}t
j t |dt ||ƒ|ƒW5QRXql|d }dD]:}d|›d}t
j t |dt ||ƒd dW5QRXq¶dS)NÚvalueri'édcSsg|]}|›d|d›‘qS)z - iór)Ú.0ÚirrrÚ
<listcomp>]sz<TestCategoricalOps.test_numeric_like_ops.<locals>.<listcomp>iôT)ZbyZ    ascendingi)F)ÚrightÚlabelsZ value_group)©Ú__add__z\+©Ú__sub__ú-©Ú__mul__z\*©Ú __truediv__ú/ú$Series cannot perform the operation ú|unsupported operandr)ZkurtZskewÚvarZstdZmeanÚsumZmedianzdoes not support reduction 'ú')Z numeric_only)rrr ÚrandintÚrangerZ sort_valuesÚpdZcutrpr%r&r'rV)rrBrvZ
cat_labelsrEÚstr_repr7r8rrrÚtest_numeric_like_ops[s&
 
ÿ
   z(TestCategoricalOps.test_numeric_like_opsc    Cs<ttddddgƒƒ}tjtddt |¡W5QRXdS)NrIr>rGrKz does not support reduction 'sum'r)rrr%r&r'rr„)rr8rrrÚtest_numeric_like_ops_seriesxsz/TestCategoricalOps.test_numeric_like_ops_seriesz op, str_reprwryr|r~c    CsLttddddgƒƒ}d|›d}tjt|dt||ƒdƒW5QRXdS)NrIr>rGrKrr‚r)rrr%r&r'rV)rrEr‰r8r7rrrÚ"test_numeric_like_ops_series_arith~s  z5TestCategoricalOps.test_numeric_like_ops_series_arithc    Cs@ttddddgƒƒ}d}tjt|dt |¡W5QRXdS)NrIr>rGrKz:Object with dtype category cannot perform the numpy op logr)rrr%r&r'rÚlog)rr8r7rrrÚ$test_numeric_like_ops_series_invalidŽsz7TestCategoricalOps.test_numeric_like_ops_series_invalidN)r:r;r<rCrFrHrJrLrNrZr[r%ÚmarkZ parametrizer*r9rjrlrmrorŠr‹rŒrŽrrrrr=‚sF    0þ
Aþþ
üþ    
r=)rRÚnumpyrr%ZpandasrˆrrrrZpandas._testingZ_testingr rr=rrrrÚ<module>s r