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
U
®ý°d!ã @sšdZddlmZddlZddlZddlZddlmZddl    m
Z ddddd    d
d d d ddddg Z ej dd„ƒZej e ddd„ƒZdd„ZGdd„dƒZdS)z
Note: for naming purposes, most tests are title with as e.g. "test_nlargest_foo"
but are implicitly also testing nsmallest_foo.
é)ÚproductN)ÚSeriesÚdatetimeÚ
datetimetzÚ    timedeltaÚint8Úint16Úint32Úint64Úfloat32Úfloat64Úuint8Úuint16Úuint32Úuint64c Cspt t dddddg¡t dddddg¡ d¡t ddddd    g¡d
œ¡}d D]}td d dd dg|d||<qL|S)z¯
    A DataFrame with many dtypes
 
    * datetime
    * datetimetz
    * timedelta
    * [u]int{8,16,32,64}
    * float{32,64}
 
    The columns are the name of the dtype.
    Z2003Z2002Z2001Z2005z
US/EasternZ3dZ2dZ1dZ5d)rrr)
rrr    r
r r r rrréééé©Údtype)ÚpdZ    DataFrameÚ to_datetimeZ tz_localizeZ to_timedeltar)Zdfr©rú`d:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/series/methods/test_nlargest.pyÚ s_main_dtypess  ÿþûÿ
 r)ÚparamscCs
||jS)zEach series in s_main_dtypes.)Úparam)ÚrequestrrrrÚs_main_dtypes_splitGsrcCsPt||d}t||ƒdƒ}|dkr,dddgndddg}|j|}t ||¡dS)NrrÚ    nsmallestrrr)rÚgetattrÚlocÚtmÚassert_series_equal)ÚvalsrÚmethodÚserÚresultZ expected_idxrÚexpectedrrrÚassert_check_nselect_boundaryMs
 
r*c @seZdZej dedddddgddedddddgddedddddgd    deed
ƒƒeed
ƒd dg¡d d „ƒZdd„Z    dd„Z
ej de ddƒ¡dd„ƒZ dd„Z dd„Zej dddg¡dd„ƒZdd„Zej d d!d"gd!gfd!d"d!d!gd!gfg¡d#d$„ƒZd%d&„Zd'd(„Zd)S)*ÚTestSeriesNLargestNSmallestÚrç@rrÚ5ÚobjectrrZ
complex128ZabcdeÚcategoryc
Csf|j}d|›}dt|ƒddf}|j|jf}t||ƒD]*\}}tjt|d||ƒW5QRXq6dS)Nz3Cannot use method 'n(largest|smallest)' with dtype rréÿÿÿÿ©Úmatch)rÚlenÚnlargestr rÚpytestÚraisesÚ    TypeError)Úselfr,ÚdtÚmsgÚargsÚmethodsr&ÚargrrrÚtest_nlargest_errorWs 
 z/TestSeriesNLargestNSmallest.test_nlargest_errorc    Cs"|}t | d¡|jddg¡t |jddd|jddg¡|jdd…}t | d¡|¡t | d¡|¡t | d¡|¡t | d¡|¡t | t|ƒ¡| ¡¡t | t|ƒd¡| ¡¡t | t|ƒ¡|jdddddg¡t | t|ƒd¡|jdddddg¡dS)    NrrÚlast©Zkeeprrr1é)r#r$r Úilocr5r4Ú sort_values)r9rr'ÚemptyrrrÚtest_nsmallest_nlargestls &z3TestSeriesNLargestNSmallest.test_nsmallest_nlargestc    Csdtdtjdddgƒ}| ¡}|jdddddg}t ||¡| ¡}|jdddddg}t ||¡d}tj    t
|d    |jd
d W5QRXtj    t
|d    |jd
d W5QRXtdgddddddgd }tdgddddgd }tdgddddgd }| d¡}t ||¡|jdd d }t ||¡| d¡}t ||¡|jdd d }t ||¡dS)Nr-rrrrBrrz#keep must be either "first", "last"r2ÚinvalidrA©Úindexr@) rÚnpÚnanr5rCr#r$r r6r7Ú
ValueError)r9r'r(r)r;Zexpected_firstZ expected_lastrrrÚtest_nlargest_miscs.  
 
 z.TestSeriesNLargestNSmallest.test_nlargest_miscÚncCsltddddgddddgd}| |¡}|jdd |¡}t ||¡| |¡}| ¡ |¡}t ||¡dS)    NrrBrrrrHF)Z    ascending)rr5rDÚheadr#r$r )r9rNr'r(r)rrrÚtest_nlargest_nŸs
 
z+TestSeriesNLargestNSmallest.test_nlargest_ncCs<t |¡}|j|j}}||d|d|g}t|||ƒdS©Nr©rJZiinfoÚminÚmaxr*)r9Únselect_methodZany_int_numpy_dtypeÚ
dtype_infoÚmin_valÚmax_valr%rrrÚtest_nlargest_boundary_integer«s
z:TestSeriesNLargestNSmallest.test_nlargest_boundary_integerc    CsLt |¡}|j|j}}tj||gd|d\}}||||g}t|||ƒdS)Nrr)rJZfinforSrTZ    nextafterr*)    r9rUZfloat_numpy_dtyperVrWrXZmin_2ndZmax_2ndr%rrrÚtest_nlargest_boundary_float²s
 
 z8TestSeriesNLargestNSmallest.test_nlargest_boundary_floatrzdatetime64[ns]ztimedelta64[ns]cCsBt d¡}|j|j}}|d|d|d||g}t|||ƒdS)Nr
rrrR)r9rUrrVrWrXr%rrrÚ#test_nlargest_boundary_datetimelikeºs
z?TestSeriesNLargestNSmallest.test_nlargest_boundary_datetimelikec    Cs†tddddddddgƒ}|jddd}tdddddddgƒ}t ||¡|jd    dd}tdddddgdd
dd dgd }t ||¡dS) Né
é    ééérBÚallrArrrrH)rr5r#r$r )r9r'r(r)rrrÚ%test_nlargest_duplicate_keep_all_tiesÄs  zATestSeriesNLargestNSmallest.test_nlargest_duplicate_keep_all_tiesz data,expectedTFcCs*t|ƒ}| d¡}t|ƒ}t ||¡dSrQ)rr5r#r$)r9Údatar)r'r(rrrÚtest_nlargest_booleanÏs
z1TestSeriesNLargestNSmallest.test_nlargest_booleancCsz|}tj d¡j| ¡dd}t| ¡|d}tj|d<|     d¡}tt 
|d¡|j  
d¡d     d¡ |¡}t   ||¡dS)Nr\F)ÚcopyrrrrH)rJÚrandomZrandnZastypeÚlowerrrerZNAr5ÚdeleterIr#r$)r9Zany_numeric_ea_dtyperZarrr'r(r)rrrÚtest_nlargest_nullableÙs
 
ÿþÿz2TestSeriesNLargestNSmallest.test_nlargest_nullablecCs‚tddddddgƒ}|jddd}tdddddgƒ}t ||¡tdddddgƒ}|jddd}tdddddgƒ}t ||¡dS)    NrrrrarAgð?g@r-)rr r#r$)r9Úsr(r)rrrÚ#test_nsmallest_nan_when_keep_is_allés z?TestSeriesNLargestNSmallest.test_nsmallest_nan_when_keep_is_allN)Ú__name__Ú
__module__Ú __qualname__r6ÚmarkZ parametrizerÚlistr?rFrMÚrangerPrYrZr[rbrdrirkrrrrr+Vs4
ùþ
     
 
     ÿ
r+)Ú__doc__Ú    itertoolsrÚnumpyrJr6ZpandasrrZpandas._testingZ_testingr#Z main_dtypesZfixturerrr*r+rrrrÚ<module>s4   ó
'