
    gZ                     ,   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?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZH d dlImJZJ d dlKZKd dlLmMZM d dlNZNd dlOZPd dlOmQZQ d dlRmSZS d ZT eJdd	      ZUd
 ZVd ZWd ZXd ZYd ZZd Z[d Z\d Z] e]        d dZ^d!dddZ_ddddZ`d Zad"dddZbd"dddZcdddddZdd Zed Zfy)#    )HFunctionFunctionOptionsFunctionRegistryHashAggregateFunctionHashAggregateKernelKernelScalarAggregateFunctionScalarAggregateKernelScalarFunctionScalarKernelVectorFunctionVectorKernelArraySortOptionsAssumeTimezoneOptionsCastOptionsCountOptionsCumulativeOptionsCumulativeSumOptionsDayOfWeekOptionsDictionaryEncodeOptionsRunEndEncodeOptionsElementWiseAggregateOptionsExtractRegexOptionsFilterOptionsIndexOptionsJoinOptionsListSliceOptionsListFlattenOptionsMakeStructOptionsMapLookupOptionsMatchSubstringOptionsModeOptionsNullOptions
PadOptionsPairwiseOptionsPartitionNthOptionsQuantileOptionsRandomOptionsRankOptionsReplaceSliceOptionsReplaceSubstringOptionsRoundBinaryOptions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call_tabular_functionregister_scalar_functionregister_tabular_functionregister_aggregate_functionregister_vector_function
UdfContext
Expression)
namedtupleN)dedent)_compute_docstrings)	docscrapec                 .    | j                   j                  S N)_doc	arg_names)funcs    D/var/www/openai/venv/lib/python3.12/site-packages/pyarrow/compute.py_get_arg_namesrU   k   s    99    _OptionsClassDoc)paramsc                 v    | j                   sy t        j                  | j                         }t        |d         S )N
Parameters)__doc__rN   NumpyDocStringrW   )options_classdocs     rT   _scrape_options_class_docr_   r   s4      

"
"=#8#8
9CC-..rV   c           	         |j                   }t        |j                  |j                  |j                  |j
                        | _        || _        || _        g }|j                  }|s/|j                  dkD  rdnd}dj                  |j                  |      }|j                  | d       |j                  }|r|j                  | d       t        j                  j                  |j                        }	|j                  t!        d             t#        |      }
|
D ]=  }|j$                  d	v rd
}nd}|j                  | d| d       |j                  d       ? |2t'        |      }|rc|j(                  D ]S  }|j                  |j                   d|j*                   d       |j,                  D ]  }|j                  d| d        U nt/        j0                  d|j                   dt2               t5        j6                  |      }|j8                  j;                         D ]@  }|j                  t!        dj                  |j                  |j                                     B |j                  t!        d|j                   d             |j                  t!        d             |	8|j                  dj                  t!        |	      j=                  d                   dj?                  |      | _         | S )N)namearityr]   options_required   	argumentsargumentz,Call compute function {!r} with the given {}z.

z

z.        Parameters
        ----------
        )vector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
{}
 )!rQ   dictra   rb   r]   rc   __arrow_compute_function____name____qualname__summaryformatappenddescriptionrM   function_doc_additionsgetrL   rU   kindr_   rX   typedescwarningswarnRuntimeWarninginspect	signature
parametersvaluesstripjoinr[   )wrapperexposed_namerS   r]   cpp_doc
doc_piecesro   arg_strrr   doc_additionrR   arg_namearg_typeoptions_class_docpsoptions_sigs                    rT   _decorate_compute_functionr   y   s    iiG)-YYjj++ 11	*3G&
 $G'GJ ooG!%a+ZAF499g. 	 	'( %%K[M./&==AA$))LL f    t$I9966#H2HXJc(267?@   5mD&--!!QVVHCxr":;A%%QCrl3   .
 MMN=+A+A*B C6 78FH!++M:K ++224!!& * F166=#9#9:	#< = 5 	& &''4'='=&> ?"  	
 f    (//&*>*D*DT*JKLggj)GONrV   c                     | j                   j                  }|sy 	 t               |   S # t        $ r, t	        j
                  dj                  |      t               Y y w xY w)Nz!Python binding for {} not exposed)rQ   r]   globalsKeyErrorrx   ry   rp   rz   )rS   
class_names     rT   _get_options_classr      sV    ((Jy$$ 9vj)>	;s   ( 2AAc           	          |s|r$|t        dj                  |              ||i |S |Kt        |t              r |di |S t        ||      r|S t        dj                  | |t	        |                  y )NzMFunction {!r} called with both an 'options' argument and additional argumentsz-Function {!r} expected a {} parameter, got {} )	TypeErrorrp   
isinstancerk   rv   )ra   r]   optionsargskwargss        rT   _handle_optionsr      s    v+  d-f--gt$ +7++/N;VD-g79 	9 rV   c                 B     d d fd
}|S d d d fd
}|S )Nmemory_poolc           	          t         ur+t        |      k7  rt         d dt        |       d      |r2t        |d   t              rt	        j
                  t        |            S j                  |d |       S )N takes  positional argument(s), but  were givenr   )Ellipsislenr   r   rJ   _calllistcall)r   r   rb   rS   	func_names     rT   r   z&_make_generic_wrapper.<locals>.wrapper   s    H$Te); k 0t9+[2  
47J7!''	4:>>99T455rV   )r   r   c           	      2   t         ur6t        |      k  rt         d dt        |       d      |d  }|d  }nd}t        |||      }|r3t	        |d   t
              r t        j                  t        |      |      S j                  |||       S )Nr   r   r   r   r   )	r   r   r   r   r   rJ   r   r   r   )	r   r   r   r   option_argsrb   rS   r   r]   s	        rT   r   z&_make_generic_wrapper.<locals>.wrapper   s    H$t9u$#$+WUG 4"4yk6  #56lFU| %i&16;G
47J7!''	4:wGG99T7K88rV   r   )r   rS   r]   rb   r   s   ```` rT   _make_generic_wrapperr      s5    '+ 	6 	64 N! (,T 	9 	9  NrV   c                    ddl m} g }| D ]$  }|j                   |||j                               & |D ]$  }|j                   |||j                               & |t        j
                  |      }|j                  j                         D ]W  }|j                  |j                  |j                  fv sJ |r|j                  |j                        }|j                  |       Y |j                   |d|j                  d              |j                   |d|j                  d              t        j                  |      S )Nr   )	Parameter)ru   r   )defaultr   )r{   r   rq   POSITIONAL_ONLYVAR_POSITIONALr|   r}   r~   ru   POSITIONAL_OR_KEYWORDKEYWORD_ONLYreplace	Signature)rR   var_arg_namesr]   r   rX   ra   r   r   s           rT   _make_signaturer     s#   !Fii&?&?@A ii&>&>?@  ''6''..0A66i=='446 6 6 6II9#9#9I:MM! 1 	i	9+A+A(,. 	/
MM)M9+A+A$(* +V$$rV   c                    t        |      }t        |      }|xr |d   j                  d      }|r!|j                         j	                  d      g}ng }t        | |||j                        }t        |||      |_        t        || ||      S )N*)rb   )
r   rU   
startswithpoplstripr   rb   r   __signature__r   )ra   rS   r]   rR   
has_varargr   r   s          rT   _wrap_functionr   #  s    &t,Mt$I<y}77<J"//45#dM5G+I},9;G%gtT=IIrV   c                  B   t               } t               }ddd}|j                         D ]s  }|j                  ||      }|j	                  |      }|j
                  dk(  r6|j
                  dk(  r|j                  dk(  rU|| vsJ |       t        ||      x| |<   | |<   u y)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orhash_aggregaterh   r   N)r   rA   rC   rt   rB   ru   rb   r   )gregrewritescpp_namera   rS   s         rT   _make_global_functionsr   3  s     		A

C H &&(||Hh/)99(( 99**tzzQ 1}"d"} .tT ::(ag )rV   c                    |duxs |du}|r|t        d      |Xt        j                  j                  j	                  |      }|du rt        j                  |      }nt        j                  |      }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
    memory_pool : MemoryPool, optional
        memory pool to use for allocations during function execution.

    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
        The cast result as a new 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safer@   )arrtarget_typer   r   r   safe_vars_passeds         rT   r   r   S  s    l D(Fk.EW0 : ; 	; hhll..{;5=!((5G!&&{3G#==rV   r   c                b   |*|| j                  |||z
        } n&| j                  |      } n|| j                  d|      } t        |t        j                        s"t        j                  || j
                        }nH| j
                  |j
                  k7  r/t        j                  |j                         | j
                        }t        |      }t        d| g||      }|M|j                         dk\  r:t        j                  |j                         |z   t        j                               }|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
    r   rv   valueindex)
slicer   r   Scalarscalarrv   as_pyr   r@   int64)datar   startendr   r   results          rT   r   r     s    & ?::eS5[1D::e$D	zz!S!eRYY'		%dii0	ejj	 		%++-dii8'G7TFG[AFV\\^q06<<>E1
CMrV   T)boundscheckr   c                :    t        |      }t        d| |g||      S )a  
    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
        Selected values for the given indices

    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)r:   r@   )r   indicesr   r   r   s        rT   r   r     s$    P k2G$';GGrV   c                 d   t        |t        j                  t        j                  t        j                  f      s"t        j
                  || j                        }nH| j                  |j                  k7  r/t        j
                  |j                         | j                        }t        d| |g      S )ae  Replace each null element in values with a corresponding
    element from fill_value.

    If fill_value is scalar-like, then every null element in values
    will be replaced with fill_value. If fill_value is array-like,
    then the i-th element in values will be replaced with the i-th
    element in fill_value.

    The fill_value's type must be the same as that of values, or it
    must be 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 values, will attempt to cast.

    Returns
    -------
    result : depends on inputs
        Values with all null elements replaced

    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
    ]
    >>> arr = pa.array([1, 2, None, 4, None])
    >>> arr.fill_null(pa.array([10, 20, 30, 40, 50]))
    <pyarrow.lib.Int64Array object at ...>
    [
      1,
      2,
      30,
      4,
      50
    ]
    r   coalesce)	r   r   ArrayChunkedArrayr   r   rv   r   r@   )r~   
fill_values     rT   	fill_nullr     su    f j288R__bii"HIYYz<
	
	'YYz//1D
fj%9::rV   c                    |g }t        | t        j                  t        j                  f      r|j	                  d       nt        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
        Indices of the top-k ordered elements

    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
    ]
    )dummy
descendingc                 
    | dfS )Nr   r   key_names    rT   <lambda>z top_k_unstable.<locals>.<lambda>O  s	    (L)ArV   select_k_unstabler   r   r   r   rq   mapr1   r@   r~   k	sort_keysr   r   s        rT   top_k_unstabler   %  sc    J 	&288R__5601A9M	Q	*G,vhMMrV   c                    |g }t        | t        j                  t        j                  f      r|j	                  d       nt        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
        Indices of the bottom-k ordered elements

    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
    ]
    )r   	ascendingc                 
    | dfS )Nr   r   r   s    rT   r   z#bottom_k_unstable.<locals>.<lambda>~  s	    (K)@rV   r   r   r   s        rT   bottom_k_unstabler   T  sc    J 	&288R__56/0@)L	Q	*G,vhMMrV   system)initializerr   r   c                :    t        |      }t        dg |||       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(   r@   )nr  r   r   s       rT   r  r    s!    , 4G2wAFFrV   c                  8   t        |       }|dk(  rvt        | d   t        t        f      rt	        j
                  | d         S t        | d   t              rt	        j                  | d         S t        dt        | d                t	        j                  |       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
        Reference to the given field

    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) ...
    rd   r   zCfield reference should be str, multiple str, tuple or integer, got )
r   r   strintrJ   _fieldtuple_nested_fieldr   rv   )name_or_indexr  s     rT   fieldr    s    B 	MAAvmA&c
3$$]1%566a(%0++M!,<==  $]1%5 679  ''66rV   c                 ,    t        j                  |       S )aB  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
        An Expression representing the scalar value
    )rJ   _scalarr   s    rT   r   r     s     e$$rV   )NNNN)NNrP   )g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/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   collectionsrK   r{   textwraprL   rx   pyarrowr   rM   pyarrow.vendoredrN   rU   rW   r_   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r   rV   rT   <module>r     s7  $M M M M M M M M M M M M M M M M M M M^ #     ' & 0+> /Pf	*>%.J ;:  B>J#D #L (, )HX8;v,NT ,N^,N ,N^ &t G4.7b%rV   