U Dx`4@s,ddlmZmZmZmZmZmZmZmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlm Z ddl!Z!ddl"Z#ddZ$ddZ%dd Z&d d Z'e d Z(e d Z)ddZ*ddZ+e+d$ddZ,ddZ-ddZ.d%ddZ/d&ddZ0dddd d!Z1d"d#Z2dS)')FunctionFunctionOptionsFunctionRegistryKernelScalarAggregateFunctionScalarAggregateKernelScalarFunction ScalarKernelVectorFunction VectorKernel CastOptions CountOptions FilterOptionsMatchSubstringOptions SplitOptionsSplitPatternOptions MinMaxOptions ModeOptionsPartitionNthOptionsProjectOptionsSetLookupOptionsStrptimeOptions TakeOptionsVarianceOptionsArraySortOptions SortOptionsfunction_registry call_function get_functionlist_functionsdedentNcCsP|jj}|sL|jdkrdg}n.|jdkr2ddg}ntd|jd|jd|S) Nargleftrightzunsupported arity: z (function: ))_doc arg_namesarityNotImplementedErrorname)funcr)r.6/tmp/pip-target-oguziej0/lib/python/pyarrow/compute.py_get_arg_names;s   r0c Cst|j|jd|_||_||_g}|j}|j}|sR|jdkr@dnd}d|j|}|j }t |} | d||r| d|| d| D]*} |j d krd } nd } | d | | q| d |dk r| d|jd dd|D|_|S)N)r,r*r" argumentsargumentz,Call compute function {!r} with the given {}z {}. z{} z. Parameters ---------- )ZvectorZscalar_aggregatez Array-likezArray-like or scalar-likezM {} : {} Argument to compute function z memory_pool : pyarrow.MemoryPool, optional If not passed, will allocate memory from the default memory pool. a- options : pyarrow.compute.{0}, optional Parameters altering compute function semantics **kwargs : optional Parameters for {0} constructor. Either `options` or `**kwargs` can be passed, but not both at the same time. css|]}t|VqdS)Nr ).0sr.r.r/ sz-_decorate_compute_function..)dictr,r*Z__arrow_compute_function____name__ __qualname__r(summaryformat descriptionr0appendkindjoin__doc__) wrapperZ exposed_namer- option_classZ doc_piecesZcpp_docr:Zarg_strr<r)Zarg_nameZarg_typer.r.r/_decorate_compute_functionIsJ   rCcCsJ|jj}|sdSz t|WStk rDtd|tYdSXdS)Nz!Python binding for {} not exposed)r(Z options_classglobalsKeyErrorwarningswarnr;RuntimeWarning)r- class_namer.r.r/_get_options_classs rJcCsh|r$|dkr|f|Std||dk rdt|tr@|f|St||rN|Std||t||S)NzSFunction {!r} called with both an 'options' argument and additional named argumentsz-Function {!r} expected a {} parameter, got {}) TypeErrorr; isinstancer7type)r,rBoptionskwargsr.r.r/_handle_optionss*    rPz def make_wrapper(func, option_class): def {func_name}({args_sig}{kwonly}, memory_pool=None): return func.call([{args_sig}], None, memory_pool) return {func_name} as def make_wrapper(func, option_class): def {func_name}({args_sig}{kwonly}, options=None, memory_pool=None, **kwargs): options = _handle_options({func_name!r}, option_class, options, kwargs) return func.call([{args_sig}], options, memory_pool) return {func_name} c Cs|t|}t|}d|}|ddr,dnd}i}|dk rBt}nt}t|j|||dt||d||}t ||||S)Nz, *r3z, *) func_nameargs_sigkwonlyZ make_wrapper) rJr0r? startswith_wrapper_options_template_wrapper_templateexecr;rDrC) r,r-rBr)rTrUnstemplaterAr.r.r/_wrap_functions r\cCsdt}t}ddd}|D]@}|||}||}||ksHt|t||||<||<qdS)z Make global functions wrapping each compute function. Note that some of the automatically-generated wrappers may be overriden by custom versions below. and_or_)andorN)rDrrgetrAssertionErrorr\)gregZrewritesZcpp_namer,r-r.r.r/_make_global_functionss   reTcCs8|dkrtd|r t|}n t|}td|g|S)a Cast array values to another data type. Can also be invoked as an array instance method. Parameters ---------- arr : Array or ChunkedArray target_type : DataType or type string alias Type to cast to safe : bool, default True Check for overflows or other unsafe conversions 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')) [ 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]') [ 1262304000000, 1420070400000 ] >>> arr.cast('timestamp[ms]').type TimestampType(timestamp[ms]) Returns ------- casted : Array Nz!Cast target type must not be Nonecast) ValueErrorr safeunsafer)ZarrZ target_typerhrNr.r.r/rfs 1  rfcCstd|gt|S)a/ Test if substring *pattern* is contained within a value of a string array. Parameters ---------- array : pyarrow.Array or pyarrow.ChunkedArray pattern : str pattern to search for exact matches Returns ------- result : pyarrow.Array or pyarrow.ChunkedArray match_substring)rr)arraypatternr.r.r/rjsrjcCs td|gS)z Sum the values in a numerical (chunked) array. Parameters ---------- array : pyarrow.Array or pyarrow.ChunkedArray Returns ------- sum : pyarrow.Scalar sum)r)rkr.r.r/rm.s rmr"cCst|d}td|g|S)a Return top-n most common values and number of times they occur in a passed numerical (chunked) array, in descending order of occurance. If there are more than one values with same count, smaller one is returned first. Parameters ---------- array : pyarrow.Array or pyarrow.ChunkedArray Returns ------- An array of structs Examples -------- >>> import pyarrow as pa >>> import pyarrow.compute as pc >>> arr = pa.array([1, 1, 2, 2, 3, 2, 2, 2]) >>> modes = pc.mode(arr, 2) >>> modes[0] >>> modes[1] )nmode)rr)rkrnrNr.r.r/ro=s rodropcCst|}td||g|S)a1 Select values (or records) from array- or table-like data given boolean filter, where true values are selected. Parameters ---------- data : Array, ChunkedArray, RecordBatch, or Table mask : Array, ChunkedArray Must be of boolean type null_selection_behavior : str, default 'drop' Configure the behavior on encountering a null slot in the mask. Allowed values are 'drop' and 'emit_null'. - 'drop': nulls will be treated as equivalent to False. - 'emit_null': nulls will result in a null in the output. Returns ------- result : depends on inputs Examples -------- >>> import pyarrow as pa >>> arr = pa.array(["a", "b", "c", None, "e"]) >>> mask = pa.array([True, False, None, False, True]) >>> arr.filter(mask) [ "a", "e" ] >>> arr.filter(mask, null_selection_behavior='emit_null') [ "a", null, "e" ] filter)rr)datamaskZnull_selection_behaviorrNr.r.r/rqZs(rq) boundscheck memory_poolcCst|d}td||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. 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) [ "a", null, "e", null ] )rttake)rr)rrindicesrtrurNr.r.r/rvs% rvcCsLt|tjstj||jd}n |j|jkr>tj||jd}td||gS)a 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. Parameters ---------- data : Array, ChunkedArray replace each null element with fill_value fill_value: Scalar-like object Either a pyarrow.Scalar or any python object coercible to a Scalar. 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 0x7f95437f01a0> [ 1, 2, 5, 3 ] )rM fill_null)rLpaZScalarZscalarrMZas_pyr)valuesZ fill_valuer.r.r/rxs  rx)T)r")rp)3Zpyarrow._computerrrrrrrr r r r r rrrrrrrrrrrrrrrrrrtextwrapr!rFZpyarrowryr0rCrJrPrXrWr\rerfrjrmrorqrvrxr.r.r.r/s&# :   :  ,)