a
    yn„fú  ã                   @  s®   d dl mZ d dlmZmZ d dlmZ d dlZd dl	m
Z
 d dlmZ d dlmZmZmZmZmZ d dlmZ d d	lmZmZmZ d
Ze ¡ ZeG dd„ de
e eƒƒZdS )é    )Úannotations)ÚCallableÚIterable)ÚpermutationsN)Ú	UnionMeta)ÚNumpyMetadata)ÚAnyÚDTypeÚIteratorÚSelfÚfinal)ÚUNSET)ÚFormÚ_SpecifierMatcherÚindex_to_dtype)Ú	UnionFormc                   @  sî   e Zd Zdddœdd„Zedd„ ƒZedd„ ƒZed	d
„ ƒZeeefeedœdd„Z	e
dddœdd„ƒZdd„ Zdd„ Zdd„ Zedd„ ƒZdd„ Zdddœdd„Zddd œd!d"„Zd#d$„ Zd%d&„ Zd'dd(d)œd*d+„Zd,dddd-œd.d/„ZdS )0r   N©Ú
parametersÚform_keyc                C  sº   t |tƒs"tt| ƒj› d|›�ƒ‚t |tƒsDtt| ƒj› d|›�ƒ‚t |tƒsftt| ƒj› d|›�ƒ‚|D ]&}t |tƒsjtt| ƒj› d|›�ƒ‚qj|| _|| _t	|ƒ| _
| j||d� d S )Nz! 'tags' must be of type str, not z" 'index' must be of type str, not z" 'contents' must be iterable, not z- all 'contents' must be Form subclasses, not r   )Ú
isinstanceÚstrÚ	TypeErrorÚtypeÚ__name__r   r   Ú_tagsÚ_indexÚlistÚ	_contentsÚ_init)ÚselfÚtagsÚindexÚcontentsr   r   Úcontent© r$   úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/forms/unionform.pyÚ__init__   s*    	
ÿ
ÿ
ÿ
ÿ
zUnionForm.__init__c                 C  s   | j S ©N)r   ©r   r$   r$   r%   r    6   s    zUnionForm.tagsc                 C  s   | j S r'   )r   r(   r$   r$   r%   r!   :   s    zUnionForm.indexc                 C  s   | j S r'   )r   r(   r$   r$   r%   r"   >   s    zUnionForm.contentsc                C  sX   t |tu r| jn||tu r | jn||tu r0| jn||tu r@| jn||tu rP| jn|d�S )Nr   )r   r   r   r   r   Ú_parametersÚ	_form_key)r   r    r!   r"   r   r   r$   r$   r%   ÚcopyB   s    	ûzUnionForm.copyc                C  s2   t jjjt j |¡t j |¡dd„ |D ƒ|d�jS )Nc                 S  s   g | ]}|  ¡ ‘qS r$   )Úlength_zero_array©Ú.0Úxr$   r$   r%   Ú
<listcomp>`   ó    z(UnionForm.simplified.<locals>.<listcomp>©r   )Úakr"   Ú
UnionArrayÚ
simplifiedr!   Ú_form_to_zero_lengthÚform)Úclsr    r!   r"   r   r   r$   r$   r%   r5   S   s    


üzUnionForm.simplifiedc                 C  s   |   ¡  tj |¡|¡jS r'   )r,   Ú_union_of_optionarraysr3   r!   r6   r7   )r   r!   r   r$   r$   r%   r9   d   s    ÿÿz UnionForm._union_of_optionarraysc                 C  s<   t | jƒt | jƒt | jƒg|  ¡ ¢}d t| ƒjd |¡¡S )Nz{}({})z, )	Úreprr   r   r   Z
_repr_argsÚformatr   r   Újoin)r   Úargsr$   r$   r%   Ú__repr__k   s    ýüzUnionForm.__repr__c                   s*   |   d| j| j‡ fdd„| jD ƒdœˆ ¡S )Nr4   c                   s   g | ]}|j ˆ d d�‘qS )F)Útoplevel)Ú_to_dict_part©r.   r#   ©Úverboser$   r%   r0   z   s   ÿz+UnionForm._to_dict_part.<locals>.<listcomp>)Úclassr    r!   r"   )Z_to_dict_extrar   r   r   )r   rC   r?   r$   rB   r%   r@   t   s    
þü	özUnionForm._to_dict_partc                 C  s   t jjdd„ | jD ƒ| jd�S )Nc                 S  s   g | ]
}|j ‘qS r$   )r   r-   r$   r$   r%   r0   …   r1   z"UnionForm.type.<locals>.<listcomp>r2   )r3   ÚtypesZ	UnionTyper   r)   r(   r$   r$   r%   r   ‚   s    þzUnionForm.typec                 C  s4   t | j| jƒD ] \}}| g |¢|‘R ||¡ qd S r'   )Úzipr   ÚfieldsÚ_columns)r   ÚpathÚoutputZlist_indicatorr#   Úfieldr$   r$   r%   rH   ‰   s    zUnionForm._columnsÚboolzForm | None)Úis_inside_record_or_unionÚreturnc                 C  sx   g }| j D ]"}| d¡}|d u r"q
| |¡ q
t|ƒdkrT|rBd S tjj| jd�S n t|ƒdkrh|d S | j|d�S d S )NTr   )r   é   ©r"   )	r   Ú_prune_columnsÚappendÚlenr3   ZformsZ	EmptyFormr*   r+   )r   rM   r"   r#   Znext_contentr$   r$   r%   rQ   �   s    

zUnionForm._prune_columnsr   r   )Úmatch_specifierrN   c                   s    ‡ fdd„| j D ƒ}| j|d�S )Nc                   s   g | ]}|  ˆ ¡‘qS r$   )Ú_select_columnsrA   ©rT   r$   r%   r0   ¡   s   z-UnionForm._select_columns.<locals>.<listcomp>rP   )r   r+   )r   rT   r"   r$   rV   r%   rU       s    
ÿzUnionForm._select_columnsc                 C  s   t dd„ | jD ƒdƒS )Nc                 s  s   | ]}|  ¡ V  qd S r'   )Ú_column_typesr-   r$   r$   r%   Ú	<genexpr>¨   r1   z*UnionForm._column_types.<locals>.<genexpr>r$   )Úsumr   r(   r$   r$   r%   rW   §   s    zUnionForm._column_typesc                 C  sP   t |tƒr| j |¡ n4|\}}}}}}|d ur8d| }| j|||||d� d S )Nzpart0-r   )r   ÚdictÚ__dict__Úupdater&   )r   ÚstateZhas_identitiesr   r   r    r!   r"   r$   r$   r%   Ú__setstate__ª   s    

ÿzUnionForm.__setstate__zCallable[[Form, str], str]zIterator[tuple[str, DType]])ÚgetkeyÚ	recursiverN   c                 c  sR   || dƒt | j fV  || dƒt | j fV  |rN| jD ]}| ||¡E d H  q6d S )Nr    r!   )r   r   r   r   Ú_expected_from_buffers)r   r_   r`   r#   r$   r$   r%   ra   »   s
    
z UnionForm._expected_from_buffersr   )ÚotherÚall_parametersr   rN   c                   sZ   ˆ  |ˆ ˆ¡oXˆj|jkoXˆj|jkoXtˆjƒt|jƒkoXt‡ ‡‡fdd„t	|jƒD ƒƒS )Nc                 3  s.   | ]&}t ‡ ‡fd d„tˆj|ƒD ƒƒV  qdS )c                 3  s    | ]\}}|  |ˆ ˆ¡V  qd S r'   )Ú_is_equal_to)r.   r/   Úy)rc   r   r$   r%   rX   Ë   s   ÿz3UnionForm._is_equal_to.<locals>.<genexpr>.<genexpr>N)ÚallrF   r   )r.   Úc©rc   r   r   r$   r%   rX   Ê   s   ü
þz)UnionForm._is_equal_to.<locals>.<genexpr>)
Z_is_equal_to_genericr   r    r   r!   rS   r   r"   Úanyr   )r   rb   rc   r   r$   rh   r%   rd   Ä   s    
ÿ
þýûûzUnionForm._is_equal_to)r   Ú
__module__Ú__qualname__r&   Úpropertyr    r!   r"   r   r+   Úclassmethodr5   r9   r>   r@   r   rH   rQ   rU   rW   r^   ra   rd   r$   r$   r$   r%   r      s@   ù 


üùù	
	r   )Ú
__future__r   Úcollections.abcr   r   Ú	itertoolsr   Zawkwardr3   Zawkward._meta.unionmetar   Zawkward._nplikes.numpy_liker   Zawkward._typingr   r	   r
   r   r   Zawkward._utilr   Zawkward.forms.formr   r   r   Ú__all__ÚinstanceÚnpr   r$   r$   r$   r%   Ú<module>   s   