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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
U
­ý°dÐ=ã@s–dZddlZddlZddlmZddlmZmZddl    Z
ddl m Z ddlmZddlmZddlmZddlmZed    œd
d „Ze jZdIeed œdd„Zejddgddd„ƒZejdd„ƒZejdd„ƒZejdd„ƒZ ejdd„ƒZ!ejdd„ƒZ"ejdd „ƒZ#ejd!d"„ƒZ$ejd#d$„ƒZ%ejd%d&„ƒZ&ej' (d&¡Z)Gd'd(„d(ƒZ*Gd)d*„d*e*ej+ƒZ,Gd+d,„d,e*ej-ƒZ.Gd-d.„d.e*ej/ƒZ0Gd/d0„d0e*ej1ƒZ2Gd1d2„d2e*ej3ƒZ4Gd3d4„d4e*ej5ƒZ6Gd5d6„d6e*ej7ƒZ8Gd7d8„d8e*ej9ƒZ:Gd9d:„d:e*ej;ƒZ<Gd;d<„d<e*ej=ƒZ>e)Gd=d>„d>e*ej?ƒƒZ@Gd?d@„d@e*ejAƒZBGdAdB„dBe*ejCƒZDGdCdD„dDe*ejEƒZFe)GdEdF„dFe*ejGƒƒZHGdGdH„dHe*ejIƒZJdS)JaÎ
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/`.
 
Note: we do not bother with base.BaseIndexTests because PandasArray
will never be held in an Index.
éN)Úcan_hold_element)ÚExtensionDtypeÚ PandasDtype)Úis_object_dtype)Ú PandasArray)Úblocks)Úbase)ÚreturncCst|tƒr| ¡}t||ƒS©N)Ú
isinstancerÚto_numpyr)ÚobjÚelement©rúXd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/extension/test_numpy.pyÚ_can_hold_element_patched#s
rÚ
Attributes)Úattrr cCst|dkrbt|ddƒ}t|ddƒ}t|tƒrBt|tƒsB| |j¡}n t|tƒrbt|tƒsb| |j¡}t||||ƒdS)zh
    patch tm.assert_attr_equal so PandasDtype("object") is closed enough to
    np.dtype("object")
    ÚdtypeN)Úgetattrr rÚastypeÚ numpy_dtypeÚorig_assert_attr_equal)rÚleftÚrightr ZlattrZrattrrrrÚ_assert_attr_equal,s   rÚfloatÚobject)ÚparamscCstt |j¡ƒSr
)rÚnprÚparam)Úrequestrrrr<src    csJ| ¡8}| tdd¡| tdt¡| tjdt¡dVW5QRXdS)aó
    A monkeypatch to tells pandas to let us in.
 
    By default, passing a PandasArray to an index / series / frame
    constructor will unbox that PandasArray to an ndarray, and treat
    it as a non-EA column. We don't want people using EAs without
    reason.
 
    The mechanism for this is a check against ABCPandasArray
    in each constructor.
 
    But, for testing, we need to allow them in pandas. So we patch
    the _typ of PandasArray, so that we evade the ABCPandasArray
    check.
    Z_typÚ    extensionrÚassert_attr_equalN)ÚcontextÚsetattrrrrÚtmZ    assertersr)Z monkeypatchÚmrrrÚallow_in_pandasAs
 
r(cCs:|jdkr$t dd„tdƒDƒ¡jSttjdd|jdƒS)NrcSsg|]
}|f‘qSrr)Ú.0ÚirrrÚ
<listcomp>\szdata.<locals>.<listcomp>édéée©r)    rÚpdÚSeriesÚrangeÚarrayrrÚarangeÚ_dtype©r(rrrrÚdataYs
r7cCs6|jdkr"ttjtjdgtdƒStt tjdg¡ƒS)Nr©r-r/gð?©rrrr3Únanrr6rrrÚ data_missing`s
r;cCstjSr
)rr:rrrrÚna_valuegsr<cCs dd„}|S)NcSst |¡ot |¡Sr
)rÚisnan)ÚaÚbrrrÚcmpnszna_cmp.<locals>.cmpr)r@rrrÚna_cmplsrAcCs@|jdkr,ttjddddgtddd…ƒStt dd    d
g¡ƒS) ziLength-3 array with a known sort order.
 
    This should be three items [B, C, A] with
    A < B < C
    rr©é©ér8r/r-NrCr)rrrr3rr6rrrÚdata_for_sortingts
"rFcCs:|jdkr$ttjdtjdgtdƒStt dtjdg¡ƒS)zvLength-3 array with a known sort order.
 
    This should be three items [B, NA, A] with
    A < B and NA missing.
    rr8)rr/r-rr9r6rrrÚdata_missing_for_sorting‚s
rGc
CsN|jdkrd\}}}nt d¡\}}}ttj||tjtj||||g|jdƒS)z“Data for factorization, grouping, and unique tests.
 
    Expected to be like [B, B, NA, NA, A, A, B, C]
 
    Where A < B < C and NA is missing
    r)r8rBrDrEr/)rrr4rr3r:)r(rr>r?ÚcrrrÚdata_for_groupingŽs 
 "ÿrIcCs&|dkr"tjjdd}|j |¡dS)aŒ
    Tests for PandasArray with nested data. Users typically won't create
    these objects via `pd.array`, but they can show up through `.array`
    on a Series with nested data. Many of the base tests fail, as they aren't
    appropriate for nested data.
 
    This fixture allows these tests to be skipped when used as a usefixtures
    marker to either an individual test or a test class.
    rúFails for object dtype©ÚreasonN)ÚpytestÚmarkÚxfailÚnodeÚ
add_marker)rr!rNrrrÚskip_numpy_objectŸs rRc@seZdZedd„ƒZdS)ÚBaseNumPyTestscOsHt|tjƒr4t|jtƒs4t|jtƒr4| t|jƒ¡}tj||f|ž|ŽSr
)    r r0r1rrrrr&Úassert_series_equal)ÚclsrrÚargsÚkwargsrrrrT³s
ÿ
þ
ýz"BaseNumPyTests.assert_series_equalN)Ú__name__Ú
__module__Ú __qualname__Ú classmethodrTrrrrrS²srSc@s eZdZdS)Ú TestCastingN©rXrYrZrrrrr\Àsr\cs6eZdZejjdddd„ƒZe‡fdd„ƒZ‡Z    S)ÚTestConstructorszWe don't register our dtyperKcCsdSr
r©Úselfr7rrrÚtest_from_dtypeÅsz TestConstructors.test_from_dtypecstƒ ||¡dSr
)ÚsuperÚ)test_series_constructor_scalar_with_index)r`r7r©Ú    __class__rrrcÊsz:TestConstructors.test_series_constructor_scalar_with_index)
rXrYrZrMrNÚskipraÚ skip_nestedrcÚ __classcell__rrrdrr^Äs 
r^cs(eZdZ‡fdd„Z‡fdd„Z‡ZS)Ú    TestDtypecs<|jjdkr,|j tjjd|jj›d¡tƒ |¡dS)Nrz2PandasArray expectedly clashes with a NumPy name: rK)    rrrPrQrMrNrOrbÚtest_check_dtype)r`r7r!rdrrrjÑs  ÿÿzTestDtype.test_check_dtypecs(|jdkrt|ƒs$t‚n tƒ |¡dS)Nr)rrÚAssertionErrorrbÚtest_is_not_object_type)r`rr!rdrrrlÛs
z!TestDtype.test_is_not_object_type)rXrYrZrjrlrhrrrdrriÐs
rics eZdZe‡fdd„ƒZ‡ZS)Ú TestGetitemcstƒ |¡dSr
)rbÚtest_getitem_scalarr_rdrrrnåszTestGetitem.test_getitem_scalar)rXrYrZrgrnrhrrrdrrmäsrmc@s eZdZdS)Ú TestGroupbyNr]rrrrroësrocs eZdZe‡fdd„ƒZ‡ZS)Ú TestInterfacecstƒ |¡dSr
)rbÚtest_array_interfacer_rdrrrqðsz"TestInterface.test_array_interface)rXrYrZrgrqrhrrrdrrpïsrpcs†eZdZe‡fdd„ƒZe‡fdd„ƒZe‡fdd„ƒZe‡fdd„ƒZej    j
d    d
‡fd d „ƒZ ‡fd d„Z e‡fdd„ƒZ ‡ZS)Ú TestMethodscstƒ |¡dSr
)rbÚtest_shift_fill_valuer_rdrrrs÷sz!TestMethods.test_shift_fill_valuecstƒ |¡dSr
)rbÚtest_fillna_copy_frame©r`r;rdrrrtüsz"TestMethods.test_fillna_copy_framecstƒ |¡dSr
)rbÚtest_fillna_copy_seriesrurdrrrvsz#TestMethods.test_fillna_copy_seriescstƒ ||¡dSr
)rbÚtest_searchsorted)r`rFZ    as_seriesrdrrrwszTestMethods.test_searchsortedz"PandasArray.diff may fail on dtyperKcstƒ ||¡Sr
)rbÚ    test_diff)r`r7Zperiodsrdrrrx szTestMethods.test_diffcs6|jjtkr&tjjdd}|j |¡tƒ     |¡dS)Nz$Dimension mismatch in np.concatenaterK)
rrrrMrNrOrPrQrbÚ test_insert)r`r7r!rNrdrrrys  zTestMethods.test_insertcstƒ ||¡dSr
)rbÚtest_insert_invalid©r`r7Zinvalid_scalarrdrrrzszTestMethods.test_insert_invalid)rXrYrZrgrsrtrvrwrMrNrOrxryrzrhrrrdrrrös  rrcsheZdZdZdZdZdZe‡fdd„ƒZedd„ƒZ    e‡fdd„ƒZ
‡fdd    „Z e‡fd
d „ƒZ ‡Z S) ÚTestArithmeticsNcstƒ |¡dSr
)rbÚ test_divmodr_rdrrr}"szTestArithmetics.test_divmodcCs t |¡}|j|t|dddS)N)Úexc)r0r1Z_check_divmod_opÚdivmod)r`r7ZserrrrÚtest_divmod_series_array&s
z(TestArithmetics.test_divmod_series_arraycstƒ ||¡dSr
)rbÚtest_arith_series_with_scalar©r`r7Úall_arithmetic_operatorsrdrrr+sz-TestArithmetics.test_arith_series_with_scalarcsD|}|jjtkr2|dkr2tjjdd}|j |¡tƒ     ||¡dS)N)Ú__add__Ú__radd__rJrK)
rrrrMrNrOrPrQrbÚtest_arith_series_with_array)r`r7rƒr!ÚopnamerNrdrrr†/s
 z,TestArithmetics.test_arith_series_with_arraycstƒ ||¡dSr
)rbÚtest_arith_frame_with_scalarr‚rdrrrˆ6sz,TestArithmetics.test_arith_frame_with_scalar)rXrYrZZ
divmod_excZseries_scalar_excZframe_scalar_excZseries_array_excrgr}r€rr†rˆrhrrrdrr|s
 r|c@s eZdZdS)Ú TestPrintingNr]rrrrr‰;sr‰cs6eZdZdd„Zej dddg¡‡fdd„ƒZ‡ZS)ÚTestNumericReducecCs:t||ƒ|d}t| |jj¡|ƒ|d}t ||¡dS)N)Úskipna)rrrr5r&Zassert_almost_equal)r`ÚsZop_namer‹ÚresultÚexpectedrrrÚ check_reduce@szTestNumericReduce.check_reducer‹TFcstƒ |||¡dSr
)rbÚtest_reduce_series)r`r7Zall_boolean_reductionsr‹rdrrrFsz$TestNumericReduce.test_reduce_series)    rXrYrZrrMrNÚ parametrizerrhrrrdrrŠ?srŠc@s eZdZdS)ÚTestBooleanReduceNr]rrrrr’Ksr’cs0eZdZe‡fdd„ƒZe‡fdd„ƒZ‡ZS)Ú TestMissingcstƒ |¡dSr
)rbÚtest_fillna_seriesrurdrrr”QszTestMissing.test_fillna_seriescstƒ |¡dSr
)rbÚtest_fillna_framerurdrrr•VszTestMissing.test_fillna_frame)rXrYrZrgr”r•rhrrrdrr“Psr“c    sBeZdZej ddejdejjdddg¡‡fdd„ƒZ‡Z    S)    Ú TestReshapingÚin_frameTFz$PandasArray inconsistently extractedrK©Zmarkscstƒ ||¡dSr
)rbÚ test_concat)r`r7r—rdrrr™]s zTestReshaping.test_concat)
rXrYrZrMrNr‘r rOr™rhrrrdrr–\s þþþ
r–c
s®eZdZe‡fdd„ƒZe‡fdd„ƒZeej dddg¡‡fdd    „ƒƒZ    e‡fd
d „ƒZ
eejjd e   d d d ddg¡e j d d d ddgddgddgd‡fdd„ƒƒZeejjddddge j dddgdde   dddg¡gdddgd‡fdd„ƒƒZejjdddde jgdfejddde jgd ejjd e j ddde jgdddfe j ddde jgdddfgd!d"d#d$gd‡fd%d&„ƒZe‡fd'd(„ƒZe‡fd)d*„ƒZd+d,„Z‡ZS)-Ú TestSetitemcstƒ ||¡dSr
)rbÚtest_setitem_invalidr{rdrrr›lsz TestSetitem.test_setitem_invalidcstƒ ||¡dSr
)rbÚ test_setitem_sequence_broadcasts©r`r7Ú box_in_seriesrdrrrœqsz,TestSetitem.test_setitem_sequence_broadcastsÚsetterÚlocNcstƒ ||¡dSr
)rbÚtest_setitem_mask_broadcast)r`r7rŸrdrrr¡wsz'TestSetitem.test_setitem_mask_broadcastcstƒ |¡dSr
)rbÚ&test_setitem_scalar_key_sequence_raiser_rdrrr¢~sz2TestSetitem.test_setitem_scalar_key_sequence_raiseÚmaskTFÚbooleanr/z numpy-arrayz boolean-array)Úidscstƒ |||¡dSr
)rbÚtest_setitem_mask)r`r7r£ržrdrrr¦†s
zTestSetitem.test_setitem_maskÚidxrr-rCZInt64Úlistz integer-arraycstƒ |||¡dSr
)rbÚtest_setitem_integer_array©r`r7r§ržrdrrr©’sz&TestSetitem.test_setitem_integer_arrayzidx, box_in_seriesr˜z
list-Falsez    list-Truezinteger-array-Falsezinteger-array-Truecstƒ |||¡dSr
)rbÚ(test_setitem_integer_with_missing_raisesrªrdrrr«›s z4TestSetitem.test_setitem_integer_with_missing_raisescstƒ ||¡dSr
)rbÚtest_setitem_slicerrdrrr¬¨szTestSetitem.test_setitem_slicecstƒ |¡dSr
)rbÚtest_setitem_loc_iloc_slicer_rdrrr­¬sz'TestSetitem.test_setitem_loc_iloc_slicecCs„t dt |¡i¡}}tj|jd}||ƒ}|d|j|df<|jjtkrtt|t    ƒrb|t    dƒkrtt d| 
¡i¡}|  ||¡dS)Nr7)Úindex) r0Z    DataFramer1r®r rrrr Úslicer Zassert_frame_equal)r`r7Z full_indexerZdfrŽrÚkeyrrrÚ,test_setitem_with_expansion_dataframe_column°s z8TestSetitem.test_setitem_with_expansion_dataframe_column)rXrYrZrgr›rœrMrNr‘r¡r¢rr3r0r¦r©ZNAr rOr«r¬r­r±rhrrrdrršksPþú*ýü
ø
ršc@s eZdZdS)Ú TestParsingNr]rrrrr²Âsr²c@s eZdZdS)Ú Test2DCompatNr]rrrrr³Çsr³)r)KÚ__doc__ÚnumpyrrMZpandas.core.dtypes.castrZpandas.core.dtypes.dtypesrrZpandasr0Zpandas._testingZ_testingr&Zpandas.api.typesrZpandas.core.arrays.numpy_rZpandas.core.internalsrZpandas.tests.extensionrÚboolrr#rÚstrrZfixturerr(r7r;r<rArFrGrIrRrNZ usefixturesrgrSZBaseCastingTestsr\ZBaseConstructorsTestsr^ZBaseDtypeTestsriZBaseGetitemTestsrmZBaseGroupbyTestsroZBaseInterfaceTestsrpZBaseMethodsTestsrrZBaseArithmeticOpsTestsr|ZBasePrintingTestsr‰ZBaseNumericReduceTestsrŠZBaseBooleanReduceTestsr’ZBaseMissingTestsr“ZBaseReshapingTestsr–ZBaseSetitemTestsršZBaseParsingTestsr²ZNDArrayBacked2DTestsr³rrrrÚ<module>sj      
 
 
 
 
 
 
 
 
 
  &  W