a
    5PÎj$U  ã                   @   s*  d dl mZmZmZmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z? d dl@mAZA d dlBZBd dlCmDZD d dlEZEd dlFZGd dlFmHZH d dlImJZJ dd„ ZKeAd	d
ƒZLdd„ ZMdd„ ZNdd„ ZOdd„ ZPdd„ ZQdd„ ZRdd„ ZSdd„ ZTeTƒ  dddfdd„ZUddfddœdd„ZVd dd!œd"d#„ZWd$d%„ ZXdfddœd&d'„ZYdfddœd(d)„ZZd*ddd+œd,d-„Z[d.d/„ Z\d0d1„ Z]dS )2é    )?ÚFunctionÚFunctionOptionsÚFunctionRegistryÚHashAggregateFunctionÚHashAggregateKernelÚKernelÚScalarAggregateFunctionÚScalarAggregateKernelÚScalarFunctionÚScalarKernelÚVectorFunctionÚVectorKernelÚArraySortOptionsÚAssumeTimezoneOptionsÚCastOptionsÚCountOptionsÚCumulativeSumOptionsÚDayOfWeekOptionsÚDictionaryEncodeOptionsÚElementWiseAggregateOptionsÚExtractRegexOptionsÚFilterOptionsÚIndexOptionsÚJoinOptionsÚMakeStructOptionsÚMapLookupOptionsÚMatchSubstringOptionsÚModeOptionsÚNullOptionsÚ
PadOptionsÚPartitionNthOptionsÚQuantileOptionsÚRandomOptionsÚRankOptionsÚReplaceSliceOptionsÚReplaceSubstringOptionsÚRoundOptionsÚRoundTemporalOptionsÚRoundToMultipleOptionsÚScalarAggregateOptionsÚSelectKOptionsÚSetLookupOptionsÚSliceOptionsÚSortOptionsÚSplitOptionsÚSplitPatternOptionsÚStrftimeOptionsÚStrptimeOptionsÚStructFieldOptionsÚTakeOptionsÚTDigestOptionsÚTrimOptionsÚUtf8NormalizeOptionsÚVarianceOptionsÚWeekOptionsÚcall_functionÚfunction_registryÚget_functionÚlist_functionsÚ	_group_byÚregister_scalar_functionÚScalarUdfContextÚ
Expression)Ú
namedtupleN)Údedent)Ú_compute_docstrings)Ú	docscrapec                 C   s   | j jS )N)Ú_docÚ	arg_names)Úfunc© rH   ú_/mounts/lovelace/software/anaconda3/envs/metadmg/lib/python3.9/site-packages/pyarrow/compute.pyÚ_get_arg_namesb   s    rJ   Ú_OptionsClassDoc)Úparamsc                 C   s"   | j s
d S t | j ¡}t|d ƒS )NZ
Parameters)Ú__doc__rD   ZNumpyDocStringrK   )Úoptions_classÚdocrH   rH   rI   Ú_scrape_options_class_doci   s    rP   c                 C   sî  |j }t|j|j|j|jd�| _|| _|| _g }|j	}|sZ|jdkrHdnd}d 
|j|¡}| |› d�¡ |j}|r„| |› d�¡ tj |j¡}	| tdƒ¡ t|ƒ}
|
D ]8}|jd	v rÀd
}nd}| |› d|› d�¡ | d¡ q¬|d u�r¬t|ƒ}|�rH|jD ]@}| |j› d|j› d�¡ |jD ]}| d|› d�¡ �q(�qnLt d|j› d�t¡ t |¡}|j ¡ D ] }| td 
|j|j¡ƒ¡ �qr| td|j› d�ƒ¡ | tdƒ¡ |	d u�rÞ| d 
t|	ƒ d¡¡¡ d |¡| _ | S )N)ÚnameÚarityrN   Úoptions_requiredé   Ú	argumentsÚargumentz,Call compute function {!r} with the given {}z.

z

z.        Parameters
        ----------
        )ZvectorZscalar_aggregatez
Array-likezArray-like or scalar-likez : Ú
z"    Argument to compute function.
z    zOptions class z does not have a docstringz¾                {0} : optional
                    Parameter for {1} constructor. Either `options`
                    or `{0}` can be passed, but not both at the same time.
                z&            options : pyarrow.compute.zK, optional
                Alternative way of passing options.
            z‰        memory_pool : pyarrow.MemoryPool, optional
            If not passed, will allocate memory from the default memory pool.
        z
{}
Ú )!rE   ÚdictrQ   rR   rN   rS   Z__arrow_compute_function__Ú__name__Ú__qualname__ÚsummaryÚformatÚappendÚdescriptionrC   Zfunction_doc_additionsÚgetrB   rJ   ÚkindrP   rL   ÚtypeÚdescÚwarningsÚwarnÚRuntimeWarningÚinspectÚ	signatureÚ
parametersÚvaluesÚstripÚjoinrM   )ÚwrapperZexposed_namerG   rN   Zcpp_docZ
doc_piecesr\   Zarg_strr_   Zdoc_additionrF   Zarg_nameZarg_typeZoptions_class_docÚpÚsÚoptions_sigrH   rH   rI   Ú_decorate_compute_functionp   sh    üÿ



ÿ

üÿ
rq   c                 C   sH   | j j}|sd S ztƒ | W S  tyB   t d |¡t¡ Y d S 0 d S )Nz!Python binding for {} not exposed)rE   rN   ÚglobalsÚKeyErrorrd   re   r]   rf   )rG   Ú
class_namerH   rH   rI   Ú_get_options_classÃ   s    ÿÿru   c                 C   st   |s|r,|d urt d | ¡ƒ‚||i |¤ŽS |d urpt|tƒrL|f i |¤ŽS t||ƒrZ|S t d | |t|ƒ¡ƒ‚d S )NzMFunction {!r} called with both an 'options' argument and additional argumentsz-Function {!r} expected a {} parameter, got {})Ú	TypeErrorr]   Ú
isinstancerY   rb   )rQ   rN   ÚoptionsÚargsÚkwargsrH   rH   rI   Ú_handle_optionsÏ   s&    þÿ


ÿÿr{   c                    s>   ˆd u r d dœ‡ ‡‡fdd„
}nd d dœ‡ ‡‡‡fdd„
}|S )N©Úmemory_poolc                    sb   ˆ t ur2t|ƒˆ kr2tˆ› dˆ › dt|ƒ› d�ƒ‚|rTt|d tƒrTt ˆt|ƒ¡S ˆ |d | ¡S )Nú takes ú positional argument(s), but ú were givenr   )ÚEllipsisÚlenrv   rw   r@   Ú_callÚlistÚcall)r}   ry   )rR   rG   Ú	func_namerH   rI   rm   æ   s    ÿÿz&_make_generic_wrapper.<locals>.wrapper)r}   rx   c                    s’   ˆ t urLt|ƒˆ k r2tˆ› dˆ › dt|ƒ› d�ƒ‚|ˆ d … }|d ˆ … }nd}tˆˆ|||ƒ}|r„t|d tƒr„t ˆt|ƒ|¡S ˆ ||| ¡S )Nr~   r   r€   rH   r   )	r�   r‚   rv   r{   rw   r@   rƒ   r„   r…   )r}   rx   ry   rz   Zoption_args©rR   rG   r†   rN   rH   rI   rm   ð   s     ÿÿÿrH   )r†   rG   rN   rR   rm   rH   r‡   rI   Ú_make_generic_wrapperä   s    
rˆ   c                 C   sÒ   ddl m} g }| D ]}| |||jƒ¡ q|D ]}| |||jƒ¡ q0|d ur²t  |¡}|j ¡ D ]6}|j|j	|j
fv s~J ‚|r�|j|j
d�}| |¡ qd| |d|j
d d�¡ | |d|j
d d�¡ t  |¡S )Nr   )Ú	Parameter)ra   rx   )Údefaultr}   )rg   r‰   r^   ÚPOSITIONAL_ONLYÚVAR_POSITIONALrh   ri   rj   ra   ÚPOSITIONAL_OR_KEYWORDÚKEYWORD_ONLYÚreplaceÚ	Signature)rF   Úvar_arg_namesrN   r‰   rL   rQ   rp   rn   rH   rH   rI   Ú_make_signature  s,    
ÿ
ÿÿr’   c                 C   sj   t |ƒ}t|ƒ}|o |d  d¡}|r8| ¡  d¡g}ng }t| |||jd�}t|||ƒ|_t	|| ||ƒS )NéÿÿÿÿÚ*)rR   )
ru   rJ   Ú
startswithÚpopÚlstriprˆ   rR   r’   Ú__signature__rq   )rQ   rG   rN   rF   Z
has_varargr‘   rm   rH   rH   rI   Ú_wrap_function  s    
ÿÿr™   c                  C   sp   t ƒ } tƒ }dddœ}| ¡ D ]L}| ||¡}| |¡}|jdkrDq|| vsTJ |ƒ‚t||ƒ | |< | |< qdS )z«
    Make global functions wrapping each compute function.

    Note that some of the automatically-generated wrappers may be overridden
    by custom versions below.
    Úand_Úor_)ÚandÚorZhash_aggregateN)rr   r:   r<   r`   r;   ra   r™   )ÚgÚregZrewritesZcpp_namerQ   rG   rH   rH   rI   Ú_make_global_functions*  s    ÿ

r    c                 C   sf   |dup|du}|r$|dur$t dƒ‚|du rXtjj |¡}|du rNt |¡}n
t |¡}td| g|ƒS )aò  
    Cast array values to another data type. Can also be invoked as an array
    instance method.

    Parameters
    ----------
    arr : Array-like
    target_type : DataType or str
        Type to cast to
    safe : bool, default True
        Check for overflows or other unsafe conversions
    options : CastOptions, default None
        Additional checks pass by CastOptions

    Examples
    --------
    >>> from datetime import datetime
    >>> import pyarrow as pa
    >>> arr = pa.array([datetime(2010, 1, 1), datetime(2015, 1, 1)])
    >>> arr.type
    TimestampType(timestamp[us])

    You can use ``pyarrow.DataType`` objects to specify the target type:

    >>> cast(arr, pa.timestamp('ms'))
    <pyarrow.lib.TimestampArray object at ...>
    [
      2010-01-01 00:00:00.000,
      2015-01-01 00:00:00.000
    ]

    >>> cast(arr, pa.timestamp('ms')).type
    TimestampType(timestamp[ms])

    Alternatively, it is also supported to use the string aliases for these
    types:

    >>> arr.cast('timestamp[ms]')
    <pyarrow.lib.TimestampArray object at ...>
    [
      2010-01-01 00:00:00.000,
      2015-01-01 00:00:00.000
    ]
    >>> arr.cast('timestamp[ms]').type
    TimestampType(timestamp[ms])

    Returns
    -------
    casted : Array
    NzRMust either pass values for 'target_type' and 'safe' or pass a value for 'options'FÚcast)	Ú
ValueErrorÚpaÚtypesÚlibÚensure_typer   ÚunsafeÚsafer9   )ZarrZtarget_typer¨   rx   Zsafe_vars_passedrH   rH   rI   r¡   F  s    3
r¡   r|   c                C   sÌ   |dur.|dur"|   ||| ¡} qB|   |¡} n|durB|   d|¡} t|tjƒs`tj|| jd�}n | j|jkr€tj| ¡ | jd�}t|d�}td| g||ƒ}|durÈ| ¡ dkrÈtj| ¡ | t 	¡ d�}|S )a©  
    Find the index of the first occurrence of a given value.

    Parameters
    ----------
    data : Array-like
    value : Scalar-like object
        The value to search for.
    start : int, optional
    end : int, optional
    memory_pool : MemoryPool, optional
        If not passed, will allocate memory from the default memory pool.

    Returns
    -------
    index : int
        the index, or -1 if not found
    Nr   ©rb   ©ÚvalueÚindex)
Úslicerw   r£   ÚScalarÚscalarrb   Úas_pyr   r9   Zint64)Údatar«   ÚstartÚendr}   rx   ÚresultrH   rH   rI   r¬   ˆ  s    
r¬   T)Úboundscheckr}   c                C   s   t |d�}td| |g||ƒS )ah  
    Select values (or records) from array- or table-like data given integer
    selection indices.

    The result will be of the same type(s) as the input, with elements taken
    from the input array (or record batch / table fields) at the given
    indices. If an index is null then the corresponding value in the output
    will be null.

    Parameters
    ----------
    data : Array, ChunkedArray, RecordBatch, or Table
    indices : Array, ChunkedArray
        Must be of integer type
    boundscheck : boolean, default True
        Whether to boundscheck the indices. If False and there is an out of
        bounds index, will likely cause the process to crash.
    memory_pool : MemoryPool, optional
        If not passed, will allocate memory from the default memory pool.

    Returns
    -------
    result : depends on inputs

    Examples
    --------
    >>> import pyarrow as pa
    >>> arr = pa.array(["a", "b", "c", None, "e", "f"])
    >>> indices = pa.array([0, None, 4, 3])
    >>> arr.take(indices)
    <pyarrow.lib.StringArray object at ...>
    [
      "a",
      null,
      "e",
      null
    ]
    )rµ   Útake)r3   r9   )r±   Úindicesrµ   r}   rx   rH   rH   rI   r¶   ®  s    '
r¶   c                 C   sV   t |tjtjtjfƒs(tj|| jd�}n | j|jkrHtj| ¡ | jd�}td| |gƒS )aQ  
    Replace each null element in values with fill_value. The fill_value must be
    the same type as values or able to be implicitly casted to the array's
    type.

    This is an alias for :func:`coalesce`.

    Parameters
    ----------
    values : Array, ChunkedArray, or Scalar-like object
        Each null element is replaced with the corresponding value
        from fill_value.
    fill_value : Array, ChunkedArray, or Scalar-like object
        If not same type as data will attempt to cast.

    Returns
    -------
    result : depends on inputs

    Examples
    --------
    >>> import pyarrow as pa
    >>> arr = pa.array([1, 2, None, 3], type=pa.int8())
    >>> fill_value = pa.scalar(5, type=pa.int8())
    >>> arr.fill_null(fill_value)
    <pyarrow.lib.Int8Array object at ...>
    [
      1,
      2,
      5,
      3
    ]
    r©   Zcoalesce)	rw   r£   ÚArrayÚChunkedArrayr®   r¯   rb   r°   r9   )rj   Z
fill_valuerH   rH   rI   Ú	fill_nullÙ  s
    "rº   c                C   sR   |du rg }t | tjtjfƒr*| d¡ ntdd„ |ƒ}t||ƒ}td| g||ƒS )a•  
    Select the indices of the top-k ordered elements from array- or table-like
    data.

    This is a specialization for :func:`select_k_unstable`. Output is not
    guaranteed to be stable.

    Parameters
    ----------
    values : Array, ChunkedArray, RecordBatch, or Table
        Data to sort and get top indices from.
    k : int
        The number of `k` elements to keep.
    sort_keys : List-like
        Column key names to order by when input is table-like data.
    memory_pool : MemoryPool, optional
        If not passed, will allocate memory from the default memory pool.

    Returns
    -------
    result : Array of indices

    Examples
    --------
    >>> import pyarrow as pa
    >>> import pyarrow.compute as pc
    >>> arr = pa.array(["a", "b", "c", None, "e", "f"])
    >>> pc.top_k_unstable(arr, k=3)
    <pyarrow.lib.UInt64Array object at ...>
    [
      5,
      4,
      2
    ]
    N)ÚdummyÚ
descendingc                 S   s   | dfS )Nr¼   rH   ©Zkey_namerH   rH   rI   Ú<lambda>,  ó    z top_k_unstable.<locals>.<lambda>Úselect_k_unstable©rw   r£   r¸   r¹   r^   Úmapr*   r9   ©rj   ÚkÚ	sort_keysr}   rx   rH   rH   rI   Útop_k_unstable  s    $
rÆ   c                C   sR   |du rg }t | tjtjfƒr*| d¡ ntdd„ |ƒ}t||ƒ}td| g||ƒS )až  
    Select the indices of the bottom-k ordered elements from
    array- or table-like data.

    This is a specialization for :func:`select_k_unstable`. Output is not
    guaranteed to be stable.

    Parameters
    ----------
    values : Array, ChunkedArray, RecordBatch, or Table
        Data to sort and get bottom indices from.
    k : int
        The number of `k` elements to keep.
    sort_keys : List-like
        Column key names to order by when input is table-like data.
    memory_pool : MemoryPool, optional
        If not passed, will allocate memory from the default memory pool.

    Returns
    -------
    result : Array of indices

    Examples
    --------
    >>> import pyarrow as pa
    >>> import pyarrow.compute as pc
    >>> arr = pa.array(["a", "b", "c", None, "e", "f"])
    >>> pc.bottom_k_unstable(arr, k=3)
    <pyarrow.lib.UInt64Array object at ...>
    [
      0,
      1,
      2
    ]
    N)r»   Ú	ascendingc                 S   s   | dfS )NrÇ   rH   r½   rH   rH   rI   r¾   Z  r¿   z#bottom_k_unstable.<locals>.<lambda>rÀ   rÁ   rÃ   rH   rH   rI   Úbottom_k_unstable1  s    $
rÈ   Úsystem)Úinitializerrx   r}   c                C   s   t |d�}tdg ||| d�S )aB  
    Generate numbers in the range [0, 1).

    Generated values are uniformly-distributed, double-precision
    in range [0, 1). Algorithm and seed can be changed via RandomOptions.

    Parameters
    ----------
    n : int
        Number of values to generate, must be greater than or equal to 0
    initializer : int or str
        How to initialize the underlying random generator.
        If an integer is given, it is used as a seed.
        If "system" is given, the random generator is initialized with
        a system-specific source of (hopefully true) randomness.
        Other values are invalid.
    options : pyarrow.compute.RandomOptions, optional
        Alternative way of passing options.
    memory_pool : pyarrow.MemoryPool, optional
        If not passed, will allocate memory from the default memory pool.
    )rÊ   Úrandom)Úlength)r"   r9   )ÚnrÊ   rx   r}   rH   rH   rI   rË   _  s    
rË   c                  G   sr   t | ƒ}|dkrdt| d ttfƒr0t | d ¡S t| d tƒrLt | d ¡S tdt	| d ƒ› �ƒ‚n
t | ¡S dS )aà  Reference a column of the dataset.

    Stores only the field's name. Type and other information is known only when
    the expression is bound to a dataset having an explicit scheme.

    Nested references are allowed by passing multiple names or a tuple of
    names. For example ``('foo', 'bar')`` references the field named "bar"
    inside the field named "foo".

    Parameters
    ----------
    *name_or_index : string, multiple strings, tuple or int
        The name or index of the (possibly nested) field the expression
        references to.

    Returns
    -------
    field_expr : Expression

    Examples
    --------
    >>> import pyarrow.compute as pc
    >>> pc.field("a")
    <pyarrow.compute.Expression a>
    >>> pc.field(1)
    <pyarrow.compute.Expression FieldPath(1)>
    >>> pc.field(("a", "b"))
    <pyarrow.compute.Expression FieldRef.Nested(FieldRef.Name(a) ...
    >>> pc.field("a", "b")
    <pyarrow.compute.Expression FieldRef.Nested(FieldRef.Name(a) ...
    rT   r   zCfield reference should be str, multiple str, tuple or integer, got N)
r‚   rw   ÚstrÚintr@   Z_fieldÚtupleZ_nested_fieldrv   rb   )Zname_or_indexrÍ   rH   rH   rI   Úfieldy  s     
ÿÿrÑ   c                 C   s
   t  | ¡S )a  Expression representing a scalar value.

    Parameters
    ----------
    value : bool, int, float or string
        Python value of the scalar. Note that only a subset of types are
        currently supported.

    Returns
    -------
    scalar_expr : Expression
    )r@   Z_scalarrª   rH   rH   rI   r¯   ©  s    r¯   )^Zpyarrow._computer   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   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   ÚcollectionsrA   rg   ÚtextwraprB   rd   Zpyarrowr£   rC   Zpyarrow.vendoredrD   rJ   rK   rP   rq   ru   r{   rˆ   r’   r™   r    r¡   r¬   r¶   rº   rÆ   rÈ   rË   rÑ   r¯   rH   rH   rH   rI   Ú<module>   s8   ÿ F
SB&+*..0