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
U
­ý°dbEã@srddlmZmZddlmZddlZddlZddlZddlm    Z    m
Z
m Z m Z m Z mZddlmZGdd„dƒZdS)é)Ú OrderedDictÚ defaultdict)ÚdatetimeN)ÚNAÚ    DataFrameÚIndexÚ
MultiIndexÚSeriesÚ    Timestampc@s$eZdZdd„Zdd„Zdd„Zej ddd    d
d d d g¡dd„ƒZ    ej de
e e ƒe g¡dd„ƒZej de e gg¡dd„ƒZdd„Zej dddd„fddd„fddd„fdd d„fd!d"d„fg¡d#d$„ƒZd%d&„Zej d'e
d(d)d*œd+d,d*œd-d.d*œd/œfe e d0d(d)d*œfd(d+d,d*œfd+d-d.d*œfgƒfe e
ƒe e
d(d)d*œd+d,d*œd-d.d*œd/œƒfg¡d1d2„ƒZd3d4„Zd5d6„Zej d7d8d8d9gefed:d(d(ƒed;d+d+ƒed<d-d-ƒgegd)d,d.gegd(d+d-gegd=d>d?gegf¡d@dA„ƒZej dBe d+¡ege dC¡ege  dD¡ege !d8¡ege "dE¡egf¡dFdG„ƒZ#dHdI„Z$ej d!dJe%dKdLgƒe%dKdLgdMdNe& 'dOdPg¡e&j'dOdPgdQdRgdSg¡ej dTdUdVge%dUdVgƒe%dUdVgdWdNe& 'dXdYg¡e&j'dXdYgdZd[gdSg¡d\d]„ƒƒZ(ej dddddd!d^g¡ej d_e d(¡d(e d-¡ge  d)¡d,e  d.¡ge  d)¡d+e d-¡ge  d)¡d`e d-¡ge  d)¡d`ge d-¡ge  d)¡dae d-¡gdbœeeegeeegeeegeeegee egee)egdbœfd(d+d-gdDdcddgdOœeeegeeegdOœfd(ded-gdDdfddgdOœeeegeeegdOœff¡dgdh„ƒƒZ*ej ddddidd!g¡djdk„ƒZ+ej dlddmdngd(d-gd+doggdpœfd^dmdngd(d-gd+doggdJgdqœfg¡drds„ƒZ,ej dldd`d(dJdtœifdd`d(dJgifdd0d(gd`gd(gdJggduœfd^d0d(gd`gd(gdJggdJgdJgdvœfdd`d(id`dJigfd!d`d(id`dJidtœfg¡dwdx„ƒZ-dydz„Z.dJS){ÚTestDataFrameToDictc
Cs\tdƒ}t||g||gdœƒ}t||gddgdœƒ}||dœ||dœg}|ddœ|ddœg}|jdd|kspt‚|jdd|ks„t‚t||gddt||gd    ddœ}t||gddtddgd    ddœ}t |jd
d|¡t |jd
d|¡d dg||g||ggdd    gd œ}d dg|dg|dggdd    gd œ}    t |jd d|¡t |jd d|    ¡dS)NZ20130101©ÚAÚBééÚrecords©Úorientr ©ÚnamerÚseriesr)ÚindexÚdataÚcolumnsÚsplit)r
rÚto_dictÚAssertionErrorr    ÚtmÚassert_dict_equal)
ÚselfZtsmpÚ    test_dataZtest_data_mixedÚexpected_recordsZexpected_records_mixedZexpected_seriesZexpected_series_mixedÚexpected_splitZexpected_split_mixed©r#ú^d:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/frame/methods/test_to_dict.pyÚtest_to_dict_timestamps>þþ
ÿýý
ÿz*TestDataFrameToDict.test_to_dict_timestampc    CsLtddgddgdœddgd}d}tjt|d    |jd
d W5QRXdS) Nrrgà?gè?©ÚaÚbr ©rz1DataFrame index must be unique for orient='index'©Úmatchrr©rÚpytestÚraisesÚ
ValueErrorr©rÚdfÚmsgr#r#r$Ú/test_to_dict_index_not_unique_with_index_orientDszCTestDataFrameToDict.test_to_dict_index_not_unique_with_index_orientc    Cs>tdddgiƒ}d}tjt|d|jddW5QRXdS)Nr rrz orient 'xinvalid' not understoodr*Zxinvalidrr,r0r#r#r$Útest_to_dict_invalid_orientLsz/TestDataFrameToDict.test_to_dict_invalid_orientrÚdÚlÚrÚspÚsÚic    Cs:tdddgiƒ}tjtdd|j|dW5QRXdS)Nr rrznot understoodr*rr,)rrr1r#r#r$Ú test_to_dict_short_orient_raisesRsz4TestDataFrameToDict.test_to_dict_short_orient_raisesÚmappingcCs|dddœddddœdœ}t|ƒj|d    }| ¡D].\}}| ¡D]\}}||||ks@t‚q@q0t|ƒ d
|¡}| ¡D]6\}}| ¡D]$\}}|||t|ƒdksˆt‚qˆqxt|ƒ d |¡}| ¡D].\}}| ¡D]\}}||||ksØt‚qØqÈt|ƒ d |¡}d dgdddgddgddgtjdggdœ}t ||¡t|ƒ d|¡}dddœdddœtjddœg}    t    |t
ƒs|t‚t |ƒdksŽt‚t ||    ƒD]\}
} t |
| ¡q˜t|ƒ d¡}| ¡D]4\}}| ¡D] \}}||||ksÖt‚q֐qÆt|ƒ} | | j d| d<|  d¡}| ¡} | | j d| d<|  ¡D]4\}}| ¡D] \}}||||ksRt‚qRqBdS)Nrr)Ú1Ú2r=r>Ú3)r=r>r?r ©ÚintoÚlistrrr rçð?ç@)rrrrérrZduped)rrÚitemsrÚintÚnpÚnanrrÚ
isinstancerBÚlenÚziprÚcopy)rr<r Z recons_dataÚkÚvZk2Zv2r"r!ÚleftÚrightr1Z    comp_datar#r#r$Ú test_to_dictYsP ý 
ý
z TestDataFrameToDict.test_to_dictc    CsJttj dd¡ƒ}d ddg¡}tjt|d|j|dW5QRXdS)NrEú|z unsupported type: <class 'list'>z1to_dict\(\) only accepts initialized defaultdictsr*r@)    rrHÚrandomZrandnÚjoinr-r.Ú    TypeErrorr)rr<r1r2r#r#r$Útest_to_dict_errors•sþÿz'TestDataFrameToDict.test_to_dict_errorsc    Cs<tdddggdddgd}t t¡| ¡W5QRXdS)NrrrEr'r(©r)rrZassert_produces_warningÚ UserWarningr)rr1r#r#r$Útest_to_dict_not_unique_warning¢s z3TestDataFrameToDict.test_to_dict_not_unique_warningzorient,item_getterÚdictcCs |||S©Nr#©r5ÚcolÚidxr#r#r$Ú<lambda>¯ózTestDataFrameToDict.<lambda>rcCs |||Sr\r#r]r#r#r$r`°rarBcCs |||Sr\r#r]r#r#r$r`±rarcCs|d||d |¡S)Nrrr)r]r#r#r$r`²rarcCs |||Sr\r#r]r#r#r$r`³racCsRtddgddgdœƒ}|j|d}t||ddƒtƒs8t‚t||d    dƒtƒsNt‚dS)
Nrrgš™™™™™¹?gš™™™™™É?r&rr'rr()rrrJrGrÚfloat)rrZ item_getterr1Úresultr#r#r$Útest_to_dict_box_scalars¬s  z,TestDataFrameToDict.test_to_dict_box_scalarsc Cs¦tdddddddtjdftdddd    d
d d tjdfg}tt|ƒd gd}|jdd}d tdtjdid tdtjdig}t |d|d¡t |d|d¡dS)Niáé ééé5riYX)Útzinfoéééirñr5rXrrz2017-11-18 21:53:00.219225+0000)Útzz2017-11-18 22:06:30.061810+0000r)    rÚpytzÚutcrrBrr
rr)rrr1rcÚexpectedr#r#r$Útest_to_dict_tz¾sþ þz#TestDataFrameToDict.test_to_dict_tzzinto, expectedrrC©Úint_colÚ    float_colrrDrEç@)rrrrcCsdtdddgdddgdœƒ}|jd|d    }d
d g}tj|dd |}tj|dd |}t ||¡dS) NrrrErCrDrurrr)rrArsrtr)rrÚ    from_dictrÚassert_frame_equal)rrArpr1rcÚcolsr#r#r$Útest_to_dict_index_dtypesÏs 'z-TestDataFrameToDict.test_to_dict_index_dtypescCsFtdd„tdƒDƒƒ}t| d¡d ¡ƒ}t|jƒ}||ksBt‚dS)NcSsi|]}t|ƒ|g“qSr#)Ústr©Ú.0r:r#r#r$Ú
<dictcomp>szBTestDataFrameToDict.test_to_dict_numeric_names.<locals>.<dictcomp>érr)rÚrangeÚsetrÚkeysrr©rr1rcrpr#r#r$Útest_to_dict_numeric_namesþs
z.TestDataFrameToDict.test_to_dict_numeric_namescCsFtdd„tdƒDƒƒ}| d¡d}dd„tdƒDƒ}||ksBt‚dS)NcSsi|]}d|d›|g“qS©ZA_r5r#r{r#r#r$r}s
z9TestDataFrameToDict.test_to_dict_wide.<locals>.<dictcomp>érrcSsi|]}d|d›|“qSr„r#r{r#r#r$r}    s
)rrrrr‚r#r#r$Útest_to_dict_widesz%TestDataFrameToDict.test_to_dict_widez
data,dtypeTFiâiãiäÚXÚYÚZcs6td|iƒ}|jdd}t‡fdd„|Dƒƒs2t‚dS)Nr'rrc3s|]}t|dƒˆkVqdS)r'N)Útype)r|Úrecord©Údtyper#r$Ú    <genexpr>"sz@TestDataFrameToDict.test_to_dict_orient_dtype.<locals>.<genexpr>)rrÚallr)rrrr1r5r#rŒr$Útest_to_dict_orient_dtype s  z-TestDataFrameToDict.test_to_dict_orient_dtypezdata,expected_dtypei÷ÿÿÿgš™™™™™ñ?z
2005-02-25cCs>td|idgd}|jdd}t|ddƒ}||ks:t‚dS)Nr'rr)rr)rrrŠr)rrZexpected_dtyper1r5rcr#r#r$Ú,test_to_dict_scalar_constructor_orient_dtype$s  z@TestDataFrameToDict.test_to_dict_scalar_constructor_orient_dtypecCs>tdgdgdœƒ}| ¡ d¡}ddddœg}||ks:t‚dS)NrCg"@r&rr)rr'r()rZ reset_indexrrr‚r#r#r$Ú test_to_dict_mixed_numeric_frame6sz4TestDataFrameToDict.test_to_dict_mixed_numeric_frameNZaaZbbÚccrr&)r'ÚcZn1Zn2)ÚnamesrÚxÚyÚz)r–r)r—rZz1Zz2cCsBtjddgddgg||d}tj|jdddd}t ||¡dS)NrrEré)rrÚtightr)rZ from_recordsrvrrrw)rrrr1Z    roundtripr#r#r$Útest_to_dict_orient_tight=sýz-TestDataFrameToDict.test_to_dict_orient_tightršzdata,expected_typesr')r')r'r(r”r5ÚeÚfgš™™™™™@gffffff
@ZhelloZworldc    sàt|ƒ}| |¡‰|dkr.dd„ˆ ¡Dƒ}nr|dkrJdd„ˆ ¡Dƒ}nV|dkrj‡fdd„ˆdDƒ}n6|d    kr†d
d„tˆƒDƒ}n|dkr d d„ˆ ¡Dƒ}|D]6\}}}||||ksÂt‚t|ƒ|||ks¤t‚q¤dS) Nr[css.|]&\}}| ¡D]\}}|||fVqqdSr\©rF)r|ÚkeyZindex_value_mapr:Úvaluer#r#r$rސs
þzHTestDataFrameToDict.test_to_dict_returns_native_types.<locals>.<genexpr>rBcss.|]&\}}t|ƒD]\}}|||fVqqdSr\©Ú    enumerate)r|rŸÚvaluesr:r r#r#r$rŽ–s
þ>ršrc3s:|]2}tˆdƒD] \}}||ˆd||fVqqdS)rrNr¡)r|r:ÚjrŸ©rcr#r$rŽœsþrrcss.|]&\}}| ¡D]\}}|||fVqqdSr\rž©r|r:r‹rŸr r#r#r$rŽ¢s
þcss.|]&\}}| ¡D]\}}|||fVqqdSr\ržr¦r#r#r$rލs
þ)rrrFr¢rrŠ)    rrrZexpected_typesr1Zassertion_iteratorr:rŸr r#r¥r$Ú!test_to_dict_returns_native_types[s22
þþ
þþþz5TestDataFrameToDict.test_to_dict_returns_native_typesrc    CsNtddgddgdœddgd}d    }tjt|d
|j|d d W5QRXdS) NrrrEr™©Úcol1Úcol2Úrow1Úrow2r)z?'index=False' is only valid when 'orient' is 'split' or 'tight'r*F©rrr,)rrr1r2r#r#r$Útest_to_dict_index_false_error²sz2TestDataFrameToDict.test_to_dict_index_false_errorzorient, expectedr©rªr™)rr)rrÚ column_namescCs<tddgddgdœddgd}|j|d    d
}t ||¡dS) NrrrEr™r¨r«r¬r)Fr­)rrrr©rrrpr1rcr#r#r$Útest_to_dict_index_falseºsz,TestDataFrameToDict.test_to_dict_index_false)rr)rrr)rrrZ index_namesr¯cCs0tddtgidd}|j|d}||ks,t‚dS)Nr'rÚInt64rŒr)rrrrr°r#r#r$Útest_to_dict_na_to_noneÎs z+TestDataFrameToDict.test_to_dict_na_to_nonecCs€ttddgddddœƒ}|jdd}t|dd    ƒtks>t‚ttdtgddddœƒ}|jdd}t|dd    ƒtks|t‚dS)
Nrrr²rŒ)r'rrrrr')rr    rrŠrGrr)rr1rcr#r#r$Ú!test_to_dict_masked_native_pythonès   z5TestDataFrameToDict.test_to_dict_masked_native_python)/Ú__name__Ú
__module__Ú __qualname__r%r3r4r-ÚmarkZ parametrizer;r[rrBrrRrWrZrdrqryrƒr†Úboolrr
rbrGrzrrHZuint64Úint64Úfloat64Zbool_Z
datetime64r‘r’rrÚ from_tuplesr›Útupler§r®r±r³r´r#r#r#r$r sN-
 
;
 
 
 
 
 
 
ûþ
 
ýþ       ýÿþ ýþþíþ"
 
 
 
ýú   ôþ
     ûþ
 
 
 ûþ
 
 ûþ
 
þú    ú÷þþû þþûãþ+ (
ýþþþ
 
ûþ
ñþ
r )Ú collectionsrrrÚnumpyrHr-rnZpandasrrrrr    r
Zpandas._testingZ_testingrr r#r#r#r$Ú<module>s