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
U
®ý°d#?ã@sžddlZddlZddlZddlmZmZmZmZm    Z    ddl
m Z ddl mZejeddgddgddgddggddgd    eddgddgddgddggddgd    eddgddgddgddggd
d
gd    eddgddgddgddggd dgd    eddgddgddgddggd dgd    eddgddgddgddggd
dgd    ed dgd d gdd gdd ggdd gd    eddgdd gdd gdd ggdd gd    eddgddgddgdd ggd dgd    g    ddd„ƒZejdd„ƒZejdd„ƒZdd„Zdd„Zej dddg¡d d!„ƒZej d"ddg¡d#d$„ƒZej d%ed&ƒ¡d'd(„ƒZd)d*„Zd+d,„Zd-d.„Zej d/d0d1„d2d1„g¡d3d4„ƒZej d/d5d1„d6d1„g¡d7d8„ƒZGd9d:„d:ƒZ dS);éN)Ú    DataFrameÚIndexÚ
MultiIndexÚSeriesÚ
date_range)Ú    safe_sortééééé©ÚcolumnsÚCçð?gç@g@g@g @ÚX)ÚparamscCs|jS)zPairwise frames test_pairwise)Úparam)Úrequest©rúXd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/window/test_pairwise.pyÚpairwise_framessrcCs(tddgddgddgddggddgdS)z'Pairwise target frame for test_pairwiserr    r
r r rr ©rrrrrÚpairwise_target_frame#srcCs2tdddgdddgdddgdddggdddgd    S)
z&Pairwise other frame for test_pairwiseNr
rér ÚYÚZrr rrrrrÚpairwise_other_frame)s"þrc    Cs\|}|tj t|ƒ¡}|jddd |¡}t |dt |dd…|dd…¡d¡dS)Né2é©ÚwindowZ min_periodséÿÿÿÿéÎÿÿÿ©rr
)ÚnpÚrandomÚrandnÚlenÚrollingÚcovÚtmÚassert_almost_equal)ÚseriesÚAÚBÚresultrrrÚtest_rolling_cov2sr2c    Cs¶|}|tj t|ƒ¡}|jddd |¡}t |dt |dd…|dd…¡d¡t     ¡}t     ¡}tj
|dd…<tj
|dd…<|jt|ƒd    d |¡}t |d| |¡¡dS)
Nrr r!r#r$r%r é
r
) r&r'r(r)r*Úcorrr,r-ZcorrcoefZmakeTimeSeriesÚnan)r.r/r0r1ÚaÚbrrrÚtest_rolling_corr:s,r8Úfuncr+r4cCsnt|jddd|ƒƒ}|jtdƒdfdf}|j d¡|_t|djddd|ƒ|dƒ}tj||dddS)Nr3r r!r
F©Z check_names)Úgetattrr*ÚlocÚsliceÚindexZ    droplevelr,Úassert_series_equal)r9Úframer1ÚexpectedrrrÚtest_rolling_pairwise_cov_corrKs
 rBÚmethodcsĈd‰tˆjddˆƒˆƒ}tˆjddˆƒˆƒ}ˆ ‡‡fdd„¡}t ||¡t ||¡ˆ ¡‰ttjj    ˆj
Žˆj ˆj d‰tˆjddˆƒˆƒ}t‡‡‡fdd„ˆDƒƒ}t ||¡dS)    Nr
r3©r"cstˆjddˆƒ|ƒS)Nr3rD©r;r*©Úx)rCr.rrÚ<lambda>Zóz(test_flex_binary_frame.<locals>.<lambda>©r>rcs,i|]$}|tˆ|jddˆƒˆ|ƒ“qS)r3rDrE)Ú.0Úk)r@Úframe2rCrrÚ
<dictcomp>fsz*test_flex_binary_frame.<locals>.<dictcomp>) r;r*Úapplyr,Úassert_frame_equalÚcopyrr&r'r(Úshaper>r)rCr@ÚresZres2ÚexpZres3r)r@rMrCr.rÚtest_flex_binary_frameTs"   ÿÿrUr"écCs@tt d¡ƒ}tt d¡ƒ}|j|dj|d ¡ ¡s<t‚dS)NérD)Úother)    rr&ÚzerosÚaranger*r4ZisnaÚallÚAssertionError)r"ÚsrXrrrÚ$test_rolling_corr_with_zero_varianceksr^c
Cs¬tt ddgddgddgddgd    d
gd d gg¡ƒ}|d jddd |d¡}tdd„|Dƒƒsdt‚ttj dd¡ƒ}|d jddd |d¡}tdd„|Dƒƒs¨t‚dS)Ng†F$ÈÙë?g)—Òé¯Ç?g‰ËT5ÿ—ä?g´?«'NÉÓ?gFr1í?g+ÿ”    C-à?gR    ²±`?gÕ1:b%§?g9T!X4!ë?gXÀÊÂS_Õ?gS®=é?g\–+“Ltä?rr T)Úcenterr
css"|]}t t |¡¡dkVqdS©r
N©r&ÚabsZ
nan_to_num©rKrGrrrÚ    <genexpr>„sz#test_corr_sanity.<locals>.<genexpr>ércss"|]}t t |¡¡dkVqdSr`rarcrrrrdˆs)    rr&Úarrayr*r4r[r\r'Zrand)ÚdfrSrrrÚtest_corr_sanityts úÿÿ rhcCs–tdddgdddgd}tddgddgd}|jddd |¡}tdddgƒ}t ||¡tdddgdddgd}|jddd |¡}t ||¡dS)Nr
rrr©r>r!r)rr*r+r,r?©Ús1Ús2r1rAZs2arrrÚtest_rolling_cov_diff_length‹s rmcCs–tdddgdddgd}tddgddgd}|jddd |¡}tdddgƒ}t ||¡tdddgdddgd}|jddd |¡}t ||¡dS)Nr
rrrrir!r)rr*r4r,r?rjrrrÚtest_rolling_corr_diff_length˜s rnÚfcCs|jdddj|ddS©Nr3r r!T©Úpairwise©r*r+rFrrrrH¨rIrHcCs|jdddj|ddSrp©r*r4rFrrrrH©rIcCs†tddgddgddgddggtdd    gd
d ttd ƒd d d}ttdd    gd
d tj|j|jgd d
gddd}||ƒ}t ||¡dS)Nr
r rré    r#rr/r0Úfoo©Únamer    Úbar©rr>©ÚnamesÚfloat64)rr>Údtype)    rrÚrangerÚ from_productr>rr,rP)rorgZ df_expectedZ    df_resultrrrÚ2test_rolling_functions_window_non_shrinkage_binary¥s    ýýrcCs|jdddj|ddSrprsrFrrrrH¿rIcCs|jdddj|ddSrprtrFrrrrHÀrIcCs¨tƒ}ttdgddtgddd}|d d¡|d<tt |j|jg¡d}ttj|j|jgddgdtdgdddd    }||ƒ}t ||¡||ƒ}t ||¡dS)
Nr6rvrwryrzr}rir{)r>rr~)    rrZastyperr€r>rr,rP)roZdf1Zdf2Z df1_expectedZ df2_expectedZ
df1_resultZ
df2_resultrrrÚ*test_moment_functions_zero_length_pairwise¼s ý r‚c
@sheZdZej ddd„dd„g¡dd„ƒZej ddd„dd„d    d„d
d„d d„d d„g¡d d„ƒZej ddd„dd„dd„dd„dd„dd„g¡dd„ƒZej ddd„dd„dd„dd„dd„dd„g¡dd„ƒZ    ej ddd„d d„d!d„d"d„d#d„d$d„g¡d%d&„ƒZ
ej dd'd„d(d„d)d„d*d„d+d„d,d„g¡d-d.„ƒZ d/d0„Z d1d2„Z d3d4„Zd5S)6Ú TestPairwiserocCs| ¡S©N)r+rFrrrrHØrIzTestPairwise.<lambda>cCs| ¡Sr„)r4rFrrrrHØrIcCsX||ƒ}t |j|j¡t |j|j¡||ƒ}| ¡j}| ¡j}tj||dddS©NF©Z check_dtype©r,Úassert_index_equalr>rÚdropnaÚvaluesÚassert_numpy_array_equal©Úselfrrror1rArrrÚ test_no_flexØs
 
zTestPairwise.test_no_flexcCs| ¡jddS©NTrq©Ú    expandingr+rFrrrrHêrIcCs| ¡jddSr©r‘r4rFrrrrHërIcCs|jddjddS©NrrDTrqrsrFrrrrHìrIcCs|jddjddSr“rtrFrrrrHírIcCs|jddjddS©Nr©ÚcomTrq©Úewmr+rFrrrrHîrIcCs|jddjddSr”©r˜r4rFrrrrHïrIcCs„||ƒ}tj|jjd|jddt t|jjdƒt|j ¡ƒ¡t |j|j¡||ƒ}| ¡j}| ¡j}tj    ||dddS©NrFr:r
r†©
r,rˆr>ÚlevelsrrÚuniquer‰rŠr‹rŒrrrÚtest_pairwise_with_selfçs
ÿ þ
 
z$TestPairwise.test_pairwise_with_selfcCs| ¡jddS©NFrqrrFrrrrH
rIcCs| ¡jddSrŸr’rFrrrrH rIcCs|jddjddS©NrrDFrqrsrFrrrrH rIcCs|jddjddSr rtrFrrrrH rIcCs|jddjddS©Nrr•Frqr—rFrrrrHrIcCs|jddjddSr¡r™rFrrrrHrIcCsX||ƒ}t |j|j¡t |j|j¡||ƒ}| ¡j}| ¡j}tj||dddSr…r‡rŒrrrÚtest_no_pairwise_with_selfs 
 
z'TestPairwise.test_no_pairwise_with_selfcCs| ¡j|ddSrr©rGÚyrrrrH"rIcCs| ¡j|ddSrr’r£rrrrH#rIcCs|jddj|ddSr“rsr£rrrrH$rIcCs|jddj|ddSr“rtr£rrrrH%rIcCs|jddj|ddSr”r—r£rrrrH&rIcCs|jddj|ddSr”r™r£rrrrH'rIcCsx|||ƒ}tj|jjd|jddt t|jjdƒt|j ¡ƒ¡|||ƒ}| ¡j}| ¡j}tj    ||dddSršr›)rrrrror1rArrrÚtest_pairwise_with_others
 
ÿ þ
 
 
z%TestPairwise.test_pairwise_with_othercCs| ¡j|ddSrŸrr£rrrrHArIcCs| ¡j|ddSrŸr’r£rrrrHBrIcCs|jddj|ddSr rsr£rrrrHCrIcCs|jddj|ddSr rtr£rrrrHDrIcCs|jddj|ddSr¡r—r£rrrrHErIcCs|jddj|ddSr¡r™r£rrrrHFrIc    CsÈ|jjr|||ƒnd}|dk    r|tjdd.t dt¡|j |j¡}|j |j¡}W5QRXt     |j|¡t     |j|¡nHt
j t dd|||ƒW5QRXt
j t dd|||ƒW5QRXdS)NT)ÚrecordÚignorez'arg1' columns are not unique)Úmatchz'arg2' columns are not unique) rZ    is_uniqueÚwarningsÚcatch_warningsÚ simplefilterÚRuntimeWarningr>Úunionr,rˆÚpytestZraisesÚ
ValueError)rrrror1Zexpected_indexZexpected_columnsrrrÚtest_no_pairwise_with_other>s"ÿ ý ÿz(TestPairwise.test_no_pairwise_with_othercCs| ¡ |¡Sr„rr£rrrrHcrIcCs| ¡ |¡Sr„r’r£rrrrHdrIcCs|jdd |¡S©NrrDrsr£rrrrHerIcCs|jdd |¡Sr±rtr£rrrrHfrIcCs|jdd |¡S©Nrr•r—r£rrrrHgrIcCs|jdd |¡Sr²r™r£rrrrHhrIcCsä||tddddgƒƒ}t |j|j¡t |j|j¡||tddddgƒƒ}| ¡j}| ¡j}tj||dd|tddddgƒ|ƒ}t |j|j¡t |j|j¡|tddddgƒ|ƒ}| ¡j}| ¡j}tj||dddS)Nr
rr Fr†)rr,rˆr>rr‰rŠr‹rŒrrrÚtest_pairwise_with_series`s 
 
 
 
z&TestPairwise.test_pairwise_with_seriescCsTttdƒtdddd}| d¡ |¡}ttjgdtdddd}t ||¡dS)Nr Z2020)ZperiodsriZ12H)    rrrr*r4r&r5r,r?)rr]r1rArrrÚtest_corr_freq_memory_errorsz(TestPairwise.test_corr_freq_memory_errorc    CsÒt tdƒtdƒtdƒg¡}tdƒ}tt d¡ dd¡||d}|jdd         ¡}t tdƒtdƒtdƒtdƒg¡}t tdƒtdƒtdƒg¡}tt 
t  d
tj ¡t  d
d ¡t  d
d ¡f¡||d}t  ||¡dS) NÚabZxyZABrér rJgš™™™™™¹?)Úalpha)r r g@@gK\ǸâðO@)rr€Úlistrrr&rZZreshaper˜r+ZvstackÚfullÚNaNr,rP)rrr>rgr1rArrrÚtest_cov_mulittindexˆs"" 
 
ýÿ÷ z!TestPairwise.test_cov_mulittindexc    Cs˜tjddgddggddgd}tt d¡|d    }| d
¡ ¡}ttjtjt tj    d tj
d d ¡ddgd ddgd gdddgd|d}t   ||¡dS)NÚMÚNÚPÚQr6r7r{)r rr rr )r~rrJ) rZ from_arraysrr&Zonesr*r4r5ÚrepeatrZÚint64r,rP)rrrgr1rArrrÚ$test_multindex_columns_pairwise_func¡s
 
ýúö z1TestPairwise.test_multindex_columns_pairwise_funcN)Ú__name__Ú
__module__Ú __qualname__r®ÚmarkÚ parametrizerŽržr¢r¥r°r³r´r»rÂrrrrrƒÖsx
úþ
úþ
úþ
úþ
úþ
rƒ)!r©Únumpyr&r®ZpandasrrrrrZpandas._testingZ_testingr,Zpandas.core.algorithmsrZfixturerrrr2r8rÆrÇrBrUrr^rhrmrnrr‚rƒrrrrÚ<module>s`  &&&&&&&&&÷ÿ
 
 
 
 
 
  þþ
þþ