o
    %gM                     @   s   d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	 ddl
mZmZmZ ddlmZmZmZmZmZmZ ddlmZmZmZ G dd	 d	ZG d
d dZG dd dZdd ZdS )z^Tests suite for mrecords.

:author: Pierre Gerard-Marchant
:contact: pierregm_at_uga_dot_edu

    N)maskednomask)temppath)recarrayfromrecords
fromarrays)MaskedRecords	mrecarrayr   fromtextfiler   addfield)assert_assert_equalassert_equal_recordsc                   @   s   e Zd Zg dZg dZg dZdefdefdgZg dZ	e
jeeeeee	edZd	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'S )(TestMRecords               皙?皙@ffffff
@皙@      @   one   two   three   four   fiveabc|S8r   r   r   r   r   maskdtypec                 C   s   | j }|t}t|j|j t|j|j tt|j	t
 t|j	|j	t
 dD ]}t|| ||  q*t|t| d S )Nr"   r#   r%   )baseviewr	   r   
recordmaskr   _maskr   
isinstance_datar   )selfr,   mbasefield r5   [/root/parts/websockify/install/lib/python3.10/site-packages/numpy/ma/tests/test_mrecords.pytest_byview$   s   
zTestMRecords.test_byviewc                 C   s  | j  }|t}dD ]}tt||||  t|| ||  q|d }tt|t t|j|j t|	 d t|j
t t|j d t|d |d d  |d }tt|t t|j|j t|	 d t|j
d t|j d	 t|d |d d  t|d tu  |d d
 }tt|t t|j|j t|j
ddg t|jtjdd	g|jjd t||d d
 t dD ]}tt|||d d
 |  qd S )Nr+   r   )r   r   r   )FFFr"   )NNNT)TTTr   r   r*   )r,   copyr-   r	   r   getattrr   r0   r*   tolistr.   r   r/   itemr   r   r)   nparray)r2   r,   r3   r4   mbase_first
mbase_lastmbase_slr5   r5   r6   test_get0   sF   

zTestMRecords.test_getc                 C   s  | j  }|t}| }d|_d|jjd d < t|d jg d t|d jg d d|_t|d jdgd  tt	
|d dgd  t|jdgd  t|j tjg d	td
 t|_t|jjdgd  t|jjdgd  tt	
|d dgd  tt	|d dgd  t|j tjg dtd
 |t }d|jdd < t|jg d t|jjg d t|jdd < t|j|d  t|jjg d ddtfg}t	jg d|d
}|t}t	jg dg dd}||d< t|j| t|jjg d d S )N)i?B g@xDN/Ar   r"   )r   r   r   r   r   r'   r   r   F)r   r   r   r   r   r   rE   rE   rF   r9   r%      N/A)r   r   r   rF   rH   rH   rF   r   r   r   r   r   r   )r   r   r   r   r   r#   r   r   r   r   r   )alphaz|S1num))r"   r   )r#   r   )r%   r   )
         r   r   r   r)   )r,   r:   r-   r	   
fill_valuer"   r1   r   r/   magetmaskarrayr.   r<   r>   r?   boolr   r%   r)   getdatar#   intr   rL   )r2   r,   r3   ndtypedatardatavalr5   r5   r6   test_set_fieldsX   sP   






zTestMRecords.test_set_fieldsc                 C   s   | j  }|t}t|d d< t|jg d t|jjg d tt	
dt	jdgdtfdtfgd}t|d d< t|jg d t|jjg d	 d S )
Nr"   r   rJ   r   r#   r9   )r   r   r   r   r   )r   r   r   r   r   )r,   r:   r-   r	   r   r   r"   r/   r   r>   arangerandomrandrW   floatr2   r,   r3   r5   r5   r6   test_set_fields_mask   s   

z!TestMRecords.test_set_fields_maskc                 C   s   | j  }|t}t|_tt|d dgd  t|d j	|d j	 t|d j	|d j	 t|j	
 tjdgd td t|_tt|d dgd  t|j	
 tjd	gd td d S )
Nr#   r   r   r"   r%   r   r   r   r9   r   rE   )r,   r:   r-   r	   r   r)   r   rS   rT   r/   r<   r>   r?   rU   r   rb   r5   r5   r6   test_set_mask   s   



zTestMRecords.test_set_maskc                 C   s   | j  }|t}g d|_t|jjg d t|jjg d t|jjg d g d|_t|jjg d t|jjg d t|jjg d d S )N)r   r   r   r   r   r   r   r   r   r   )	r,   r:   r-   r	   r)   r   r"   r#   r%   rb   r5   r5   r6   test_set_mask_fromarray   s   



z$TestMRecords.test_set_mask_fromarrayc                 C   s   | j  t}tjg ddtfdtfdtfgd}||_t|j	jg d t|j
jg d t|jjg d d|_||_t|j	jg d t|j
jg d t|jjg d d S )	N)r   r   r   rh   r   r   r   ri   rE   r"   r#   r%   r9   )r   r   r   r   r   )r   r   r   r   r   F)r,   r:   r-   r	   r>   r?   rU   r)   r   r"   r#   r%   	fieldmask)r2   r3   nmaskr5   r5   r6   test_set_mask_fromfields   s   z%TestMRecords.test_set_mask_fromfieldsc                 C   s^  | j  }|t }t|d< t|j tj	g dt
d t|jg d |t }d|d d< t|jjg d t|jjg d t|jjg d	 t|jjg d t|jjg d
 t|jjg d |t }t|d d< t|jjg d t|jjg d t|jjg d t|jjg d t|jjg d t|jjg d d S )Nr]   )rE   rd   rE   rd   rd   r9   rJ   r   r   r   r   )r   r   r   r   r   rf   )      @rn   r   r   r   )   5ro   r   r    r!   r   )r   r   r   r   r   r   r   )r,   r:   r-   r	   r   r   r/   r<   r>   r?   rU   r.   r"   r1   r#   r%   rb   r5   r5   r6   test_set_elements   s<   

zTestMRecords.test_set_elementsc              	   C   s   | j  }|t}|  zAd|dd < t|jjg d t|jjg d t|j	jg d t|jj
g d t|jj
|jj
 t|jj
|j	j
 W td tyX   Y n ty_    w zd|dd < W td	 ttfyw   Y d S w )
Nrm   r]   rI   )r   r   r   r   r   )r   r   r   ro   r!   r'   z)Flexible hard masks should be supported !r   z.Should have expected a readable buffer object!)r,   r:   r-   r	   harden_maskr   r"   r1   r#   r%   r/   NotImplementedErrorAssertionError	Exception	TypeErrorrb   r5   r5   r6   test_setslices_hardmask   s2   

z$TestMRecords.test_setslices_hardmaskc                 C   s   | j  }|t}|  t|j t|_t	|j
|j
 |  t|j  t|_t	|j
t|j|j tt|d j
tu  t|d j
|d j
 d S )Nr#   r"   )r,   r:   r-   r	   rq   r   	_hardmaskr   r)   r   r/   soften_maskrS   make_mask_noneshaper*   	make_maskr   rb   r5   r5   r6   test_hardmask
  s   


zTestMRecords.test_hardmaskc                 C   s~   | j  }|t}tdtjd D ]*}tj||d}t|}t	|j
|j
 t|j|j t	|j|j t|j|j qd S )Nr   r   )protocol)r,   r:   r-   r	   rangepickleHIGHEST_PROTOCOLdumpsloadsr   r*   r   r1   r/   )r2   r,   mrecproto_mrec_r5   r5   r6   test_pickling  s   


zTestMRecords.test_picklingc                 C   s   t jg dg dtd}t jg dg dtd}t jg dg ddd}dtfdtfd	g}t|||g|d
d}| }t|d tjdtd t|d tjdtd t|d tjddd d S )Nr   r   r   rH   r(   r   r   r   onetwothreer&   r"   r#   r$   韆     i@rD   r*   rR   )r   r   r   r9   )r   r   r   r%   )r   r   rD   )rS   r?   rW   ra   r   filledr   r>   )r2   _a_b_cddtyper   
mrecfilledr5   r5   r6   test_filled'  s   zTestMRecords.test_filledc                 C   s   t jg dg dtd}t jg dg dtd}t jg dg ddd}dtfd	tfd
g}t|||g|dd}t| g d d S )Nr   rH   r(   r   r   rP   r&   r"   r#   r$   r   r   ))r   r   N)r   r   r   )NNr   )rS   r?   rW   ra   r   r   r<   )r2   r   r   r   r   r   r5   r5   r6   test_tolist6  s   zTestMRecords.test_tolistc                 C   s0   t dtdd}d|d d< t|d d d d S )Nr   r,   )formatsnamesrM   r   )r	   ra   r   )r2   xr5   r5   r6   test_withnamesC  s   zTestMRecords.test_withnamesc                 C   s   t ddtfddtfgd}t|d< t|d d t ddgd}t|d< t|d tjd	|j	d  t d
dd}t|d< d|d< |d t
|dtjddg|j	d d S )Nr   i)sr&   fr9   r   )r      1g      ?)f0z<f8)r   r   )r   r   zi4, (2,3)float, floatrd   rE   )r	   rW   ra   r   r   r   r=   r>   r?   r*   r   )r2   easysolomultr5   r5   r6   test_exotic_formatsI  s"   


z TestMRecords.test_exotic_formatsN)__name__
__module____qualname__ilistflistslistrW   ra   r   r)   rS   r?   listzipr,   r7   rC   r\   rc   re   rg   rl   rp   rv   r|   r   r   r   r   r   r5   r5   r5   r6   r      s,    (7 r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestViewc                 C   sn   t dt jd}}dtfdtfg}t jtt|||d}t||g|dd}d|j	d< ||||f| _
d S )	NrM   r"   r#   r9   )g      "g     Xr   )FTr   )r>   r^   r_   r`   ra   r?   r   r   r   r)   rY   )r2   r"   r#   rX   arrr   r5   r5   r6   setup_method_  s   
zTestView.setup_methodc                 C   s@   | j \}}}}| }tt|t t|| t|j|j d S )N)rY   r-   r   r0   r   r   r/   )r2   r   r"   r#   r   testr5   r5   r6   test_view_by_itselfh  s
   
zTestView.test_view_by_itselfc                 C   sd   | j \}}}}tdf}||}tt|tj t|tj	t
t||td t|d tju  d S )Nr   r9   )r   r   )rY   ra   r-   r   r0   rS   MaskedArrayr   r>   r?   r   r   r   )r2   r   r"   r#   r   ntyper   r5   r5   r6   test_view_simple_dtypeo  s   
zTestView.test_view_simple_dtypec                 C   s~   | j \}}}}dtfdtfg}||}tt|t t||| t|d d tu  t|j	t
	| t|jd u  d S )NABr   )rY   ra   r-   r   r0   r   r   r   r   r*   r>   _fill_value)r2   r   r"   r#   r   alttyper   r5   r5   r6   test_view_flexible_typew  s   
z TestView.test_view_flexible_typeN)r   r   r   r   r   r   r   r5   r5   r5   r6   r   ]  s
    	r   c                   @   s   e Zd Zejg dg dedZejg dg dedZejg dg dddZ	defdefd	gZ
eeee	ge
d
dZeejeje	jfe
dZeee
fZdd Zdd Zdd Zdd Zdd ZdS )TestMRecordsImportr   rH   r(   r   )r   r   r   r&   r"   r#   r$   )s   99999s   99999.rG   r   r9   c           
      C   s   t jg dg dtd}t jg dg dtd}t jg dg ddd}| j\}}}td|||fD ]\}}tt||j|j q2t jg dg d	t	d}	t
t|	|jd
|d  d S )Nr   rH   r(   r   r   r&   r+   )r   r   r   rP   r9   r   )rS   r?   rW   ra   rY   r   r   r;   r/   objectr   r   r*   )
r2   r   r   r   r   nrecr   r   l_xr5   r5   r6   test_fromarrays  s   z"TestMRecordsImport.test_fromarraysc                 C   s   | j \}}}g d}t|dd}t|dd}t|| t|}t|j|j |jjD ]}tt||t|j| q*t|	 dd}t|jdt
fdtfdg tdd	D ]\}	}
tt||	t|j|
 qSt|}t|j|j t|j|  t|j|j d S )
N))r   abcg   @r   )r   xyg   @r   )r    g   ?r   zc1, c2, c3, c4)r   zc1,c2,c3c1c2)c3z|S5)r   r   r   r+   )rY   recfromrecordsr   r   r   r*   r   r;   r1   r<   rW   ra   r   r   r/   )r2   r   r   r   palistpampa_mrecr4   r   nr5   r5   r6   test_fromrecords  s"   
z#TestMRecordsImport.test_fromrecordsc                 C   s   | j \}}}t| |g dd}t|j|j t|j g d t| |dd}t|j|j t|j g d t| ||jd}t|j|j t|j |j  t| ||j d}t|j|j t|j |j  d S )Nrh   )r*   r)   )rE   rd   rE   T)rd   rd   rd   )rY   r   r<   r   r1   r   r/   )r2   r   r   r   r   r5   r5   r6   test_fromrecords_wmask  s   
z)TestMRecordsImport.test_fromrecords_wmaskc              	   C   s   d}t  )}t|d}|| W d    n1 sw   Y  t|ddd}W d    n1 s1w   Y  tt|t t|jg d t|j	j
g d t|jg d d S )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,ABCDEFG)	delimitervarnames)r   r   r   r   )r   r   g    OAg|۽)r   openwriter
   r   r0   r   r   FEr/   C)r2   fcontentpathr   mrectxtr5   r5   r6   test_fromtextfile  s   z$TestMRecordsImport.test_fromtextfilec                 C   sP   | j \}}}g dg d}}t|tj||d}t|j| t|jj| d S )N)d      i,  rP   rQ   )rY   r   rS   r?   r   f3r/   )r2   r   r   r   dmr5   r5   r6   test_addfield  s
   z TestMRecordsImport.test_addfieldN)r   r   r   rS   r?   rW   r   ra   r   r   r   r   r   recfromarraysr1   r   rY   r   r   r   r   r   r5   r5   r5   r6   r     s"    

r   c                  C   s0   t jddgddgdtfdtfgd} | d  d S )	N)r   2)r   4)r   r   )r   r   r"   r#   r(   r   )rS   masked_arrayrW   r   )yr5   r5   r6   #test_record_array_with_object_field  s   r   )__doc__r   numpyr>   numpy.marS   r   r   numpy.testingr   numpy._core.recordsr   r   r   r   r   numpy.ma.mrecordsr   r	   r
   r   numpy.ma.testutilsr   r   r   r   r   r   r   r5   r5   r5   r6   <module>   s      D&c