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
U
­ý°dU3ã@s¦ddlmZddlmZddlZddlZddlmZm    Z    m
Z
m Z m Z m Z mZmZddlmZGdd„dƒZdd„Zd    d
„Zd d „Zd d„Zdd„Zdd„Zdd„ZdS)é)Úproduct)Úascii_lowercaseN)Ú    DataFrameÚIndexÚ
MultiIndexÚPeriodÚSeriesÚ    TimedeltaÚ    TimestampÚ
date_rangec @seZdZdd„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"„Zej d#d$d%„ed&d'ƒDƒd(d%„ed&d'ƒDƒd)d%„ed&d'ƒDƒd*d%„ed&d'ƒDƒd+d%„ed&d'ƒDƒg¡d,d-„ƒZd.d/„Zd0d1„Zd2d3„Zd4S)5Ú TestCountingcCshtdgdgdgdgdggdgd}| d¡}|j}tdddddgƒ}t || ¡¡t || ¡¡dS)    NÚaÚbÚA©Úcolumnsrééé©rÚgroupbyrrÚtmÚassert_series_equalÚcumcount©ÚselfÚdfÚgÚsgÚexpected©r úYd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/groupby/test_counting.pyÚ test_cumcounts "
zTestCounting.test_cumcountcCsNtƒjdd}ttdjdd}tdd}t || ¡¡t || ¡¡dS©Nr)Úlevel©ÚdtypeÚint64)rrrÚobjectrrr©rÚgeÚseÚer r r!Útest_cumcount_emptys
 
z TestCounting.test_cumcount_emptycCsztdgdgdgdgdggdgdgdd}| d¡}|j}tddddd    gdgdd
}t || ¡¡t || ¡¡dS© Nr rrré©rÚindexrrr©r1rrr r r!Útest_cumcount_dupe_index)sÿ
z%TestCounting.test_cumcount_dupe_indexcCs–t ddgddgddgddgddgg¡}tdgdgdgdgdggdg|d}| d¡}|j}tdddddg|d    }t || ¡¡t || ¡¡dS)
Nrrrr rrr0rr2)    rÚ from_tuplesrrrrrrr©rÚmirrrrr r r!Útest_cumcount_mi5s($
zTestCounting.test_cumcount_micCs„tdgdgdgdgdggdgdgdd}| dddddg¡}|j}tddddd    gdgdd
}t || ¡¡t || ¡¡dSr.rrr r r!Útest_cumcount_groupby_not_col@sÿz*TestCounting.test_cumcount_groupby_not_colcCsVtdtdƒiƒ}| d¡}|j}tdddddgƒ}t || ¡¡t || ¡¡dS)NrÚaaabarr©rÚlistrrrrrÚngrouprr r r!Ú test_ngroupLs 
zTestCounting.test_ngroupcCsTtdtdƒiƒ}| d¡}|j}ttdƒdd}t || ¡¡t || ¡¡dS)NrZabcder/r'r%)    rr;rrrÚrangerrr<rr r r!Útest_ngroup_distinctVs 
z!TestCounting.test_ngroup_distinctcCsTtddgdiƒ}| d¡}|j}tdgdƒ}t || ¡¡t || ¡¡dS)Nrrr/)rrrrrrr<rr r r!Útest_ngroup_one_group`s 
z"TestCounting.test_ngroup_one_groupcCsNtƒjdd}ttdjdd}tdd}t || ¡¡t || ¡¡dSr#)rrrr(rrr<r)r r r!Útest_ngroup_emptyjs
 
zTestCounting.test_ngroup_emptycCs@tdtdƒiƒ}ttdƒƒ}t | |¡ ¡| |¡ ¡¡dS)Nrr9)rr;rrrrr<)rrÚsr r r!Ú test_ngroup_series_matches_framets z-TestCounting.test_ngroup_series_matches_framecCsjtdtdƒidgdd}| d¡}|j}tdddddgdgdd}t || ¡¡t || ¡¡dS©Nrr9rr/r2rr:rr r r!Útest_ngroup_dupe_indexzs 
z#TestCounting.test_ngroup_dupe_indexcCs†t ddgddgddgddgddgg¡}tdtdƒi|d}| d¡}|j}tdddddg|d}t ||     ¡¡t ||     ¡¡dS)Nrrrrr9r2)
rr4rr;rrrrrr<r5r r r!Útest_ngroup_mi„s(
zTestCounting.test_ngroup_micCsttdtdƒidgdd}| dddddg¡}|j}tdddddgdgdd}t || ¡¡t || ¡¡dSrDr:rr r r!Útest_ngroup_groupby_not_colŽs z(TestCounting.test_ngroup_groupby_not_colcCsŠtdddddgdgd}| dg¡}tdddddgƒ}tdddddgƒ}t ||jd|¡t ||jdd¡t ||jd    d¡dS)
Nr rrrrrT)Ú    ascendingF)rrrrrZngroupsr<)rrrrHZ
descendingr r r!Útest_ngroup_descending˜s z#TestCounting.test_ngroup_descendingcCsŒtddgddgddgddgddggddgd}| ddg¡}| ¡}| ¡}tdd    d
dd gƒ}tdddd    dgƒ}t ||¡t ||¡dS) Nr ÚxÚyrrÚXrrrrr)rrr<rrrr)rrrZg_ngroupZ
g_cumcountZexpected_ngroupZexpected_cumcountr r r!Útest_ngroup_matches_cumcount£s þ z)TestCounting.test_ngroup_matches_cumcountcsŽttdƒddD]x‰tdˆiƒ}| dg¡}ttˆƒƒ‰‡fdd„ˆDƒ}‡fdd„tˆƒDƒ}t |     ¡t
|ƒ¡t |  ¡t
|ƒ¡qdS)Nré)Úrepeatr csg|]}ˆ |¡‘qSr r2)Ú.0Úval)Úorderr r!Ú
<listcomp>¹sz:TestCounting.test_ngroup_cumcount_pair.<locals>.<listcomp>cs"g|]\}}ˆd|… |¡‘qS©N)Úcount)rPÚirQ)Úpr r!rSºs) rr>rrÚsortedÚsetÚ    enumeraterrr<rr)rrrZngroupdZ
cumcountedr )rRrWr!Útest_ngroup_cumcount_pair²s   z&TestCounting.test_ngroup_cumcount_pairc    CsÄtj d¡tdtj tdƒd¡iƒ}|jd|d}d|d<d|d<t|ƒD]>\}\}}||j|j    df<t|j    ƒD]\}}||j|df<qrqLt
  t |dj ƒ| ¡¡t
  t |dj ƒ| ¡¡dS)    Nrr Zabcdeféd)ÚsortéÿÿÿÿZgroup_idZ group_index)ÚnpÚrandomÚseedrÚchoicer;rrZÚlocr1rrrÚvaluesr<r)    rr]rrrVÚ_ÚgroupÚjÚindr r r!Ú"test_ngroup_respects_groupby_order¿s z/TestCounting.test_ngroup_respects_groupby_orderÚ datetimelikecCsg|]}td|d›dƒ‘qS)ú2016-05-Ú02dz 20:09:25+00:00©r
©rPrVr r r!rSÑszTestCounting.<listcomp>rrNcCsg|]}td|d›dƒ‘qS)rkrlú     20:09:25rmrnr r r!rSÒscCs"g|]}td|d›ddd‘qS)rkrlroÚUTC)Útzrmrnr r r!rSÓscCsg|]}t|dd‘qS)Úh)Úunit)r    ©rPrJr r r!rSÔscCsg|]}tdd|d‘qS)Z2Wiá)ÚfreqÚyearÚmonth)rrtr r r!rSÕscCsRtdddg|dœƒ}| d¡ ¡}tdddgiddgd}d|j_t ||¡dS)    Nr r)rJrKrJrKrrr2)rrrUr1ÚnamerÚassert_frame_equal)rrjrÚresrr r r!Útest_count_with_datetimelikeÎs
z)TestCounting.test_count_with_datetimelikecCsxttjtjgddgddgdœƒ}| ddg¡j ¡}tgddgggggddgd}tg|tjd    d
}t    j
||d d dS) Nr rrr)rÚBÚCrr|)ÚlevelsÚcodesÚnamesr})r1r&rxF)Zcheck_index_type) rr_Únanrr}rUrrr'rr)rrÚresultr6rr r r!Ú(test_count_with_only_nans_in_first_groupâs
 z5TestCounting.test_count_with_only_nans_in_first_groupcCsltdddddgddtjddgdœƒ}| dg¡ ¡}ttdd    d
d gdd d ddddgid}t ||¡dS)Nrr/rNrr)rr|r|gg@g@g@©rxr)r1Údata)rr_ÚNaNrrUrrry)rrrzrr r r!Ú4test_count_groupby_column_with_nan_in_groupby_columnês$ÿzATestCounting.test_count_groupby_column_with_nan_in_groupby_columncCs‚tdddd}tt d¡|t d¡gd}| dd„¡}| ¡}tt d¡t d¡|gd}| dd„¡}| ¡}t ||¡dS)    Nz1/1/2012Z5miné
)ÚstartruÚperiodsr2cSs|dddkS)Nrrrr ©rJr r r!Ú<lambda>øóz@TestCounting.test_groupby_count_dateparseerror.<locals>.<lambda>cSs|dddkS)Nrrr r‹r r r!rŒür)r rr_ÚarangerrUrr)rÚdrZserZgroupedr‚rr r r!Ú!test_groupby_count_dateparseerrorósz.TestCounting.test_groupby_count_dateparseerrorN)Ú__name__Ú
__module__Ú __qualname__r"r-r3r7r8r=r?r@rArCrErFrGrIrMr[riÚpytestÚmarkZ parametrizer>r{rƒr‡rr r r r!r s<
 
 
 
 
 
 
 
 
  ûþ
 
 
    r cCs\ttdƒt d¡ d¡dœƒ}tddgtddgdd    d
d }| d¡j     ¡}t
  ||¡dS) NÚababrNztimedelta64[ns])rÚdeltrr rrr„r—©r1rx) rr;r_rŽÚastyperrrr—rUrr)rrr‚r r r!Ú#test_groupby_timedelta_cython_counts ÿršc CsJd}td|ddd}ttj ttƒ|¡tj dd|¡tj |¡     d¡tj d    d|¡tj ||¡tj |¡     d¡tj |¡     d¡tj ||¡tj |d
¡tj ttƒ|¡d œ    ƒ}|j
  d d dg¡D]"}tj |j tj ||d¡|f<qÄ|d d¡|d<d d d d gfD]<}| |¡ ¡}| |¡ tj¡j |d
d}t ||¡qdS)Ni€z
2015-08-30rˆÚT)rŠrurr/riöÿÿÿr)    Ú1stÚ2ndZ3rdÚ4thZ5thZ6thZ7thZ8thÚ9thrœrržrŸÚcategory)Zaxis)r rr_r`rbr;rÚrandintZrandnÚroundrZdroprrcr™rrUÚapplyrry)ÚnrrÚcolÚkeyÚleftÚrightr r r!Ú
test_count s* ÷ÿ r©cCs¼tdddgdtjdgdtjtjggdddgd    }| d¡ ¡}|jdd
d  ¡}tddgd d ggddgddgd }d|j_t ||     ¡¡t ||¡| d¡d ¡}t 
||d¡dS)NrrZfooÚbarrrr|r}rF)Zas_indexrr0) rr_rrrUr1rxrryZ reset_indexr)rZcount_asZ count_not_asrZcount_Br r r!Útest_count_non_nulls(s þ" r«cCsØtdgddgddgddgddœƒ}| d¡j ¡}tddgtddgdddd}t ||¡tdtj    tj    gdgddgddgddœƒ}| d¡j ¡}td    dgtddgdddd}t ||¡dS)
Nr rrr)r Úcr¬r„r˜r)
rrr rUrrrrr_r©rr‚rr r r!Útest_count_object<s. 2r®cCsªt tj ddd¡tj ddd¡f¡}t|ddddgd    }tj||dk<| ddg¡ ¡}d
D]F}|d |¡|d<|d |¡|d<| ddg¡ ¡}t     
||¡q^dS) Nrr/)r\rrr rr¬Údr)Úfloat32r() r_Zhstackr`r¡rrrrUr™rry)ÚvalsrrÚtr‚r r r!Útest_count_cross_typeHsÿr³c    Cs–tt ddddgtj¡t ddddgtj¡t dddd    gtj¡td
ƒd œƒ}| d ¡ ¡}tddgddgddgd œt    tdƒd dd}t
  ||¡dS)Nrrrr\rérNr/ér–)r rr¬Úgrpr¶)r rr¬Úabr„r2) rr_ÚarrayZint8Zuint32Úint16r;rrUrrryr­r r r!Útest_lower_int_prec_countYsüÿÿrºcs„Gdd„dtƒ‰G‡fdd„dƒ‰t‡fdd„tdƒDƒtdƒd    œƒ}| d
¡ ¡}td d d gittd ƒd
dd}t ||¡dS)Nc@s eZdZdS)zAtest_count_uses_size_on_exception.<locals>.RaisingObjectExceptionN)r‘r’r“r r r r!ÚRaisingObjectExceptionjsr»cs0eZdZdddœ‡fdd„ Z‡fdd„Z‡ZS)    z8test_count_uses_size_on_exception.<locals>.RaisingObjectúI will raise inside CythonN)Úreturncstƒ ¡||_dSrT)ÚsuperÚ__init__Úmsg)rrÀ©Ú    __class__r r!r¿ns
zAtest_count_uses_size_on_exception.<locals>.RaisingObject.__init__csˆ|jƒ‚dSrT)rÀ)rÚother©r»r r!Ú__eq__rsz?test_count_uses_size_on_exception.<locals>.RaisingObject.__eq__)r¼)r‘r’r“r¿rÅÚ __classcell__r rÄrÁr!Ú RaisingObjectmsrÇcsg|]
}ˆƒ‘qSr r )rPre)rÇr r!rSvsz5test_count_uses_size_on_exception.<locals>.<listcomp>rNr–)r r¶r¶r rr·r„r2)    Ú    Exceptionrr>r;rrUrrryr­r )rÇr»r!Ú!test_count_uses_size_on_exceptionis     $ rÉ)Ú    itertoolsrÚstringrÚnumpyr_r”Zpandasrrrrrr    r
r Zpandas._testingZ_testingrr ršr©r«r®r³rºrÉr r r r!Ú<module>s  (
o