a
    yn„f‰  ã                   @  s„   d dl m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 d dlmZ dZe
 ¡ Zeƒ dd
d„ƒZdd„ Zdd„ ZdS )é    )ÚannotationsN)Úhigh_level_function)ÚHighLevelContextÚmaybe_posaxis)ÚNumpyMetadata)Úregularize_axis)Ú	AxisError)Ú	drop_noneTc                 c  s   | fV  t | ||||ƒS )a?  
    Args:
        array: Data in which to remove Nones.
        axis (None or int): If None, the operation drops Nones at all levels of
            nesting, returning an array of the same dimension, but without Nones.
            Otherwise, it drops Nones at a specified depth.
            The outermost dimension is `0`, followed by `1`, etc.,
            and negative values count backward from the innermost: `-1` is the
            innermost dimension, `-2` is the next level up, etc.
        highlevel (bool): If True, return an #ak.Array; otherwise, return
            a low-level #ak.contents.Content subclass.
        behavior (None or dict): Custom #ak.behavior for the output array, if
            high-level.
        attrs (None or dict): Custom attributes for the output array, if
            high-level.

    Removes missing values (None) from a given array.

    For example, in the following `array`,

        >>> array = ak.Array([[[0]], [[None]], [[1], None], [[2, None]]])

    The None value will be removed, resulting in

        >>> ak.drop_none(array)
        <Array [[[0]], [[]], [[1]], [[2]]] type='4 * var * var * int64'>

    The default axis is None, however an axis can be specified:

        >>> ak.drop_none(array, axis=1)
        <Array [[[0]], [[None]], [[1]], [[2, None]]] type='4 * var * var * ?int64'>

    )Ú_impl)ÚarrayÚaxisÚ	highlevelÚbehaviorÚattrs© r   úb/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/operations/ak_drop_none.pyr	      s    $r	   c                 C  s   | j r|  ¡ S | S d S ©N)Úis_listr	   )Úlayoutr   r   r   Ú_drop_none_if_list;   s    r   c                   sö   t ˆ ƒ‰ t||d�� }|j| ddd�}W d   ƒ n1 s:0    Y  ˆ d u rd|jrZ| ¡ }dd„ }nH|jd d }ˆ |kr�tdˆ › d	|› d
�ƒ‚‡ ‡fdd„}	‡ ‡fdd„}dg i‰tjj	||ˆd�}
t
ˆd ƒdkrètjj	|
|	ˆd�}
|j|
|d�S )N)r   r   FÚerror)Zallow_recordZprimitive_policyc                 [  s
   t |ƒ ƒS r   )r   )r   ZcontinuationÚkwargsr   r   r   ÚactionM   s    z_impl.<locals>.actioné   úaxis=z exceeds the depth (z) of this arrayc                   sR   t | ˆ |ƒ}|dkr ||d ks.||krN| jrNˆd  d¡}|  || j¡}|S d S )Nr   r   Únone_indexes)r   r   ÚpopZ_rebuild_without_nonesÚcontent)r   Údepthr   Úposaxisr   Úout©r   Úoptionsr   r   Úrecompute_offsetsU   s    ÿ
þýüz _impl.<locals>.recompute_offsetsc                   sÐ   | j rN‡‡ fdd„| jD ƒ}t|ƒdkrNt‡ fdd„|D ƒƒrNtdˆ› d�ƒ‚t| ˆˆ ƒ}|dkrt| jsl| S |  ¡ S |ˆ d krª| jrª|  ¡ \}}}ˆd	  	|¡ |  ¡ S |ˆ d krÌ| j
rÌ| jjrÌ|  ¡ S d S )
Nc                   s   h | ]}t |ˆ ˆƒ’qS r   )r   ©Ú.0Úx)r   r   r   r   Ú	<setcomp>c   ó    z(_impl.<locals>.action.<locals>.<setcomp>r   c                 3  s   | ]}|ˆ k V  qd S r   r   r$   ©r   r   r   Ú	<genexpr>d   r(   z(_impl.<locals>.action.<locals>.<genexpr>r   zk implies different levels in records that might require part of a record to be dropped, which is impossibler   r   )Z	is_recordÚcontentsÚlenÚanyr   r   Ú	is_optionr	   Z_nextcarry_outindexÚappendr   r   )r   r   r   Z	posaxisesr   Ú_r   r!   r)   r   r   a   s"    "
ÿr   )Zdepth_contextr   )r   )r   r   Úunwrapr.   r	   Zbranch_depthr   ÚakZ_doZrecursively_applyr,   Úwrap)r   r   r   r   r   Úctxr   r   Zmax_axisr#   r    r   r!   r   r
   C   s"    .
r
   )NTNN)Ú
__future__r   Zawkwardr2   Zawkward._dispatchr   Zawkward._layoutr   r   Zawkward._nplikes.numpy_liker   Zawkward._regularizer   Zawkward.errorsr   Ú__all__ÚinstanceÚnpr	   r   r
   r   r   r   r   Ú<module>   s   )