a
    zn„f•  ã                   @  s¦  d Z ddlmZ ddlZddlZddlZdd„ ZG dd„ dƒZG dd	„ d	eƒZd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZG dd„ deƒZdd„ Zdd„ Zdd„ Zdd„ Zd0d d!„ZG d"d#„ d#eƒZejeƒ ejeƒ ejeƒ iZeej ed$< eej ed%< eej ed	< eej ed&< eej ed'< eej ed(< eej ed)< eej ed*< eej ed< eej ed+< eej ed,< eej ed#< eej ed-< d.d/„ ZdS )1aÃ  
This module represents external libraries that define "array-like" types so that users can
choose an output format.

The :doc:`uproot.interpretation.library.NumPy` library always works (NumPy is
Uproot's only strict dependency) and outputs NumPy arrays for single arrays
and dict/tuple/list as groups. Objects and jagged arrays are not efficiently
represented, but it provides a zero-dependency least common denominator.

The :doc:`uproot.interpretation.library.Awkward` library is the default and
depends on Awkward Array (``awkward``). It is usually the best option, as it
was designed for Uproot.

The :doc:`uproot.interpretation.library.Pandas` library outputs
``pandas.Series`` for single arrays and ``pandas.DataFrame`` as groups. Objects
are not efficiently represented, but some jagged arrays are encoded as
``pandas.MultiIndex``.

Lazy arrays (:doc:`uproot.behaviors.TBranch.lazy`) can only use the
:doc:`uproot.interpretation.library.Awkward` library.
é    )ÚannotationsNc                 C  s    |d u sd|vr| S |d S d S )NÚrename© )ÚnameÚcontextr   r   ú`/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/uproot/interpretation/library.pyÚ_rename!   s    r   c                   @  s\   e Zd ZdZe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 )ÚLibraryaÄ  
    Abstract superclass of array-library handlers, for libraries such as NumPy,
    Awkward Array, and Pandas.

    A library is used in the finalization and grouping stages of producing an
    array, converting it from internal representations like
    :doc:`uproot.interpretation.jagged.JaggedArray`,
    :doc:`uproot.interpretation.strings.StringArray`, and
    :doc:`uproot.interpretation.objects.ObjectArray` into the library's
    equivalents. It can also be required for concatenation and other late-stage
    operations on the output arrays.

    Libraries are usually selected by a string name. These names are held in a
    private registry in the :doc:`uproot.interpretation.library` module.
    c                 C  s   t ‚dS )zQ
        Attempts to import the library and returns the imported module.
        N©ÚAssertionError©Úselfr   r   r   Úimported9   s    zLibrary.importedc                 C  s   t  ||¡S )a  
        Args:
            shape (tuple of int): NumPy array ``shape``. (The first item must
                be zero.)
            dtype (``numpy.dtype`` or its constructor argument): NumPy array
                ``dtype``.

        Returns an empty NumPy-like array.
        )ÚnumpyÚempty©r   ÚshapeÚdtyper   r   r   r   @   s    
zLibrary.emptyc                 C  s   t  ||¡S )a  
        Args:
            shape (tuple of int): NumPy array ``shape``. (The first item must
                be zero.)
            dtype (``numpy.dtype`` or its constructor argument): NumPy array
                ``dtype``.

        Returns a NumPy-like array of zeros.
        )r   Úzerosr   r   r   r   r   L   s    
zLibrary.zerosc                 C  s   t ‚dS )a�  
        Args:
            array (array): Internal, temporary, trimmed array. If this is a
                NumPy array, it may be identical to the output array.
            branch (:doc:`uproot.behaviors.TBranch.TBranch`): The ``TBranch``
                that is represented by this array.
            interpretation (:doc:`uproot.interpretation.Interpretation`): The
                interpretation that produced the ``array``.
            entry_start (int): First entry that is included in the output.
            entry_stop (int): FIrst entry that is excluded (one greater than
                the last entry that is included) in the output.
            interp_options (dict): Flags and other options passed through the
                interpretation process.

        Create a library-appropriate output array for this temporary ``array``.

        This array would represent one ``TBranch`` (i.e. not a "group").
        Nr
   )r   ÚarrayÚbranchÚinterpretationÚentry_startÚ
entry_stopZinterp_optionsr   r   r   ÚfinalizeX   s    zLibrary.finalizec                   sp   |t u rt ‡ fdd„|D ƒƒS |tu r8‡ fdd„|D ƒS |tu sH|du rZ‡ fdd„|D ƒS td| j› d	�ƒ‚dS )
uÙ  
        Args:
            arrays (dict of str â†’ array): Mapping from names to finalized
                array objets to combine into a group.
            expression_context (list of (str, dict) tuples): Expression strings
                and a dict of metadata about each.
            how (None, str, or container type): Library-dependent instructions
                for grouping. The only recognized container types are ``tuple``,
                ``list``, and ``dict``. Note that the container *type itself*
                must be passed as ``how``, not an instance of that type (i.e.
                ``how=tuple``, not ``how=()``).

        Combine the finalized ``arrays`` into a library-appropriate group type.
        c                 3  s   | ]\}}ˆ | V  qd S ©Nr   ©Ú.0r   Ú_©Úarraysr   r   Ú	<genexpr>   ó    z Library.group.<locals>.<genexpr>c                   s   g | ]\}}ˆ | ‘qS r   r   r   r   r   r   Ú
<listcomp>�   r"   z!Library.group.<locals>.<listcomp>Nc                   s    i | ]\}}t ||ƒˆ | “qS r   ©r   ©r   r   Úcr   r   r   Ú
<dictcomp>ƒ   r"   z!Library.group.<locals>.<dictcomp>úfor library z3, how must be tuple, list, dict, or None (for dict))ÚtupleÚlistÚdictÚ	TypeErrorr   )r   r    Úexpression_contextÚhowr   r   r   Úgroupo   s    ÿzLibrary.groupc                 C  s   |S )aÉ  
        Args:
            array (array): The library-appropriate array whose global index
                needs adjustment.
            global_offset (int): A number to add to the global index of
                ``array`` to correct it.

        Apply *in-place* corrections to the global index of ``array`` by adding
        ``global_offset``.

        Even though the operation is performed *in-place*, this method returns
        the ``array``.
        r   )r   r   Úglobal_offsetr   r   r   Úglobal_indexŠ   s    zLibrary.global_indexc                 C  s   t ‚dS )zÎ
        Args:
            all_arrays (list of arrays): A list of library-appropriate arrays
                that need to be concatenated.

        Returns a concatenated version of ``all_arrays``.
        Nr
   )r   Ú
all_arraysr   r   r   Úconcatenateš   s    zLibrary.concatenatec                 C  s
   t | jƒS r   )Úreprr   r   r   r   r   Ú__repr__¤   s    zLibrary.__repr__c                 C  s   t t| j ƒt t|j ƒu S r   )ÚtypeÚ
_librariesr   )r   Úotherr   r   r   Ú__eq__§   s    zLibrary.__eq__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   r   r   r/   r1   r3   r5   r9   r   r   r   r   r	   (   s   

r	   c                   @  s0   e Zd ZdZdZedd„ ƒZdd„ Zdd„ Zd	S )
ÚNumPyu1  
    A :doc:`uproot.interpretation.library.Library` that presents ``TBranch``
    data as NumPy arrays. The standard name for this library is ``"np"``.

    The single-``TBranch`` form for this library is a ``numpy.ndarray``. If
    the data are non-numerical, they will be converted into Python objects and
    stored in an array with ``dtype="O"``. This is inefficient, but it is the
    minimal-dependency option for Python.

    The "group" behavior for this library is:

    * ``how=dict`` or ``how=None``: a dict of str â†’ array, mapping the
      names to arrays.
    * ``how=tuple``: a tuple of arrays, in the order requested. (Names are
      lost.)
    * ``how=list``: a list of arrays, in the order requested. (Names are lost.)

    Since NumPy arrays are not indexed, ``global_index`` has no effect.
    Únpc                 C  s   dd l }|S )Nr   )r   )r   r   r   r   r   r   Â   s    zNumPy.importedc                 C  s  t |tjjjƒr|t |jtjjjƒr|tj	t
|ƒtd�}t|ƒD ]:\}}	tj	|	jtd�||< |	 ¡ D ]\}
}||| |
< q`q<|S t |tjjjƒrºtj	|jtd�}| ¡ D ]\}}	|	||< q¤|S t |tjjjtjjjtjjjfƒ�rtj	t
|ƒtd�}t|ƒD ]\}}	|	||< qø|S |S d S )N©r   )Ú
isinstanceÚuprootr   ÚjaggedÚJaggedArrayÚcontentÚobjectsÚStridedObjectArrayr   r   ÚlenÚobjectÚ	enumerater   ZndenumerateÚstringsÚStringArrayZObjectArray)r   r   r   r   r   r   ÚoptionsÚoutÚiÚxÚjÚyr   r   r   r   È   s<    þþ
ýþ
zNumPy.finalizec                   s  t |ƒdkr|S t|d ttfƒr4tt |d ƒƒ}n,t|d tƒrPt|d ƒ}ntt|d ƒƒ‚dd„ |D ƒ‰|D ] }|D ]}ˆ|  || ¡ qzqr‡fdd„|D ƒ‰ t|d tƒrÊt‡ fdd„|D ƒƒS t|d tƒrê‡ fdd„|D ƒS t|d tƒ� rþˆ S d S )	Nr   c                 S  s   i | ]
}|g “qS r   r   ©r   Úkr   r   r   r'   ø   r"   z%NumPy.concatenate.<locals>.<dictcomp>c                   s   i | ]}|t  ˆ | ¡“qS r   )r   r3   rT   )Úto_concatenater   r   r'   ý   r"   c                 3  s   | ]}ˆ | V  qd S r   r   rT   ©Úconcatenatedr   r   r!      r"   z$NumPy.concatenate.<locals>.<genexpr>c                   s   g | ]}ˆ | ‘qS r   r   rT   rW   r   r   r#     r"   z%NumPy.concatenate.<locals>.<listcomp>)	rI   rB   r)   r*   Úranger+   r   r4   Úappend©r   r2   Úkeysr    rU   r   )rX   rV   r   r3   í   s$    zNumPy.concatenateN)	r:   r;   r<   r=   r   r>   r   r   r3   r   r   r   r   r?   «   s   
%r?   c                 C  sü   g }g }|  ¡ }|jD ]~\}}| d¡s|}t|ƒdkrD|d | }t|tjjjƒrj| 	t
| |||ƒ¡ n | 	| jt || ¡ddd�¡ | 	|¡ qdtj |jj¡d i}	t|ƒdkrÂt|ƒnd }
| jj|||
|	d�}t|jƒD ]}| j ||¡}qä|S )	Nú@r   ú/TF©ÚregulararrayÚ	highlevelZ
__record__©Ú
parameters)ÚflattenÚmembersÚ
startswithrI   rB   rC   r   rG   ÚAsStridedObjectsrZ   Ú_strided_to_awkwardÚ
from_numpyr   r   ÚmodelZclassname_decoder:   ÚcontentsÚRecordArrayÚreversedZinner_shapeÚRegularArray)ÚawkwardÚpathr   Údatark   Únamesr   ÚmemberÚprc   ÚlengthrO   Údimr   r   r   rh     s.    
ÿÿÿrh   c                   sX  | d dkr|S | d dkrˆi }t | d | d ƒD ]P\}‰| d¡s2t|dƒrn| |¡rntˆ| |¡ƒ||< q2tˆt||ƒƒ||< q2|S | d d d… d	k�r | d
  d¡dkr´|S | d d
  d¡dk�r| d d d ‰ | d d d ‰‡ ‡fdd„| ¡ D ƒS | d ‰‡fdd„|D ƒS n4| d dk�rH| d ‰‡fdd„|D ƒS t	| d ƒ‚d S )NÚclassÚ
NumpyArrayrl   Úfieldsrk   r]   Ú
has_memberé   ÚListOffsetArrayrc   Ú	__array__ÚstringrF   Ú
sorted_mapr   é   c                   s$   g | ]\}}t ˆ |ƒt ˆ|ƒf‘qS r   ©Ú_object_to_awkward_json)r   rQ   rS   )Úkey_formÚ
value_formr   r   r#   8  s   ýþz+_object_to_awkward_json.<locals>.<listcomp>c                   s   g | ]}t ˆ |ƒ‘qS r   r�   ©r   rQ   ©Úsubformr   r   r#   B  r"   rn   c                   s   g | ]}t ˆ |ƒ‘qS r   r�   r…   r†   r   r   r#   F  r"   )
Úziprf   Úhasattrrz   r‚   rs   ÚgetattrÚgetÚitemsr   )ÚformÚobjrO   r   r   )rƒ   r‡   r„   r   r‚   #  s2    
û	r‚   c                 C  s  t || jjƒrˆ|d dkr2| j tjdtjd�¡S |d dkrV| j tjdtj	d�¡S |d dkrz| j 
tjdtjd�¡S t|d ƒ‚n€|d dkr®| j tj|jtjd�¡S |d dkrÔ| j tj|jtj	d�¡S |d dk� rü| j 
tj|jtjd�¡S t|d ƒ‚d S )NÚoffsetsZi32r€   rA   Úu32Zi64)rB   rk   Ú
EmptyArrayÚindexÚIndex32r   r   Úint32ÚIndexU32Úuint32ÚIndex64Úint64r   Úasarrayr�   )ro   r�   r   r   r   r   Ú_awkward_offsetsL  s*    ÿÿÿrš   c                 C  sÆ  |d dkrz| j  t |¡¡}| jj |j¡}t|| j	j
ƒrX| j	jtjd|d�|jd�S | j	jtj|j|d�|jd�S �nH|d dk�r*g }g }t|d |d ƒD ]T\}}| d	¡s¢t|| j	j
ƒrÖ| t| ||ƒ¡ n| t| ||| ƒ¡ | |¡ q¢t|ƒdk�rt|ƒnd }| j	j||||d
 d�S |d d d… dk�rZ|d
  d¡dk�rât|| j	j
ƒ�r´| j	jtjdtjd�|d d
 d�}	| j	j| j tjdgtjd�¡|	|d
 d�S t| |d |jƒ}	t|ƒ|j|	|d
 d�S �qÂ|d d
  d¡dk�rôt | ||ƒ}
|d d d }|d d d }t|| j	j
ƒ�rpt| ||ƒ}t| ||ƒ}| j	j||fd d|d d
 d�}	n`t| ||jd ƒ}t| ||jd ƒ}t|ƒdk�r¬t|jƒnd }| j	j||fd ||d d
 d�}	t!j" #| |d ¡}||
|	|d
 d�S t | ||ƒ}
t|| j	j
ƒ�r"t| |d |ƒ}	nt| |d |jƒ}	t!j" #| |d ¡}||
|	|d
 d�S nh|d dk�r¶t|| j	j
ƒ�rŠt| |d |ƒ}	nt| |d |jƒ}	| j	j$|	|d |d
 d�S t%|d ƒ‚d S )Nrw   rx   r   rA   rb   rl   ry   rk   r]   rc   r{   r|   r}   r~   rF   r   r€   Ú0Ú1rn   Úsize)&ZformsÚ	from_jsonÚjsonÚdumpsÚtypesZ	numpytypeZprimitive_to_dtypeZ	primitiverB   rk   r‘   rx   r   r   rc   r™   rq   rˆ   rf   rZ   Ú_awkward_json_to_arrayrI   rl   r‹   Úuint8r|   r’   r—   r   rF   r6   r�   rš   rC   Ú_utilZ_content_cls_from_namern   r   )ro   r�   r   r   rk   rr   r   r‡   ru   rF   r�   rƒ   r„   r\   ÚvaluesÚclsr   r   r   r¢   g  sª    þþ

ÿÿ
þýÿÿ

ü
üÿÿr¢   c                 C  s   |r|   |d|j¡S |S d S )Nr=   )Zwith_parameterÚtitle)ro   r   r   Ú
ak_add_docr   r   r   Ú_awkward_add_docÍ  s    r©   c                   s.   | j ‡ fdd„|D ƒdd�}|  t| ˆ |ƒ¡S )Nc                 3  s   | ]}t ˆ |ƒV  qd S r   r�   r…   ©r�   r   r   r!   Ö  r"   z+_object_to_awkward_array.<locals>.<genexpr>F)ra   )Z	from_iterÚArrayr¢   )ro   r�   r   Z	unlabeledr   rª   r   Ú_object_to_awkward_arrayÔ  s
    þr¬   c                   @  s8   e Zd ZdZdZedd„ ƒZdd„ Zdd„ Zd	d
„ Z	dS )ÚAwkwardu¡  
    A :doc:`uproot.interpretation.library.Library` that presents ``TBranch``
    data as Awkward Arrays. The standard name for this library is ``"ak"``.

    This is the default for all functions that require a
    :doc:`uproot.interpretation.library.Library`, though Uproot does not
    explicitly depend on Awkward Array. If you are confronted with a message
    that Awkward Array is not installed, either install ``awkward`` or
    select another library (likely :doc:`uproot.interpretation.library.NumPy`).

    Both the single-``TBranch`` and "group" forms for this library are
    ``ak.Array``, though groups are always arrays of records. Awkward Array
    was originally developed for Uproot, so the data structures are usually
    optimial for Uproot data.

    The "group" behavior for this library is:

    * ``how=None``: an array of Awkward records.
    * ``how=dict``: a dict of str â†’ array, mapping the names to arrays.
    * ``how=tuple``: a tuple of arrays, in the order requested. (Names are
      lost.)
    * ``how=list``: a list of arrays, in the order requested. (Names are lost.)

    Since Awkward arrays are not indexed, ``global_index`` has no effect.
    Zakc                 C  s
   t j ¡ S r   )rC   Úextrasro   r   r   r   r   r   ù  s    zAwkward.importedc              	   C  s´  | j }| dd¡}t||jjƒr4t|| |¡||ƒS t|tjj	j
ƒrft|| t|d|j|jƒ¡||ƒS t|tjjjƒ�rt|jtjj	j
ƒ�rt|d|jj|jjƒ}	t|jjjtjƒrÒ|j |j¡}
|j |
|	¡}n|j |j¡}
|j |
|	¡}t|| |¡||ƒS t|tjjjƒ�rˆ|j|jddd�}	t|jjjtjƒ�rX|j |j¡}
|j |
|	¡}n|j |j¡}
|j |
|	¡}t|| |¡||ƒS t|tjjjƒ�r”|jjtj|jt tj ¡d�ddid	�}	t|jjjtjƒ�rü|j |j¡}
|jj|
|	dd
id	�}n„t|jjjtj!ƒ�r6|j "|j¡}
|jj#|
|	dd
id	�}nJt|jjjtj$ƒ�rp|j |j¡}
|jj|
|	dd
id	�}nt%t&|jjƒƒ‚t|| |¡||ƒS t|tjj	j'ƒ�rÔt( )| *|j+j,¡ -¡ ¡}t|t.|||ƒ||ƒS |jj/d u�r˜|j0d |j0dd …  }}| 1d¡}g }|jj/D ]&}| 2|jt || ¡ddd�¡ �qt3|ƒdk�rLd }|j 4||jj/|¡}|d d d… D ]}|j 5||¡}�qnt|| |¡||ƒS t||j|dd�||ƒS d S )Nr¨   FÚ Tr_   rA   r}   Úcharrb   r~   r   r€   éÿÿÿÿ)r`   )6r   r‹   rB   rk   ZContentr©   r«   rC   r   rG   rH   rh   r   rD   rE   rF   Ú
issubclassr�   r   r6   r   r”   r’   r“   ZListOffsetArray32r—   r|   ri   rL   rM   rx   Z
frombufferr£   r–   r•   ZListOffsetArrayU32r˜   r   r4   Z	AsObjectsrŸ   ÚloadsÚawkward_formr   ÚfileÚto_jsonr¬   rr   r   ZreshaperZ   rI   rl   rn   )r   r   r   r   r   r   rN   ro   r¨   rF   r�   Úlayoutr�   ru   r   rk   r   rO   r�   r   r   r   r   ý  s²    ÿú	ÿÿÿþ
ÿ
ÿ
ÿÿ
ü
ÿÿüzAwkward.finalizec                   sÈ  | j }|tu r$t‡ fdd„|D ƒƒS |tu r>‡ fdd„|D ƒS |tu rX‡ fdd„|D ƒS |d u r t|ƒdkr„| |jjg g dd�¡S | ‡ fd	d„|D ƒ¡S �n$|d
k�r²g }g }g }i ‰|D ]ú\}}	ˆ |  }
ˆt||	ƒ< |	d �r¨t	|
j
|jjƒ�s
|
j
jd dk�r|
j
 d¡}n|
j
}t|ƒdk�rL| |j¡ | t||	ƒg¡ nZt||ƒD ]0\}}t |j|¡�rV| t||	ƒ¡  �q¸�qV| |j¡ | t||	ƒg¡ q¾| t||	ƒ¡ q¾d }t|ƒdk�rt|ƒdk�rô| |jjg g dd�¡}n| ‡fdd„|D ƒ¡}t|ƒD �]–\}}t|d ƒ‰|D ]j}tˆt|ƒƒ‰ˆdk�r†|d ˆ… |d d ˆ… k�sz|ˆd  dv�r†ˆd8 ‰�q@ˆdk�r. �qš�q.|d u�rÔˆdk�rÔ|d d ˆ…  d¡| |¡v �rÔd‰ˆdk�r*d|› �}t|ƒdk�r| |jjg g dd�¡}n| ‡fdd„|D ƒ¡}nX|d d ˆ…  d¡}t|ƒdk�rh| |jjg g dd�¡}n| ‡‡fdd„|D ƒ¡}|d u �rœ| ||i¡}n| |||¡}�q|S td| j› d�ƒ‚d S )Nc                 3  s   | ]\}}ˆ | V  qd S r   r   r   r   r   r   r!   i  r"   z Awkward.group.<locals>.<genexpr>c                   s   g | ]\}}ˆ | ‘qS r   r   r   r   r   r   r#   k  r"   z!Awkward.group.<locals>.<listcomp>c                   s    i | ]\}}t ||ƒˆ | “qS r   r$   r%   r   r   r   r'   m  r"   z!Awkward.group.<locals>.<dictcomp>r   )ry   ru   c                   s    i | ]\}}t ||ƒˆ | “qS r   r$   r%   r   r   r   r'   u  r"   rˆ   Z	is_jaggedTc                   s   i | ]}|ˆ | “qS r   r   ©r   r   ©Úrenamed_arraysr   r   r'   œ  r"   r€   )r   Ú.r^   ú_./rD   c                   s   i | ]}|ˆ | “qS r   r   r¸   r¹   r   r   r'   ·  r"   c                   s$   i | ]}|ˆ d …   d¡ˆ| “qS )Nr¼   )Ústripr¸   )Úcutrº   r   r   r'   Á  s   ÿr(   z‡, how must be tuple, list, dict, "zip" for a record array with jagged arrays zipped, if possible, or None, for an unzipped record array)r   r)   r*   r+   rI   r«   rk   rl   r   rB   r·   Z	ListArrayr�   Zto_ListOffsetArray64rZ   rˆ   r   Zarray_equalrK   Úminr½   ry   Z
with_fieldr,   r   )r   r    r-   r.   ro   Z	nonjaggedr�   Zjaggedsr   r   r   Zarray_layoutÚorR   rO   ÚnumberrD   ÚcommonZsubarrayr   )r    r¾   rº   r   r/   e  sº    ÿÿ

ÿþ
ÿÿ
ÿþ

ÿþý

ÿÿÿþÿ
ÿzAwkward.groupc                   s  | j ‰ t|ƒdkr|S t|d ttfƒr:tt|d ƒƒ}n&t|d tƒrVt|d ƒ}n
ˆ  |¡S dd„ |D ƒ‰|D ] }|D ]}ˆ|  || ¡ qzqr‡ ‡fdd„|D ƒ‰t|d tƒrÌt‡fdd„|D ƒƒS t|d tƒrì‡fdd„|D ƒS t|d tƒ�r ˆS d S )	Nr   c                 S  s   i | ]
}|g “qS r   r   rT   r   r   r   r'   à  r"   z'Awkward.concatenate.<locals>.<dictcomp>c                   s   i | ]}|ˆ   ˆ| ¡“qS r   )r3   rT   )ro   rV   r   r   r'   å  r"   c                 3  s   | ]}ˆ | V  qd S r   r   rT   rW   r   r   r!   è  r"   z&Awkward.concatenate.<locals>.<genexpr>c                   s   g | ]}ˆ | ‘qS r   r   rT   rW   r   r   r#   ê  r"   z'Awkward.concatenate.<locals>.<listcomp>)	r   rI   rB   r)   r*   rY   r+   r3   rZ   r[   r   )ro   rX   rV   r   r3   Ó  s&    
zAwkward.concatenateN)
r:   r;   r<   r=   r   r>   r   r   r/   r3   r   r   r   r   r­   Ü  s   
hnr­   c                 C  s^   t | dƒrt|| jƒrdS t |dƒr0| ¡ r0dS tj | j¡tj d¡k rZt|| jƒrZdS dS )NÚ
RangeIndexTÚ
is_integerz1.4.0F)	r‰   rB   rÃ   rÄ   rC   r¤   Úparse_versionÚ__version__Ú
Int64Index)Úpandasr’   r   r   r   Ú_is_pandas_rangeindexï  s    ÿ
þrÉ   c                 C  sl   |j D ]`\}}| d¡sg | ¢|‘R }t|tjjjƒrHt|||||ƒ q| |d 	|¡ ¡ | |¡ qd S )Nr]   r^   )
re   rf   rB   rC   r   rG   rg   Ú_strided_to_pandasrZ   Újoin)rp   r   rq   r    Úcolumnsr   rs   rt   r   r   r   rÊ   ü  s    
rÊ   c                 C  s*   t | dƒr|  ||¡S |  t||ƒ¡S d S )NrÃ   )r‰   rÃ   rÇ   rY   )rÈ   r   r   r   r   r   Ú_pandas_basic_index  s    
rÍ   c                 C  s@   i }g }|D ]*\}}|| |t ||ƒ< | t ||ƒ¡ q||fS r   )r   rZ   )rÈ   Zoriginal_arraysr-   r    rr   r   r   r   r   r   Ú_pandas_only_series  s    rÎ   c                 C  sð   t | tjƒrP| jjd u rPt| jƒdkrP| jt t¡krP|r>| S tj	 
¡  | ¡S nœz| d ¡ W n tjjjyv   Y nv0 |rÖttj  | |||||¡} t | jjtj	 
¡ jjƒrÄ| jjdkrÄ|  ¡ } qètj	 ¡  | ¡} nttj	 
¡ || ƒ} | S d S )Nr€   )r€   r€   )rB   r   Zndarrayr   rr   rI   r   rJ   rC   r®   ro   r«   r´   r   rG   ZCannotBeAwkwardr7   r­   r   r   r6   rF   r¡   Z	NumpyTyper·   Zminmax_depthZto_numpyZawkward_pandasZAwkwardExtensionArrayr¬   )r   r   r   r   r   r   rN   r�   r   r   r   Ú_process_array_for_pandas  s8    
ÿ
þýü
ÿÿ
þ
rÏ   c                   @  s@   e Zd ZdZdZedd„ ƒZdd„ Zdd„ Zd	d
„ Z	dd„ Z
dS )ÚPandasuÓ  
    A :doc:`uproot.interpretation.library.Library` that presents ``TBranch``
    data as Pandas Series and DataFrames. The standard name for this library is
    ``"pd"``.

    The single-``TBranch`` (with a single ``TLeaf``) form for this library is
    ``pandas.Series``, and the "group" form is ``pandas.DataFrame``.

    The "group" behavior for this library is:

    * ``how=None`` or a string: passed to ``pandas.merge`` as its ``how``
      parameter, which would be relevant if jagged arrays with different
      multiplicity are requested.
    * ``how=dict``: a dict of str â†’ array, mapping the names to
      ``pandas.Series``.
    * ``how=tuple``: a tuple of ``pandas.Series``, in the order requested.
      (Names are assigned to the ``pandas.Series``.)
    * ``how=list``: a list of ``pandas.Series``, in the order requested.
      (Names are assigned to the ``pandas.Series``.)

    Pandas Series and DataFrames are indexed, so ``global_index`` adjusts them.
    Úpdc                 C  s
   t j ¡ S r   )rC   r®   rÈ   r   r   r   r   r   Z  s    zPandas.importedc           	      C  s4   | j }t|||ƒ}t|d|||||ƒ}|j||d�S )NT)r’   )r   rÍ   rÏ   ÚSeries)	r   r   r   r   r   r   rN   rÈ   r’   r   r   r   r   ^  s    ÿzPandas.finalizec                   sÖ   | j ‰|tu r$t‡ fdd„|D ƒƒS |tu r>‡ fdd„|D ƒS |tu rX‡ fdd„|D ƒS t|tƒsj|d u rÀtˆˆ |ƒ\‰ }tˆ ƒdkrŽˆ ¡ S ‡fdd„ˆ  	¡ D ƒ‰ ˆj
ˆ d	d
d�}||_|S ntd| j› d�ƒ‚d S )Nc                 3  s   | ]\}}ˆ | V  qd S r   r   r   r   r   r   r!   l  r"   zPandas.group.<locals>.<genexpr>c                   s   g | ]\}}ˆ | ‘qS r   r   r   r   r   r   r#   o  r"   z Pandas.group.<locals>.<listcomp>c                   s    i | ]\}}t ||ƒˆ | “qS r   r$   r%   r   r   r   r'   r  r"   z Pandas.group.<locals>.<dictcomp>r   c                   s6   i | ].\}}|t |ˆ jˆ jfƒr$|nˆ j||d �“qS ))r   )rB   rÒ   Ú	DataFrame)r   rU   Úv)rÈ   r   r   r'   y  s
   ûÿr€   T)ZaxisZignore_indexr(   z}, how must be tuple, list, dict, str (for pandas.merge's 'how' parameter, or None (for one or moreDataFrames without merging))r   r)   r*   r+   rB   ÚstrrÎ   rI   rÓ   rŒ   ÚconcatrÌ   r,   r   )r   r    r-   r.   rr   rO   r   )r    rÈ   r   r/   h  s(    
úÿzPandas.groupc                   s˜   t |tƒr"t‡ ‡fdd„|D ƒƒS t |tƒr@‡ ‡fdd„|D ƒS t|jƒjdkr||jj}|jj}t|jƒ|ˆ  |ˆ  ƒ|_n|jj}t	j
|ˆ |d� |S )Nc                 3  s   | ]}ˆ  |ˆ ¡V  qd S r   ©r1   r…   ©r0   r   r   r   r!   Ž  r"   z&Pandas.global_index.<locals>.<genexpr>c                   s   g | ]}ˆ  |ˆ ¡‘qS r   r×   r…   rØ   r   r   r#   �  r"   z'Pandas.global_index.<locals>.<listcomp>rÃ   )rO   )rB   r)   r*   r6   r’   r:   ÚstartÚstopr    r   Úadd)r   r    r0   Zindex_startZ
index_stopr’   r   rØ   r   r1   Œ  s    

ÿzPandas.global_indexc                   s  | j ‰t|ƒdkr|S t|d ttfƒr:tt|d ƒƒ}n&t|d tƒrVt|d ƒ}n
ˆ |¡S dd„ |D ƒ‰|D ] }|D ]}ˆ|  || ¡ qzqr‡‡fdd„|D ƒ‰ t|d tƒrÌt‡ fdd„|D ƒƒS t|d tƒrì‡ fdd„|D ƒS t|d tƒ�r ˆ S d S )	Nr   c                 S  s   i | ]
}|g “qS r   r   rT   r   r   r   r'   ¬  r"   z&Pandas.concatenate.<locals>.<dictcomp>c                   s   i | ]}|ˆ   ˆ| ¡“qS r   )rÖ   rT   )rÈ   rV   r   r   r'   ±  r"   c                 3  s   | ]}ˆ | V  qd S r   r   rT   rW   r   r   r!   ´  r"   z%Pandas.concatenate.<locals>.<genexpr>c                   s   g | ]}ˆ | ‘qS r   r   rT   rW   r   r   r#   ¶  r"   z&Pandas.concatenate.<locals>.<listcomp>)	r   rI   rB   r)   r*   rY   r+   rÖ   rZ   r[   r   )rX   rÈ   rV   r   r3   Ÿ  s&    
zPandas.concatenateN)r:   r;   r<   r=   r   r>   r   r   r/   r1   r3   r   r   r   r   rÐ   @  s   

$rÐ   r   ZNumpyZNUMPYZawkward1ZAwkward1ZAWKWARD1ro   ZAWKWARDrÈ   ZPANDASc              
   C  sÎ   t | tƒr>| jtv rt| j S tdt| ƒj› d| j›d�ƒ‚nŒt | tƒrˆt| tƒrˆ| ƒ jtv rjt| ƒ j S td| j› d| ƒ j›d�ƒ‚nBz
t|  W S  tyÈ } ztd| ›d�ƒ|‚W Y d }~n
d }~0 0 d S )Nzlibrary z (z!) cannot be used in this functionze not recognized (for this function); try "np" (NumPy), "ak" (Awkward Array), or "pd" (Pandas) instead)	rB   r	   r   r7   Ú
ValueErrorr6   r:   r²   ÚKeyError)ZlibraryÚerrr   r   r   Ú_regularize_libraryÒ  s(    


ÿÿ

ÿürß   )NNNNN)r=   Ú
__future__r   rŸ   r   rC   r   r	   r?   rh   r‚   rš   r¢   r©   r¬   r­   rÉ   rÊ   rÍ   rÎ   rÏ   rÐ   r   r7   rß   r   r   r   r   Ú<module>   s\    \)f       ø
)|ý