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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
U
­ý°džBã@spdZddlZddlZddlmZddlZddlmZddl    m
Z ddl m Z ddlmZdd„Zejd    d
„ƒZejdejgd d d „ƒZejdd„ƒZejdejgd dd„ƒZejdejgd dd„ƒZejdejgd dd„ƒZejdejgd dd„ƒZejdd„ƒZejdd„ƒZejdejgd dd„ƒZejdejgd dd„ƒZGd d!„d!ƒZGd"d#„d#eejƒZ Gd$d%„d%eej!ƒZ"Gd&d'„d'eej#ƒZ$Gd(d)„d)eej%ƒZ&Gd*d+„d+eej'ƒZ(Gd,d-„d-ej)ƒZ*Gd.d/„d/eej+ƒZ,Gd0d1„d1eej-ƒZ.Gd2d3„d3eej/ƒZ0Gd4d5„d5eej1ƒZ2Gd6d7„d7eƒZ3Gd8d9„d9eej4ƒZ5Gd:d;„d;eej6ƒZ7Gd<d=„d=ej8ƒZ9dS)>aj
This file contains a minimal set of tests for compliance with the extension
array interface test suite, and should contain no other tests.
The test suite for the full functionality of the array is located in
`pandas/tests/arrays/`.
 
The tests in this file are inherited from the BaseExtensionTests, and only
minimal tweaks should be applied to get the tests passing (by overwriting a
parent method).
 
Additional tests should either be added to one of the BaseExtensionTests
classes (if they are relevant for the extension interface for all dtypes), or
be added to the array-specific tests in `pandas/tests/arrays/`.
 
éN)ÚPerformanceWarning©Ú SparseDtype)Ú SparseArray)ÚbasecCs^t |¡rtjjdd}n2tjjdddd}|d|dkrL|dd7<||ddd…<|S)Néd)Úsizeéréé)ÚnpÚisnanÚrandomÚuniformÚrandint)Ú
fill_valueÚdata©rúYd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/extension/test_sparse.pyÚ    make_datas
rcCstƒS©NrrrrrÚdtype)sr)ÚparamscCstt|jƒ|jd}|S)z*Length-100 PeriodArray for semantics test.©r)rrÚparam)ÚrequestÚresrrrr.srcCstt d¡dƒS)Nrr
)rr ZonesrrrrÚ data_for_twos5srcCsttjdg|jdS)zLength 2 array with [NA, Valid]r    r©rr Únanr©rrrrÚ data_missing:sr!c#s‡fdd„}|VdS)z1Return different versions of data for count timesc3s(t|ƒD]}ttˆjƒˆjdVqdS)Nr)Úrangerrr)ÚcountÚ_r rrÚgenDs zdata_repeated.<locals>.genNr)rr%rr rÚ data_repeated@s r&cCstdddg|jdS)Nr
r r    r)rrr rrrÚdata_for_sortingKsr'cCstdtjdg|jdS)Nr
r    rrr rrrÚdata_missing_for_sortingPsr(cCstjSr)r rrrrrÚna_valueUsr)cCsdd„S)NcSst |¡ot |¡Sr)ÚpdÚisna)ÚleftÚrightrrrÚ<lambda>\ózna_cmp.<locals>.<lambda>rrrrrÚna_cmpZsr0c    Cs"tddtjtjddddg|jdS)Nr    r
r rrr rrrÚdata_for_grouping_sr1c Cs$tddtjdddddddg
|jdS)Nréþÿÿÿéÿÿÿÿér
r rrr rrrÚdata_for_comparedsr5cs2eZdZdd„Zejjdd‡fdd„ƒZ‡ZS)ÚBaseSparseTestscCs|jttdƒkrt d¡dS)NrzCan't store nan in int array.)rrÚintÚpytestÚskip©ÚselfrrrrÚ_check_unsupportedjsz"BaseSparseTests._check_unsupportedú$SparseArray does not support setitem©Úreasoncstƒ |¡dSr)ÚsuperÚ
test_ravelr:©Ú    __class__rrrAnszBaseSparseTests.test_ravel)    Ú__name__Ú
__module__Ú __qualname__r<r8ÚmarkÚxfailrAÚ __classcell__rrrBrr6is r6c@seZdZdd„ZdS)Ú    TestDtypecCs| ¡tkst‚dSr)Zconstruct_array_typerÚAssertionError)r;rrrrrÚtest_array_type_with_argtsz"TestDtype.test_array_type_with_argN)rDrErFrLrrrrrJssrJc@seZdZdd„Zdd„ZdS)Ú TestInterfacecCs | ¡dSr©Úcopyr:rrrÚ    test_copyyszTestInterface.test_copycCs | ¡dSr)Úviewr:rrrÚ    test_view}szTestInterface.test_viewN)rDrErFrPrRrrrrrMxsrMc@s eZdZdS)ÚTestConstructorsN©rDrErFrrrrrS‚srScs°eZdZdd„Zej dddgejj    ddgdd    gd
g¡‡fd d „ƒZ
‡fd d„Z ‡fdd„Z ‡fdd„Z ‡fdd„Z‡fdd„Z‡fdd„Zejjdd‡fdd„ƒZ‡ZS)Ú TestReshapingcCs|t d|dd…i¡}t ddddgi¡}t ddddgi¡ d¡}|||g}t |¡}t d    d
„|Dƒ¡}| ||¡dS) NÚAr r    r
ÚaÚbÚcÚcategorycSsg|]}| dd„¡‘qS)cSst |¡ t¡Sr)r ÚasarrayÚastypeÚobject)Úsrrrr.’r/zCTestReshaping.test_concat_mixed_dtypes.<locals>.<listcomp>.<lambda>)Úapply©Ú.0ÚxrrrÚ
<listcomp>’sz:TestReshaping.test_concat_mixed_dtypes.<locals>.<listcomp>)r*Ú    DataFramer\ÚconcatÚassert_frame_equal)r;rZdf1Zdf2Zdf3ÚdfsÚresultÚexpectedrrrÚtest_concat_mixed_dtypes‡s
 
 ÿz&TestReshaping.test_concat_mixed_dtypesÚcolumnsrVÚB)rVrW)rVrXÚouterÚinner)Únamescstƒ ||¡dSr)r@Ú
test_stack)r;rrkrBrrrp–s
zTestReshaping.test_stackcs| |¡tƒ ||¡dSr)r<r@Útest_concat_columns©r;rr)rBrrrq¢s
z!TestReshaping.test_concat_columnscs| |¡tƒ ||¡dSr)r<r@Ú'test_concat_extension_arrays_copy_falserrrBrrrs¦s
z5TestReshaping.test_concat_extension_arrays_copy_falsecs| |¡tƒ ||¡dSr)r<r@Ú
test_alignrrrBrrrtªs
zTestReshaping.test_aligncs| |¡tƒ ||¡dSr)r<r@Útest_align_framerrrBrrru®s
zTestReshaping.test_align_framecs| |¡tƒ ||¡dSr)r<r@Útest_align_series_framerrrBrrrv²s
z%TestReshaping.test_align_series_framecs| |¡tƒ ||¡dSr)r<r@Ú
test_mergerrrBrrrw¶s
zTestReshaping.test_merger=r>cstƒ |¡dSr)r@Útest_transposer:rBrrrxºszTestReshaping.test_transpose)rDrErFrjr8rGÚ parametrizer*Z
MultiIndexÚ from_tuplesrprqrsrtrurvrwrHrxrIrrrBrrU†s&ÿþþ           rUcs$eZdZdd„Z‡fdd„Z‡ZS)Ú TestGetitemcCsˆtj|dd„tt|ƒƒDƒd}t |jj¡rTt | d¡¡rNt |j    d¡slt
‚n| d¡|j    dkslt
‚| d¡|j    dks„t
‚dS)NcSsg|] }d|‘qS)r
r)raÚirrrrcÁsz(TestGetitem.test_get.<locals>.<listcomp>)Úindexr4r
r    ) r*ÚSeriesr"Úlenr r ÚvaluesrÚgetÚilocrK)r;rÚserrrrÚtest_getÀs
 &zTestGetitem.test_getcs| |¡tƒ ||¡dSr)r<r@Ú test_reindexrrrBrrr…Ès
zTestGetitem.test_reindex)rDrErFr„r…rIrrrBrr{¿sr{c@s eZdZdS)Ú    TestIndexNrTrrrrr†Ðsr†csjeZdZdd„Z‡fdd„Z‡fdd„Z‡fdd„Z‡fd    d
„Zej    j
d d ‡fd d„ƒZ dd„Z ‡Z S)Ú TestMissingcCs„t|ƒ}ttt |jj¡ƒ}tddg|d}| ¡}t ||¡|     d¡}ttt |jj¡ƒ}tddgd|d}| 
| ¡|¡dS)NTF©rr©rr) rrÚboolr*r+rrÚtmÚassert_sp_array_equalÚfillnaZ assert_equal)r;r!ZsarrZexpected_dtyperirhrrrÚ    test_isnaÕs 
zTestMissing.test_isnac    s*tjtddtƒ |¡W5QRXdS©NF©Zcheck_stacklevel)r‹Úassert_produces_warningrr@Útest_fillna_limit_pad©r;r!rBrrr’âsz!TestMissing.test_fillna_limit_padc    s*tjtddtƒ |¡W5QRXdSr©r‹r‘rr@Útest_fillna_limit_backfillr“rBrrr•æsz&TestMissing.test_fillna_limit_backfillc    sLt |j¡r"|j tjjdd¡tj    t
ddt ƒ  |¡W5QRXdS)Nz'returns array with different fill valuer>Fr) r r rÚnodeÚ
add_markerr8rGrHr‹r‘rr@Útest_fillna_no_op_returns_copy)r;rrrBrrr˜ês   ÿz*TestMissing.test_fillna_no_op_returns_copyc    s*tjtddtƒ |¡W5QRXdSrr”r“rBrrÚtest_fillna_series_methodòsz%TestMissing.test_fillna_series_methodZ Unsupportedr>cstƒ ¡dSr)r@Útest_fillna_series)r;rBrrršöszTestMissing.test_fillna_seriescCst|d}t |ddgdœ¡ |¡}t |j¡r<t|j|ƒ}n|j}t |j||g|dddgdœ¡}| ||¡dS)Nr    r
)rVrlrˆ)    r*rdrr+rrrÚ_from_sequencerf)r;r!rrhrrirrrÚtest_fillna_frameûs þÿzTestMissing.test_fillna_frame)rDrErFrŽr’r•r˜r™r8rGrHršrœrIrrrBrr‡Ôs     r‡csªeZdZdZdd„Zdd„Zejjdd‡fdd    „ƒZ    d
d „Z
‡fd d „Z ‡fdd„Z dd„Z ej dddg¡‡fdd„ƒZej dejejejg¡‡fdd„ƒZ‡ZS)Ú TestMethodsz Sparse[bool]cCsŠ| ddg¡}tjd|idd}|jd}| |¡}t|jdƒrn|rZ|jj|jjksnt    ‚n|jj|jjk    snt    ‚|j
j   ¡|  ¡ks†t    ‚dS)Nr    rVFrN)rrÚblocks) Útaker*rdr‚rÚhasattrZ_mgrr€rrKrVÚ_valuesÚto_dense)r;r!Úusing_copy_on_writeÚarrZdfÚ
filled_valrhrrrÚtest_fillna_copy_frames
 
 z"TestMethods.test_fillna_copy_framecCsn| ddg¡}tj|dd}|d}| |¡}|rD|j|jksTt‚n|j|jk    sTt‚|j ¡| ¡ksjt‚dS)Nr    FrNr)rŸr*r~rr¡rKr¢)r;r!r£r¤rƒr¥rhrrrÚtest_fillna_copy_series!s
z#TestMethods.test_fillna_copy_serieszNot Applicabler>cstƒ |¡dSr)r@Útest_fillna_length_mismatchr“rBrrr¨/sz'TestMethods.test_fillna_length_mismatchc Csü|d|dkst‚t|ƒ}|dd…\}}t |j||||g|jd¡}t ddddg¡}| |¡}t    ddƒ}    t |j||||g|    d¡}
||
¡|j||||g|jd} t ddddg¡}| || ¡}t |j||||g|jd¡}
||
¡dS)    Nrr    r
rˆTFÚfloatg) rKÚtyper*r~r›rr ÚarrayÚwhererÚassert_series_equal) r;rr)ÚclsrWrXrƒZcondrhZ    new_dtyperiÚotherrrrÚtest_where_series3s 
 
ÿ  zTestMethods.test_where_seriescs6|jjdkr&tjjdd}|j |¡tƒ |¡dS)Nr7z2TODO(SparseArray.__setitem__) will preserve dtype.r>)    rÚsubtyper8rGrHr–r—r@Útest_combine_first)r;rrrGrBrrr²Is  ÿ zTestMethods.test_combine_firstc    s,tjtddtƒ ||¡W5QRXdSr)r‹r‘rr@Útest_searchsorted)r;r'Ú    as_seriesrBrrr³SszTestMethods.test_searchsortedcCs6| d¡}|jd|jd<|jd|jdks2t‚dS)Nrr    )ÚshiftZ_sparse_valuesrK)r;rrhrrrÚtest_shift_0_periodsWs
z TestMethods.test_shift_0_periodsÚmethodZargmaxZargmincs| |¡tƒ |||¡dSr)r<r@Útest_argmin_argmax_all_na)r;r·rr)rBrrr¸^s
z%TestMethods.test_argmin_argmax_all_naÚboxcs | |¡tƒ ||||¡dSr)r<r@Ú test_equals)r;rr)r´r¹rBrrrºds
zTestMethods.test_equals)rDrErFZ_combine_le_expected_dtyper¦r§r8rGrHr¨r°r²r³r¶ryr¸r*r«r~rdrºrIrrrBrrs 
rcs4eZdZdd„Zejjedd‡fdd„ƒZ‡Z    S)Ú TestCastingcCsHt |dd…¡ t¡}tjdd„|dd…Dƒtd}| ||¡dS)NécSsg|] }t|ƒ‘qSr)Ústrr`rrrrcosz/TestCasting.test_astype_str.<locals>.<listcomp>rˆ)r*r~r\r½r]r­)r;rrhrirrrÚtest_astype_strks zTestCasting.test_astype_strzno sparse StringDtype)Úraisesr?cstƒ |¡dSr)r@Útest_astype_stringr:rBrrrÀrszTestCasting.test_astype_string)
rDrErFr¾r8rGrHÚ    TypeErrorrÀrIrrrBrr»jsr»cs\eZdZdZdZdZdZdd„Z‡fdd„Z‡fdd„Z    ‡fdd    „Z
e f‡fd
d „    Z ‡Z S) ÚTestArithmeticOpsNcCs|jdkrt d¡dS)Nrz=Incorrected expected from Series.combine and tested elsewhere)rr8r9r:rrrÚ_skip_if_different_combine}s
z,TestArithmeticOps._skip_if_different_combinecs| |¡tƒ ||¡dSr)rÃr@Útest_arith_series_with_scalar©r;rÚall_arithmetic_operatorsrBrrrĄs
z/TestArithmeticOps.test_arith_series_with_scalarcs| |¡tƒ ||¡dSr)rÃr@Útest_arith_series_with_arrayrÅrBrrrLjs
z.TestArithmeticOps.test_arith_series_with_arraycsH|jjdkrn(| d¡dkr6tjjdd}|j |¡tƒ     ||¡dS)Nrr$)ÚmulZrmulÚfloordivZ    rfloordivÚpowÚmodZrmodz result dtype.fill_value mismatchr>)
rrÚstripr8rGrHr–r—r@Útest_arith_frame_with_scalar)r;rrÆrrGrBrrr͌s       z.TestArithmeticOps.test_arith_frame_with_scalarcstƒj|||dddS)N)Úexc)r@Ú_check_divmod_op)r;rƒÚopr¯rÎrBrrrϜsz"TestArithmeticOps._check_divmod_op)rDrErFZseries_scalar_excZframe_scalar_excZ
divmod_excZseries_array_excrÃrÄrÇrÍÚNotImplementedErrorrÏrIrrrBrrÂws   rÂc@s`eZdZedœdd„Zedœdd„Zejjddedœdd    „ƒZ    ejjddedœd
d „ƒZ
d S) ÚTestComparisonOps)r5cCs–|}|||ƒ}t|tƒst‚|jjtjks.t‚t|tƒrH||j|jƒ}n>t |t     |j¡t     |¡ƒ¡}t|| 
¡t     |¡ƒ|tjd}t   ||¡dS)Nr‰) Ú
isinstancerrKrr±r Zbool_rÚallr[r¢r‹rŒ)r;r5Ú comparison_opr¯rÐrhrrirrrÚ_compare_other¢s
 
ÿýz TestComparisonOps._compare_othercCs>| ||d¡| ||d¡| ||d¡| ||tj¡dS)Nrr    r3)rÖr r)r;r5rÕrrrÚ test_scalar·szTestComparisonOps.test_scalarz Wrong indicesr>cCs t ddd¡}| |||¡dS)Néüÿÿÿr¼é
)r ZlinspacerÖ©r;r5rÕr¤rrrÚ
test_array½szTestComparisonOps.test_arraycCs0|d}| |||¡|d}| |||¡dS)Nr    r
)rÖrÚrrrÚtest_sparse_arrayÂsz#TestComparisonOps.test_sparse_arrayN) rDrErFrrÖr×r8rGrHrÛrÜrrrrrÒ¡s   rÒcs*eZdZejjdd‡fdd„ƒZ‡ZS)Ú TestPrintingzDifferent reprr>cstƒ ||¡dSr)r@Útest_array_repr)r;rrrBrrrÞËszTestPrinting.test_array_repr)rDrErFr8rGrHrÞrIrrrBrrÝÊs rÝcs.eZdZej dddg¡‡fdd„ƒZ‡ZS)Ú TestParsingÚenginerYÚpythonc    s0d}tjt|dtƒ ||¡W5QRXdS)Nz,.*must implement _from_sequence_of_strings.*)Úmatch)r8r¿rÑr@Ú test_EA_types)r;ràrZ expected_msgrBrrrãÑszTestParsing.test_EA_types)rDrErFr8rGryrãrIrrrBrrßÐsrßc@s&eZdZej dddg¡dd„ƒZdS)ÚTestNoNumericAccumulationsÚskipnaTFcCsdSrr)r;rZall_numeric_accumulationsrårrrÚtest_accumulate_seriesÙsz1TestNoNumericAccumulations.test_accumulate_seriesN)rDrErFr8rGryrærrrrräØsrä):Ú__doc__Únumpyr r8Z pandas.errorsrZpandasr*rZpandas._testingZ_testingr‹Z pandas.arraysrZpandas.tests.extensionrrZfixturerrrrr!r&r'r(r)r0r1r5r6ZBaseDtypeTestsrJZBaseInterfaceTestsrMZBaseConstructorsTestsrSZBaseReshapingTestsrUZBaseGetitemTestsr{ZBaseIndexTestsr†ZBaseMissingTestsr‡ZBaseMethodsTestsrZBaseCastingTestsr»ZBaseArithmeticOpsTestsrÂrÒZBasePrintingTestsrÝZBaseParsingTestsrßZBaseAccumulateTestsrärrrrÚ<module>s\      
 
 
 
 
 
 
 
 
 
 
 
 
 
9<Z *)