a
    yn„f“7  ã                   @  sh  d dl mZ d dlmZmZmZ d dlZd dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZmZ d dlmZ d dlmZ d dlmZ d dlm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& d dl'm(Z( d dl)m*Z*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 e �r>d dlm7Z7 e 8¡ Z9e 8¡ Z:e&G dd„ dee+ƒƒZ;dS )é    )Úannotations)ÚMappingÚMutableMappingÚSequenceN)ÚBackend)ÚNumpyBackend)ÚTypeTracerBackend)Úmaybe_posaxis)Ú	EmptyMeta)Ú	ArrayLike)ÚNumpy)Ú	IndexTypeÚNumpyMetadata)Ú	ShapeItem)Úis_integer_like)ÚNO_HEAD)ÚTYPE_CHECKINGÚAnyÚCallableÚFinalÚSelfÚSupportsIndexÚfinal)ÚUNSET)ÚApplyActionOptionsÚContentÚImplementsApplyActionÚRemoveStructureOptionsÚToArrowOptions)Ú	AxisError)Ú	EmptyForm)ÚForm)ÚIndex)Ú	SliceItemc                   @  s°  e Zd ZU dZdddœdd„ZeZded< eedœdd	„Z	d
d„ Z
dd„ Zedddœdd„ƒZdddœdd„Zddddddœdd„Zdddœd d!„Zdd"œd#d$„Zdd"œd%d&„Zed'd(œd)d*„ƒZd+d,„ Zd-d.„ Zd›d/d0„Zd1d2„ Zd3d4„ Zdd(œd5d6„Zd7d8œd9d:„Zd7d7d;d<œd=d>„Zdœd@dAd;dBœdCdD„Zd�dEdAd;dBœdFdG„ZdHdd dIœdJdK„ZdHdHd;d;dLœdMdN„Z dOdPdQd;dRœdSdT„Z!dUdUdVdWœdXdY„Z"d;dddZœd[d\„Z#d]d;d^œd_d`„Z$d;d;daœdbdc„Z%ddde„ Z&dfdg„ Z'dhdi„ Z(djdk„ Z)dldm„ Z*dndo„ Z+dpdq„ Z,drds„ Z-dtdu„ Z.dvdw„ Z/dxdy„ Z0dzd{d{dUd|d}œd~d„Z1ed€d�„ ƒZ2d‚dƒ„ Z3dd„d…d†œd‡dˆ„Z4d‰dUdŠdŠd‹d{dŒœd�dŽ„Z5džddd�œd‘d’„Z6d“d”„ Z7ddd•œd–d—„Z8dddddd˜œd™dš„Z9dS )ŸÚ
EmptyArraya?  
    An EmptyArray is used whenever an array's type is not known because it is empty
    (such as data from #ak.ArrayBuilder without enough sample points to resolve the
    type).

    Unlike all other Content subclasses, EmptyArray cannot contain any parameters
    (parameter values are always None).

    EmptyArray has no equivalent in Apache Arrow.

    To illustrate how the constructor arguments are interpreted, the following is a
    simplified implementation of `__init__`, `__len__`, and `__getitem__`:

        class EmptyArray(Content):
            def __init__(self):
                pass

            def __len__(self):
                return 0

            def __getitem__(self, where):
                if isinstance(where, int):
                    assert False

                elif isinstance(where, slice) and where.step is None:
                    return EmptyArray()

                elif isinstance(where, str):
                    raise ValueError("field " + repr(where) + " not found")

                else:
                    raise AssertionError(where)
    N©Ú
parametersÚbackendc                C  sH   |d u s(t |ƒdks(tt| ƒj› d�ƒ‚|d u r8t ¡ }|  ||¡ d S )Nr   ú cannot contain parameters)ÚlenÚ	TypeErrorÚtypeÚ__name__r   ÚinstanceÚ_init©Úselfr&   r'   © r1   ú^/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/contents/emptyarray.pyÚ__init__U   s
    zEmptyArray.__init__r   Úform_clsc                C  sH   |t u s0|d u s0t|ƒdks0tt| ƒj› d�ƒ‚t|t u r@| jn|d�S ©Nr   r(   ©r'   )r   r)   r*   r+   r,   r$   Ú_backendr/   r1   r1   r2   Úcopy^   s
    ÿzEmptyArray.copyc                 C  s   |   ¡ S ©N©r8   ©r0   r1   r1   r2   Ú__copy__j   s    zEmptyArray.__copy__c                 C  s   |   ¡ S r9   r:   )r0   Úmemor1   r1   r2   Ú__deepcopy__m   s    zEmptyArray.__deepcopy__c                C  s.   |d u s$t |ƒdks$t| j› d�ƒ‚| |d�S r5   )r)   r*   r,   )Úclsr&   r'   r1   r1   r2   Ú
simplifiedp   s    zEmptyArray.simplifiedzCallable[[Content], str | None]r    )ÚgetkeyÚreturnc                 C  s   | j || ƒd�S )N)Zform_key)r4   )r0   rA   r1   r1   r2   Ú_form_with_keyv   s    zEmptyArray._form_with_keyr!   z#Callable[[Content, Form, str], str]zMutableMapping[str, ArrayLike]r   Ústr)ÚformrA   Ú	containerr'   Ú	byteorderc                 C  s   t || jƒsJ ‚d S r9   )Ú
isinstancer4   )r0   rE   rA   rF   r'   rG   r1   r1   r2   Ú_to_buffersy   s    zEmptyArray._to_buffersÚboolr   )Úforget_lengthrB   c                 C  s   t t ¡ d�S ©Nr6   )r$   r   r-   )r0   rK   r1   r1   r2   Ú_to_typetracerƒ   s    ÿzEmptyArray._to_typetracer)Ú	recursivec                 C  s   d S r9   r1   ©r0   rN   r1   r1   r2   Ú_touch_dataˆ   s    zEmptyArray._touch_datac                 C  s   d S r9   r1   rO   r1   r1   r2   Ú_touch_shape‹   s    zEmptyArray._touch_shaper   )rB   c                 C  s   dS ©Nr   r1   r;   r1   r1   r2   ÚlengthŽ   s    zEmptyArray.lengthc                 C  s   |   ddd¡S ©NÚ )Ú_reprr;   r1   r1   r2   Ú__repr__’   s    zEmptyArray.__repr__c                 C  sh   |   |d ¡}t|ƒdkr*|| d | S ||dg}| |¡ | d| d ¡ | |¡ d |¡S d S )Nz    r   z<EmptyArray len='0'/>z<EmptyArray len='0'>Ú
z</EmptyArray>rU   )Z_repr_extrar)   ÚextendÚappendÚjoin)r0   ÚindentÚpreÚpostÚextraÚoutr1   r1   r2   rV   •   s    


zEmptyArray._reprc                 C  s*   |p| j }tjj|jjd|d�| j|d�S )Nr   ©Údtyper%   )r7   ÚakÚcontentsÚ
NumpyArrayÚnplikeÚemptyÚ_parameters)r0   rb   r'   r1   r1   r2   Úto_NumpyArray    s    
ýzEmptyArray.to_NumpyArrayc                 C  s   t g ƒS r9   )Úiterr;   r1   r1   r2   Ú__iter__¨   s    zEmptyArray.__iter__c                 C  s   | S r9   r1   r;   r1   r1   r2   Ú_getitem_nothing«   s    zEmptyArray._getitem_nothingc                 C  s   dS )NFr1   r;   r1   r1   r2   Ú_is_getitem_at_placeholder®   s    z%EmptyArray._is_getitem_at_placeholderr   )Úwherec                 C  s   t j | |d¡‚d S )Núarray is empty©rc   Ú_errorsÚindex_error)r0   rn   r1   r1   r2   Ú_getitem_at±   s    zEmptyArray._getitem_atr   )ÚstartÚstoprB   c                 C  s   | S r9   r1   )r0   rt   ru   r1   r1   r2   Ú_getitem_range´   s    zEmptyArray._getitem_ranger1   zstr | SupportsIndexztuple[str, ...])rn   Úonly_fieldsrB   c                 C  s   t j | |d¡‚d S )Núnot an array of recordsrp   ©r0   rn   rw   r1   r1   r2   Ú_getitem_field·   s    zEmptyArray._getitem_fieldzlist[str | SupportsIndex]c                 C  s,   t |ƒdkr|  dd¡S tj | |d¡‚d S )Nr   rx   )r)   rv   rc   rq   rr   ry   r1   r1   r2   Ú_getitem_fields¼   s    zEmptyArray._getitem_fieldsr"   )ÚcarryÚ
allow_lazyrB   c                 C  s>   t |tjjƒsJ ‚|jjr$|jdkr(| S tj | |j	d¡‚d S )Nr   ro   )
rH   rc   Úindexr"   rf   Ú
known_datarS   rq   rr   Údata)r0   r|   r}   r1   r1   r2   Ú_carryÃ   s    zEmptyArray._carry)ÚslicestartsÚ
slicestopsÚslicecontentrB   c              	   C  s$   t j | t jj|||d d�d¡‚d S )N)r&   z*too many jagged slice dimensions for array)rc   rq   rr   rd   Z	ListArray)r0   r‚   rƒ   r„   Útailr1   r1   r2   Ú_getitem_next_jaggedË   s    ÿûzEmptyArray._getitem_next_jaggedzSliceItem | tupleztuple[SliceItem, ...]zIndex | None)Úheadr…   ÚadvancedrB   c                 C  s*  |t u r| S t|ƒr(tj | |d¡‚� nþt|tƒrDtj | |d¡‚nât|tƒr\|  |||¡S t|t	ƒrt|  
|||¡S |tju rŠ|  ||¡S |tu rž|  ||¡S t|tjjƒrÖ|jjr¾|jdkrÂ| S tj | |jd¡‚nPt|tjjƒ� røtj | |d¡‚n.t|tjjƒ�rtj | |d¡‚ntt|ƒƒ‚d S )Nro   r   )r   r   rc   rq   rr   rH   ÚslicerD   Z_getitem_next_fieldÚlistZ_getitem_next_fieldsÚnpZnewaxisZ_getitem_next_newaxisÚEllipsisZ_getitem_next_ellipsisr~   ÚIndex64rf   r   rS   r€   rd   ZListOffsetArrayZIndexedOptionArrayÚAssertionErrorÚrepr)r0   r‡   r…   rˆ   r1   r1   r2   Ú_getitem_nextÖ   s.    



zEmptyArray._getitem_nextÚintztuple[Index, Content])ÚaxisÚdepthrB   c                 C  sV   t | ||ƒ}|d ur,|d |kr,t| dƒ‚n&tjjjd| jjd�}|t| jd�fS d S )Né   zaxis=0 not allowed for flatten)rf   r6   )	r	   r   rc   r~   r�   Zzerosr7   Zindex_npliker$   )r0   r’   r“   ÚposaxisÚoffsetsr1   r1   r2   Ú_offsets_and_flattened   s    
þz!EmptyArray._offsets_and_flattened)ÚotherÚ	mergeboolrB   c                 C  s   dS ©NTr1   )r0   r˜   r™   r1   r1   r2   Ú_mergeable_next  s    zEmptyArray._mergeable_nextzSequence[Content])ÚothersrB   c                 C  s>   t |ƒdkr| S t |ƒdkr$|d S |d  |dd … ¡S d S )Nr   r”   )r)   Ú
_mergemany)r0   rœ   r1   r1   r2   r�     s
    zEmptyArray._mergemany)ÚvaluerB   c                 C  s   t | jd�S rL   ©r$   r7   )r0   rž   r1   r1   r2   Ú
_fill_none  s    zEmptyArray._fill_nonec                 C  s^   t | ||ƒ}|d urD|d |krDtjj| jjjdtjd�d | jd�S t	d|› d|› d�ƒ‚d S )Nr”   r   ra   r%   úaxis=ú" exceeds the depth of this array (ú))
r	   rc   rd   re   r7   rf   rg   r‹   Zint64r   )r0   r’   r“   r•   r1   r1   r2   Ú_local_index  s    ýzEmptyArray._local_indexc                 C  s    |r|   tjj |¡¡S | S d S r9   )ri   rc   ÚtypesZ	numpytypeZprimitive_to_dtype)r0   ÚnameZincluding_unknownr1   r1   r2   Ú_numbers_to_type$  s    zEmptyArray._numbers_to_typec                 C  s   dS rš   r1   ©r0   ÚnegaxisÚstartsÚparentsÚ	outlengthr1   r1   r2   Ú
_is_unique*  s    zEmptyArray._is_uniquec                 C  s   | S r9   r1   r¨   r1   r1   r2   Ú_unique-  s    zEmptyArray._uniquec           	   	   C  s"   |   tj¡}| |||||||¡S r9   )ri   r‹   Úfloat64Ú_argsort_next)	r0   r©   rª   Úshiftsr«   r¬   Ú	ascendingÚstableÚas_numpyr1   r1   r2   r°   0  s    ÿzEmptyArray._argsort_nextc                 C  s   | S r9   r1   )r0   r©   rª   r«   r¬   r²   r³   r1   r1   r2   Ú
_sort_next8  s    zEmptyArray._sort_nextc                 C  s   t jj| jd�S rL   )rc   rd   r$   r7   )r0   ÚnÚreplacementZrecordlookupr&   r’   r“   r1   r1   r2   Ú_combinations;  s    zEmptyArray._combinationsc
                 C  s&   |   |j¡}
|
 |||||||||	¡	S r9   )ri   Zpreferred_dtypeÚ_reduce_next)r0   Zreducerr©   rª   r±   r«   r¬   ÚmaskZkeepdimsÚbehaviorr´   r1   r1   r2   r¹   >  s    ÷zEmptyArray._reduce_nextc                 C  s   dS rT   r1   )r0   Úpathr1   r1   r2   Ú_validity_errorW  s    zEmptyArray._validity_errorc                 C  s   dS rR   r1   r;   r1   r1   r2   Ú_nbytes_partZ  s    zEmptyArray._nbytes_partc                 C  sH   t | ||ƒ}|d ur8|d |kr8td|› d|› d�ƒ‚n|  |d¡S d S )Nr”   r¡   r¢   r£   T)r	   r   Z_pad_none_axis0)r0   Útargetr’   r“   Zclipr•   r1   r1   r2   Ú	_pad_none]  s    zEmptyArray._pad_noner   zContent | Noner   )ÚpyarrowÚ	mask_nodeÚ
validbytesrS   Úoptionsc              	   C  s–   |d d u rR|j jtjjj| ¡ |d |d || |d u d�|tjj |¡g|d�S t 	|d ¡}tj
jtj||d�| j| jd�}| |||||¡S d S )NZemptyarray_toZextensionarrayÚrecord_is_scalar)Zstorage_typeZuse_extensionarrayrÅ   rº   ÚnodeZis_nonnullable_nulltype)Z
null_countra   r%   )ZArrayZfrom_buffersrc   Ú_connectrÁ   Zto_awkwardarrow_typeÚnullZto_validbitsr‹   rb   rd   re   Únumpyrg   rh   r7   Ú	_to_arrow)r0   rÁ   rÂ   rÃ   rS   rÄ   rb   Únextr1   r1   r2   rÊ   d  s,    úÿóýzEmptyArray._to_arrowc                 C  s   dS rš   r1   )r?   r1   r1   r2   Ú_arrow_needs_option_type†  s    z#EmptyArray._arrow_needs_option_typec                 C  s   |j jdtjd�S )Nr   ra   )rf   rg   r‹   r¯   )r0   Zallow_missingr'   r1   r1   r2   Ú_to_backend_arrayŠ  s    zEmptyArray._to_backend_arrayr   zlist[Content])r'   rÄ   rB   c                 C  s   | gS r9   r1   )r0   r'   rÄ   r1   r1   r2   Ú_remove_structure�  s    zEmptyArray._remove_structurer   zMapping[str, Any] | Noner   )Úactionr“   Údepth_contextÚlateral_contextrÄ   rB   c              	     s`   ˆ d r‡ ‡fdd„}ndd„ }|ˆ||||ˆj ˆ d�}t|tƒrF|S |d u rT|ƒ S t|ƒ‚d S )NZreturn_arrayc                     s   ˆ d rˆS t ˆjd�S d S )NZkeep_parametersr6   rŸ   r1   ©rÄ   r0   r1   r2   Úcontinuationœ  s    z3EmptyArray._recursively_apply.<locals>.continuationc                   S  s   d S r9   r1   r1   r1   r1   r2   rÓ   ¤  s    )r“   rÐ   rÑ   rÓ   r'   rÄ   )r7   rH   r   rŽ   )r0   rÏ   r“   rÐ   rÑ   rÄ   rÓ   Úresultr1   rÒ   r2   Ú_recursively_apply’  s"    ù

zEmptyArray._recursively_applyT)rN   rB   c                 C  s   | S r9   r1   rO   r1   r1   r2   Ú	to_packed¸  s    zEmptyArray.to_packedc                 C  s   | j jjstdƒ‚g S )Nz0cannot convert typetracer arrays to Python lists)r7   rf   r   r*   )r0   r»   Zjson_conversionsr1   r1   r2   Ú_to_list»  s    
zEmptyArray._to_list)r'   rB   c                 C  s
   t |d�S rL   )r$   )r0   r'   r1   r1   r2   Ú_to_backendÀ  s    zEmptyArray._to_backend)r˜   Úindex_dtypeÚ
numpyarrayÚall_parametersrB   c                 C  s   |   ||¡S r9   )Z_is_equal_to_generic)r0   r˜   rÙ   rÚ   rÛ   r1   r1   r2   Ú_is_equal_toÃ  s    zEmptyArray._is_equal_to)N)r1   )r1   )T):r,   Ú
__module__Ú__qualname__Ú__doc__r3   r    r4   Ú__annotations__r   r8   r<   r>   Úclassmethodr@   rC   rI   rM   rP   rQ   ÚpropertyrS   rW   rV   ri   rk   rl   rm   rs   rv   rz   r{   r�   r†   r�   r—   r›   r�   r    r¤   r§   r­   r®   r°   rµ   r¸   r¹   r½   r¾   rÀ   rÊ   rÌ   rÍ   rÎ   rÕ   rÖ   r×   rØ   rÜ   r1   r1   r1   r2   r$   1   sr   
"ü

 ÿ ÿ*"
&r$   )<Ú
__future__r   Úcollections.abcr   r   r   Zawkwardrc   Zawkward._backends.backendr   Zawkward._backends.numpyr   Zawkward._backends.typetracerr   Zawkward._layoutr	   Zawkward._meta.emptymetar
   Zawkward._nplikes.array_liker   Zawkward._nplikes.numpyr   Zawkward._nplikes.numpy_liker   r   Zawkward._nplikes.shaper   Zawkward._regularizer   Zawkward._slicingr   Zawkward._typingr   r   r   r   r   r   r   Zawkward._utilr   Zawkward.contents.contentr   r   r   r   r   Zawkward.errorsr   Zawkward.forms.emptyformr    Zawkward.forms.formr!   Zawkward.indexr"   r#   r-   rÉ   r‹   r$   r1   r1   r1   r2   Ú<module>   s4   $	