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
U
­ý°d'ã@sêdZddlZddlZddlZddlZddlmZmZm    Z    ddl
m Z ddl mZddlmZdd„Zejdd    „ƒZejd
d „ƒZejd d „ƒZejdd„ƒZejdd„ƒZejdd„ƒZejdd„ƒZGdd„dejƒZGdd„dejƒZGdd„dejƒZGdd„dej ƒZ!Gdd„dej"ƒZ#Gd d!„d!ej$ƒZ%Gd"d#„d#ej&ƒZ'Gd$d%„d%ej(ƒZ)Gd&d'„d'ej*ƒZ+Gd(d)„d)ej,ƒZ-Gd*d+„d+ej.ƒZ/Gd,d-„d-ej0ƒZ1Gd.d/„d/ej2ƒZ3Gd0d1„d1ej4ƒZ5Gd2d3„d3ej6ƒZ7Gd4d5„d5ej8ƒZ9dS)6aj
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)Ú CategoricalÚCategoricalIndexÚ    Timestamp©ÚCategoricalDtype)ÚbasecCs.tjjttjƒdd}|d|dkrq*q|S)Néd)Úsizeré)ÚnpÚrandomÚchoiceÚlistÚstringÚ ascii_letters)Úvalues©rú^d:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/extension/test_categorical.pyÚ    make_data srcCstƒS©NrrrrrÚdtype+srcCs
ttƒƒS)zˆLength-100 array for this type.
 
    * data[0] and data[1] should both be non missing
    * data[0] and data[1] should not be equal
    )rrrrrrÚdata0srcCsttjdgƒS)zLength 2 array with [NA, Valid]ÚA)rr ÚnanrrrrÚ data_missing:srcCstdddgdddgddS)NrÚBÚCT©Ú
categoriesZordered©rrrrrÚdata_for_sorting@sr cCstdddgddgddS)NrrTrrrrrrÚdata_missing_for_sortingEsr!cCstjSr)r rrrrrÚna_valueJsr"c    CstddddddddgƒS)NÚaÚbÚcrrrrrÚdata_for_groupingOsr&c@s eZdZdS)Ú    TestDtypeN©Ú__name__Ú
__module__Ú __qualname__rrrrr'Tsr'cs2eZdZejjdd‡fdd„ƒZdd„Z‡ZS)Ú TestInterfacezMemory usage doesn't match©Úreasoncstƒ |¡dSr)ÚsuperÚtest_memory_usage©Úselfr©Ú    __class__rrr0YszTestInterface.test_memory_usagecCs€|jj}|| ¡}|d|ks&t‚|d|ks6t‚||ksBt‚||ksNt‚tjD]&}||krbqT||ksnt‚||ksTt‚qTdS)Nr)rr"ZisnaÚAssertionErrorÚtmZ NULL_OBJECTS)r2rrr"Z na_value_objrrrÚ test_contains^s  
 zTestInterface.test_contains)    r)r*r+ÚpytestÚmarkÚxfailr0r7Ú __classcell__rrr3rr,Xs r,c@seZdZdd„ZdS)ÚTestConstructorscCs:| ¡}|jd|d}t||ƒs$t‚|jtgƒks6t‚dS)N)é©r)Zconstruct_array_typeÚ_emptyÚ
isinstancer5rr)r2rÚclsÚresultrrrÚ
test_emptyxszTestConstructors.test_emptyN)r)r*r+rCrrrrr<wsr<c@s eZdZdS)Ú TestReshapingNr(rrrrrD‚srDcs*eZdZejjdd‡fdd„ƒZ‡ZS)Ú TestGetitemzBackwards compatibilityr-cstƒ |¡dSr)r/Útest_getitem_scalarr1r3rrrF‡szTestGetitem.test_getitem_scalar)r)r*r+r8r9ÚskiprFr;rrr3rrE†s rEc@s eZdZdS)Ú TestSetitemNr(rrrrrHsrHc@s eZdZdS)Ú    TestIndexNr(rrrrrI“srIc@s eZdZdS)Ú TestMissingNr(rrrrrJ—srJc@s eZdZdS)Ú
TestReduceNr(rrrrrK›srKc@s&eZdZej dddg¡dd„ƒZdS)ÚTestAccumulateÚskipnaTFcCsdSrr)r2rZall_numeric_accumulationsrMrrrÚtest_accumulate_series sz%TestAccumulate.test_accumulate_seriesN)r)r*r+r8r9Ú parametrizerNrrrrrLŸsrLcs2eZdZejjdd‡fdd„ƒZdd„Z‡ZS)Ú TestMethodszUnobserved categories includedr-cstƒ ||¡Sr)r/Útest_value_counts)r2Zall_dataZdropnar3rrrQ¦szTestMethods.test_value_countscs¤|dƒ\}}t |¡}t |¡}| |dd„¡}t dd„tt|ƒt|ƒƒDƒ¡}| ||¡|jd‰| ˆdd„¡}t ‡fdd„t|ƒDƒ¡}| ||¡dS)    NécSs||Srr©Úx1Zx2rrrÚ<lambda>°óz.TestMethods.test_combine_add.<locals>.<lambda>cSsg|]\}}||‘qSrr)Ú.0r#r$rrrÚ
<listcomp>²sz0TestMethods.test_combine_add.<locals>.<listcomp>rcSs||SrrrSrrrrU·rVcsg|] }|ˆ‘qSrr)rWr#©ÚvalrrrX¸s)ÚpdÚSeriesÚcombineÚziprÚassert_series_equalZiloc)r2Z data_repeatedZ
orig_data1Z
orig_data2Ús1Ús2rBÚexpectedrrYrÚtest_combine_addªs 
 
ÿ 
zTestMethods.test_combine_add)    r)r*r+r8r9r:rQrcr;rrr3rrP¥s rPc @s eZdZej deeg¡ej ddej    ge
dƒe j gg¡dd„ƒƒZ ej de jdd    gd
d e jd d gd d e je  d¡e  d    ¡gdd e je  d d¡e  dd¡gdd e jdej    gdd g¡dd„ƒZej ddejdgdd fde  e
dddg¡jfg¡dd„ƒZdS)Ú TestCastingrArr
Ú2000c    Cs8||ƒ}d}tjttf|d| t¡W5QRXdS)NzCannot (cast|convert)©Úmatch)r8ÚraisesÚ
ValueErrorÚ    TypeErrorÚastypeÚint)r2rArÚsÚmsgrrrÚtest_cast_nan_to_int½sz TestCasting.test_cast_nan_to_intrbÚ2019Ú2020zdatetime64[ns, UTC]r>rztimedelta64[ns]z period[A-DEC]rRÚintervalZInt64cCs"| d¡ |j¡}t ||¡dS)NÚcategory)rkrr6r_)r2rbrBrrrÚ%test_cast_category_to_extension_dtypeÇs z1TestCasting.test_cast_category_to_extension_dtypezdtype, expectedzdatetime64[ns]z2015-01-01T00:00:00.000000000zdatetime64[ns, MET]z2015-01-01 00:00:00+0100ZMET)ÚtzcCs tdgƒ |¡}||kst‚dS)Nz
2015-01-01)rrkr5)r2rrbrBrrrÚtest_consistent_casting×sz#TestCasting.test_consistent_castingN)r)r*r+r8r9rOrrr rrr[ZNaTror\ZPeriodZIntervalrtÚarrayZ DatetimeIndexrvrrrrrd¼s4   ûþ
 
þ ÿþûþrdcsHeZdZ‡fdd„Z‡fdd„Zdd„Zdd„Zef‡fd    d
„    Z‡Z    S) ÚTestArithmeticOpscs4|}|dkr"|j tjjdd¡tƒ ||¡dS©NÚ__rmod__z/rmod never called when string is first argumentr-)ÚnodeÚ
add_markerr8r9r:r/Útest_arith_frame_with_scalar©r2rZall_arithmetic_operatorsÚrequestÚop_namer3rrr}ísÿÿz.TestArithmeticOps.test_arith_frame_with_scalarcs4|}|dkr"|j tjjdd¡tƒ ||¡dSry)r{r|r8r9r:r/Útest_arith_series_with_scalarr~r3rrrøsÿÿz/TestArithmeticOps.test_arith_series_with_scalarc    Cs0t |¡}tjtdd||W5QRXdS)Nz"cannot perform|unsupported operandrf)r[r\r8rhrj)r2rZserrrrÚ$test_add_series_with_extension_arrays
z6TestArithmeticOps.test_add_series_with_extension_arraycCsdSrr)r2rrrÚtest_divmod_series_arraysz*TestArithmeticOps.test_divmod_series_arraycstƒj|||tdS)N)Úexc)r/Ú_check_divmod_oprj)r2rmÚopÚotherr„r3rrr… sz"TestArithmeticOps._check_divmod_op)
r)r*r+r}rr‚rƒÚNotImplementedErrorr…r;rrr3rrxìs
 
rxc@sDeZdZdd„Zej dddgddgedƒed    ƒgg¡d
d „ƒZd S) ÚTestComparisonOpsc        Cs¢d|j›d}|dkrB|||ƒ}| |dd„¡}||k ¡sžt‚n\|dkrv|||ƒ}| |dd„¡}||k ¡sžt‚n(d}tjt|d|||ƒW5QRXdS)    NÚ__Ú__eq__cSs||kSrr©ÚxÚyrrrrUrVz2TestComparisonOps._compare_other.<locals>.<lambda>Ú__ne__cSs||kSrrrŒrrrrUrVz7Unordered Categoricals can only compare equality or notrf)r)r]Úallr5r8rhrj)    r2rmrr†r‡r€rBrbrnrrrÚ_compare_others
 
z TestComparisonOps._compare_otherrr#r$rr
rprqcCs<tjddg|d}tjddg|d}||k}| ¡s8t‚dS)Néÿÿÿÿr)rr
)rZ
from_codesrr5)r2rZc1Úc2rBrrrÚtest_not_equal_with_na"sz(TestComparisonOps.test_not_equal_with_naN)    r)r*r+r‘r8r9rOrr”rrrrr‰s þr‰c@s eZdZdS)Ú TestParsingNr(rrrrr•0sr•c@seZdZdd„ZdS)Ú Test2DCompatcCsHt| dd¡ƒ}| d¡dks"t‚t| dd¡ƒ}| d¡dksDt‚dS)Nr
r’z
Categories)ÚreprZreshapeÚcountr5)r2rÚresrrrÚ test_repr_2d5szTest2DCompat.test_repr_2dN)r)r*r+ršrrrrr–4sr–):Ú__doc__rÚnumpyr r8Zpandasr[rrrZpandas._testingZ_testingr6Zpandas.api.typesrZpandas.tests.extensionrrZfixturerrrr r!r"r&ZBaseDtypeTestsr'ZBaseInterfaceTestsr,ZBaseConstructorsTestsr<ZBaseReshapingTestsrDZBaseGetitemTestsrEZBaseSetitemTestsrHZBaseIndexTestsrIZBaseMissingTestsrJZBaseNoReduceTestsrKZBaseAccumulateTestsrLZBaseMethodsTestsrPZBaseCastingTestsrdZBaseArithmeticOpsTestsrxZBaseComparisonOpsTestsr‰ZBaseParsingTestsr•ZNDArrayBacked2DTestsr–rrrrÚ<module>sN    
 
    
 
 
 
 
     0$