a :jgM@sdZddlZddlZddlmZddlmZmZddlm Z ddl m Z m Z mZddlmZmZmZmZm Z mZddlmZmZmZGdd d ZGd d d ZGd d d ZddZdS)z^Tests suite for mrecords. :author: Pierre Gerard-Marchant :contact: pierregm_at_uga_dot_edu N)maskednomask)temppath)recarray fromrecords fromarrays) MaskedRecords mrecarrayr fromtextfileraddfield)assert_ assert_equalassert_equal_recordsc@seZdZgdZgdZgdZdefdefdgZgdZ e j e e eeee edZd d Zd d Zd dZddZddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'S)( TestMRecords皙?皙@ffffff @皙@@onetwothreefourfiveabc|S8rrrrrmaskdtypecCs|j}|t}t|j|jt|j|jtt|j t t|j |j t dD]}t||||qTt|t|dS)Nr"r#r%) baseviewr r recordmaskr_maskr isinstance_datar)selfr,mbasefieldr5F/usr/local/lib/python3.9/site-packages/numpy/ma/tests/test_mrecords.py test_byview$s zTestMRecords.test_byviewcCs|j}|t}dD]*}tt||||t||||q|d}tt|tt|j|jt| dt|j t t|j dt|d|dd|d}tt|tt|j|jt| dt|j dt|j d t|d|ddt|dtu|dd }tt|tt|j|jt|j dd gt|jtjdd g|j jd t||dd tdD]"}tt|||dd |qdS) Nr+r)rrr)FFFr")NNNT)TTTrrr*)r,copyr-r r getattrr r0r*tolistr.rr/itemrrr)nparray)r2r,r3r4Z mbase_firstZ mbase_lastZmbase_slr5r5r6test_get0sD     zTestMRecords.test_getcCs|j}|t}|}d|_d|jjdd<t|djgdt|djgdd|_t|djdgdtt |ddgdt|j dgdt|j t jgd td t|_t|jjdgdt|jj dgdtt |d dgdtt |d d gdt|j t jgd td |t}d|jdd<t|jgdt|jjgdt|jdd<t|j|dt|jjgdddtfg}t jgd|d }|t}t jgdgdd}||d<t|j|t|jjgddS)N)i?Bg@xDN/Arr")rrrrrr'rrF)rrrrrrrBrBrCr9r%N/A)rrrrCrErErCrrrrrr)rrrrrr#rrrrr)alphaz|S1num))r"r)r#r)r%r) rrrr))r,r:r-r fill_valuer"r1r r/ma getmaskarrayr.r<r>r?boolrr%r)Zgetdatar#intrrI)r2r,r3ndtypedataZrdatavalr5r5r6test_set_fieldsXsP         zTestMRecords.test_set_fieldscCs|j}|t}t|dd<t|jgdt|jjgdtt dt j dgdt fdtfgd}t|dd<t|jgdt|jjgd dS) Nr"rrGrr#r9)rrrrr)rrrrr)r,r:r-r rr r"r/rr>arangerandomrandrSfloatr2r,r3r5r5r6test_set_fields_masks    z!TestMRecords.test_set_fields_maskcCs|j}|t}t|_tt|ddgdt|dj |dj t|dj |dj t|j t j dgdt dt|_tt|ddgdt|j t j d gdt ddS) Nr#rrr"r%rrrr9rrB)r,r:r-r rr)r rPrQr/r<r>r?rRrr]r5r5r6 test_set_masks    zTestMRecords.test_set_maskcCs|j}|t}gd|_t|jjgdt|jjgdt|jjgdgd|_t|jjgdt|jjgdt|jjgddS)N)rrrrrrrrrr) r,r:r-r r)r r"r#r%r]r5r5r6test_set_mask_fromarrays    z$TestMRecords.test_set_mask_fromarraycCs|jt}tjgddtfdtfdtfgd}||_t|j jgdt|j jgdt|j jgdd|_||_ t|j jgdt|j jgdt|j jgddS) N)rrrrcrrrrdrBr"r#r%r9)rrrrr)rrrrrF) r,r:r-r r>r?rRr)r r"r#r%Z fieldmask)r2r3Znmaskr5r5r6test_set_mask_fromfieldssz%TestMRecords.test_set_mask_fromfieldscCs^|j}|t}t|d<t|jtj gdt dt|j gd|t}d|dd<t|j j gdt|j jgdt|jj gd t|jjgdt|jj gd t|jjgd|t}t|dd<t|j j gd t|j jgd t|jj gd t|jjgd t|jj gdt|jjgd dS)NrX)rBr_rBr_r_r9rGrrrr)rrrrrra)@rgrrr)5rhrr r!r)rrrrrrr)r,r:r-r rr r/r<r>r?rRr.r"r1r#r%r]r5r5r6test_set_elementss<    zTestMRecords.test_set_elementsc Cs|j}|t}|z|d|dd<t|jjgdt|jjgdt|j jgdt|jj gdt|jj |jj t|jj |j j Wn$t yYnt yYn 0t dzd|dd<Wnt tfyYn 0td dS) NrfrXrF)rrrrr)rrrrhr!r'z)Flexible hard masks should be supported !rz.Should have expected a readable buffer object!)r,r:r-r harden_maskr r"r1r#r%r/NotImplementedErrorAssertionError Exception TypeErrorr]r5r5r6test_setslices_hardmasks.     z$TestMRecords.test_setslices_hardmaskcCs|j}|t}|t|jt|_t |j |j | t|j t|_t |j t |j|jtt |dj tut|dj |dj dS)Nr#r")r,r:r-r rjr Z _hardmaskrr)rr/Z soften_maskrPZmake_mask_noneshaper*Z make_maskr r]r5r5r6 test_hardmask s    zTestMRecords.test_hardmaskcCs~|j}|t}tdtjdD]T}tj||d}t|}t |j |j t |j |j t |j |j t |j |j q$dS)Nrr)protocol)r,r:r-r rangepickleHIGHEST_PROTOCOLdumpsloadsr r*rr1r/)r2r,mrecproto_Zmrec_r5r5r6 test_picklings   zTestMRecords.test_picklingcCstjgdgdtd}tjgdgdtd}tjgdgddd}dtfdtfd g}t|||g|d d }|}t|dtjd td t|dtjdtd t|dtjddd dS)NrrrrEr(rrronetwothreer&r"r#r$韆i@rAr*rO)rrrr9)rrrr%)rrrA)rPr?rSr\rfilledr r>)r2_a_b_cddtyperxZ mrecfilledr5r5r6 test_filled's zTestMRecords.test_filledcCstjgdgdtd}tjgdgdtd}tjgdgddd}dtfd tfd g}t|||g|d d }t|gd dS)Nr|rEr(r}r~rMr&r"r#r$rr))rrN)rrr)NNr)rPr?rSr\rr r<)r2rrrrrxr5r5r6 test_tolist6s zTestMRecords.test_tolistcCs0tdtdd}d|dd<t|ddddS)Nrr,)formatsnamesrJr)r r\r )r2xr5r5r6test_withnamesCs zTestMRecords.test_withnamescCstddtfddtfgd}t|d<t|ddtddgd}t|d<t|dtjd |j dtd d d}t|d<d |d<|dt |dtjd d g|j ddS)Nri)sr&fr9r)r1g?)Zf0zr?r*r)r2ZeasyZsoloZmultr5r5r6test_exotic_formatsIs"    z TestMRecords.test_exotic_formatsN)__name__ __module__ __qualname__ZilistflistslistrSr\rr)rPr?listzipr,r7r@rWr^r`rbrerirorqr{rrrrr5r5r5r6rs* (7   rc@s,eZdZddZddZddZddZd S) TestViewcCsntdtjd}}dtfdtfg}tjtt|||d}t||g|dd}d|j d<||||f|_ dS) NrJr"r#r9)g"gXr)FTr) r>rYrZr[r\r?rrrr)rU)r2r"r#rTarrrxr5r5r6 setup_method_s  zTestView.setup_methodcCs@|j\}}}}|}tt|tt||t|j|jdS)N)rUr-r r0rrr/)r2rxr"r#rtestr5r5r6test_view_by_itselfhs  zTestView.test_view_by_itselfcCsd|j\}}}}tdf}||}tt|tjt|tj t t ||tdt|dtj udS)Nrr9)rr) rUr\r-r r0rPZ MaskedArrayr r>r?rrr)r2rxr"r#rZntyperr5r5r6test_view_simple_dtypeos  zTestView.test_view_simple_dtypecCs~|j\}}}}dtfdtfg}||}tt|tt|||t|ddtut|j t |t|j dudS)NABr) rUr\r-r r0rrrr r*r>Z _fill_value)r2rxr"r#rZalttyperr5r5r6test_view_flexible_typews z TestView.test_view_flexible_typeN)rrrrrrrr5r5r5r6r]s rc@seZdZejgdgdedZejgdgdedZejgdgdddZ defdefd gZ e eee ge d d Z e ejeje jfe d Ze ee fZd dZddZddZddZddZdS)TestMRecordsImportr|rEr(r})rrrr&r"r#r$)s99999s99999.rDrr9c Cstjgdgdtd}tjgdgdtd}tjgdgddd}|j\}}}td|||fD]\}}tt||j|jqdtjgdgd t d} t t | |j d |d dS) Nr|rEr(r}r~r&r+)rrrrMr9r) rPr?rSr\rUrr r;r/objectrrr*) r2rrrrxnrecrzrlZ_xr5r5r6test_fromarrayss z"TestMRecordsImport.test_fromarraysc Cs|j\}}}gd}t|dd}t|dd}t||t|}t|j|j|jjD]}tt||t|j|qTt| dd}t|jdt fdt fdgt dd D] \} } tt|| t|j| qt|}t|j|jt|j| t|j|jdS) N))rabcg @r)rZxyg@r)r g?rzc1, c2, c3, c4)rzc1,c2,c3c1c2)c3z|S5)rrrr+)rUrecfromrecordsrrr r*rr;r1r<rSr\rrr/) r2rxrrZpalistpampa_mrecr4rnr5r5r6test_fromrecordss"     z#TestMRecordsImport.test_fromrecordscCs|j\}}}t||gdd}t|j|jt|jgdt||dd}t|j|jt|jgdt|||jd}t|j|jt|j|jt|||jd}t|j|jt|j|jdS)Nrc)r*r))rBr_rBT)r_r_r_)rUrr<rr1r r/)r2rxrrrr5r5r6test_fromrecords_wmasks  z)TestMRecordsImport.test_fromrecords_wmaskc Csd}tR}t|d}||Wdn1s60Yt|ddd}Wdn1sb0Ytt|tt|jgdt|j j gdt|j gddS)Nz# 'One (S)','Two (I)','Three (F)','Four (M)','Five (-)','Six (C)' 'strings',1,1.0,'mixed column',,1 'with embedded "double quotes"',2,2.0,1.0,,1 'strings',3,3.0E5,3,,1 'strings',4,-1e-10,,,1 w,ZABCDEFG) delimitervarnames)rrrr)rrgOAg|۽) ropenwriter r r0rr FEr/C)r2ZfcontentpathrZmrectxtr5r5r6test_fromtextfiles (,z$TestMRecordsImport.test_fromtextfilecCsP|j\}}}gdgd}}t|tj||d}t|j|t|jj|dS)N)di,rMrN)rUr rPr?r Zf3r/)r2rxrrdmr5r5r6 test_addfields   z TestMRecordsImport.test_addfieldN)rrrrPr?rSrr\rrrrrx recfromarraysr1rrUrrrrrr5r5r5r6rs     rcCs0tjddgddgdtfdtfgd}|ddS) N)r2)r4)rr)rrr"r#r(r)rPZ masked_arrayrSr)yr5r5r6#test_record_array_with_object_fields r)__doc__rtnumpyr>Znumpy.marPrrZ numpy.testingrZnumpy._core.recordsrrrrrZnumpy.ma.mrecordsrr r r Znumpy.ma.testutilsr r rrrrrr5r5r5r6s   D&c