a
    yn„fË  ã                   @  sd   d dl mZ d dlmZ d dlZd dlmZ d dlm	Z	 dZ
e ¡ Ze	ƒ ddœd	d
„ƒZdd„ ZdS )é    )Úannotations)ÚMappingN)ÚNumpyBackend)Úhigh_level_function)Úto_rdataframeT©Úflatlist_as_rvecc                c  s   |   ¡ V  t| |d�S )aŒ  
    Args:
        arrays (dict of arrays): Each value in this dict can be any array-like data
            that #ak.to_layout recognizes, but they must all have the same length.
        flatlist_as_rvec (bool): If True, lists of primitive types (numbers, booleans, etc.)
            are presented to C++ as `ROOT::RVec<primitive>`, but all other types use
            Awkward Array's custom C++ classes. If False, even these "flat" lists use
            Awkward Array's custom C++ classes.

    Converts an Awkward Array into ROOT Data Frame columns:

        >>> x = ak.Array([
        ...     [1.1, 2.2, 3.3],
        ...     [],
        ...     [4.4, 5.5],
        ... ])
        >>> y = ak.Array([
        ...     {"a": 1.1, "b": [1]},
        ...     {"a": 2.2, "b": [2, 1]},
        ...     {"a": 3.3, "b": [3, 2, 1]},
        ... ])

        >>> rdf = ak.to_rdataframe({"x": x, "y": y})
        >>> rdf.Define("z", "ROOT::VecOps::Sum(x) + y.a() + y.b()[0]").AsNumpy(["z"])
        {'z': ndarray([ 8.7,  4.2, 16.2])}

        >>> ak.sum(x, axis=-1) + y.a + y.b[:, 0]
        <Array [8.7, 4.2, 16.2] type='3 * float64'>

    See also #ak.from_rdataframe.
    r   )ÚvaluesÚ_impl)Úarraysr   © r   úf/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/operations/ak_to_rdataframe.pyr      s
    "
þr   c                 C  sÎ   dd l }t| tƒstdƒ‚n0tdd„ | D ƒƒs8tdƒ‚nt| ƒdkrLtdƒ‚i }d }|  ¡ D ]Z\}}tjj	j
|dddd	d	d
dd� t¡||< |d u r || j}q\||| jkr\tdƒ‚q\tjjjj|||d�S )Nr   z='arrays' must be a dict (to provide C++ names for the arrays)c                 s  s   | ]}t |tƒV  qd S )N)Ú
isinstanceÚstr)Ú.0Únamer   r   r   Ú	<genexpr>C   ó    z_impl.<locals>.<genexpr>zKkeys of 'arrays' dict must be strings (to provide C++ names for the arrays)z('arrays' must contain at least one arrayFÚerrorTZforbidzas-characters)Zallow_recordZallow_unknownZnone_policyZregulararrayZuse_from_iterZprimitive_policyZstring_policyz(lengths of 'arrays' must all be the samer   )Z)awkward._connect.rdataframe.to_rdataframer   r   Ú	TypeErrorÚallÚlenÚitemsÚakÚ
operationsZak_to_layoutr
   Z
to_backendÚcpuÚlengthÚ
ValueErrorÚ_connectZ
rdataframer   )r   r   ÚawkwardZlayoutsr   r   Úarrayr   r   r   r
   ;   sB    

ÿø	÷


ýr
   )Ú
__future__r   Úcollections.abcr   r   r   Zawkward._backends.numpyr   Zawkward._dispatchr   Ú__all__Úinstancer   r   r
   r   r   r   r   Ú<module>   s   *