d}i9b~ddlmZmZmZmZmZmZmZmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm 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;mZ>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPddlQmRZRddlSZSddlTmUZUddlVZVddlWZXddlWmYZYddlZm[Z[dZ\eRdd Z]d Z^d Z_d Z`d ZadZbdZcdZddZeeeefdxZgZhd!dZid"dddZjddddZkdZld#dddZmd#dddZndddddZodZpd ZqdS)$)PFunctionFunctionOptionsFunctionRegistryHashAggregateFunctionHashAggregateKernelKernelScalarAggregateFunctionScalarAggregateKernelScalarFunction ScalarKernelVectorFunction VectorKernelArraySortOptionsAssumeTimezoneOptions CastOptions CountOptionsCumulativeOptionsCumulativeSumOptionsDayOfWeekOptionsDictionaryEncodeOptionsRunEndEncodeOptionsElementWiseAggregateOptionsExtractRegexOptionsExtractRegexSpanOptions FilterOptions IndexOptionsInversePermutationOptions JoinOptionsListSliceOptionsListFlattenOptionsMakeStructOptionsMapLookupOptionsMatchSubstringOptions ModeOptions NullOptions PadOptionsPairwiseOptionsPartitionNthOptionsPivotWiderOptionsQuantileOptions RandomOptions RankOptionsRankQuantileOptionsReplaceSliceOptionsReplaceSubstringOptionsRoundBinaryOptions RoundOptionsRoundTemporalOptionsRoundToMultipleOptionsScalarAggregateOptionsScatterOptionsSelectKOptionsSetLookupOptions SkewOptions SliceOptions SortOptions SplitOptionsSplitPatternOptionsStrftimeOptionsStrptimeOptionsStructFieldOptions TakeOptionsTDigestOptions TrimOptionsUtf8NormalizeOptionsVarianceOptions WeekOptionsWinsorizeOptionsZeroFillOptions call_functionfunction_registry get_functionlist_functionscall_tabular_functionregister_scalar_functionregister_tabular_functionregister_aggregate_functionregister_vector_function UdfContext Expression) namedtupleN)dedent)_compute_docstrings) docscrapec|jjSN)_doc arg_names)funcs =C:\PYTHON\_runtimes\venv\Lib\site-packages\pyarrow/compute.py_get_arg_namesr]ss 9 _OptionsClassDoc)paramscp|jsdStj|j}t|dS)N Parameters)__doc__rVNumpyDocStringr_) options_classdocs r\_scrape_options_class_docrgzs8  t  "=#8 9 9C C - . ..r^c |j}t|j|j|j|j|_||_||_g}|j }|s|jdkrdnd}d|jd|}| |d|j }|r| |dtj |j} | td t!|} | D]@} |jd vrd } nd } | | d | d| dA|t%|} | rS| jD]J}| |jd |jd|jD]}| d|dKnt-jd|jdt0t3j|}|jD]=}| td|jd|jd|jd>| td|jd| td| ;t| d}| d|dd||_|S)N)namearityreoptions_required argumentsargumentzCall compute function z with the given z. z z. Parameters ---------- )vectorscalar_aggregatez Array-likezArray-like or scalar-likez :  z" Argument to compute function. z zOptions class z does not have a docstringz z. : optional Parameter for z7 constructor. Either `options` or `z@` 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. ) rYdictrirjrerk__arrow_compute_function____name__ __qualname__summaryappend descriptionrUfunction_doc_additionsgetrTr]kindrgr`typedescwarningswarnRuntimeWarninginspect signature parametersvaluesstripjoinrc)wrapper exposed_namer[recpp_doc doc_piecesrwarg_strry doc_additionrZarg_namearg_typeoptions_class_docps options_sigstrippeds r\_decorate_compute_functionrsiG)- Yj+ 1 *3*3*3G& $G'GJoG R!%a++ZQ49QQQQ'''(((%K0[...///&=AA$)LLLf    t$$IAA 96 6 6#HH2HX66(666777?@@@@ 5mDD  &- 4 4!!QV":":":":":;;;44A%%lQlll33334 4 M7=+A7778F H H H!+M::K +2244  !!&***#0#9*****## &"'4'="""    f    ,''--d33+x+++,,,ggj))GO Nr^c|jj}|sdS t|S#t$r"t jd|dt YdSwxYw)NzPython binding for z not exposed)rYreglobalsKeyErrorrrr)r[ class_names r\_get_options_classrst(J tyy$$  DJDDD$ & & &tts&(AAc |s|r|td|d||i|S|Tt|tr|di|St||r|Std|d|dt|dS)Nz Function z@ called with both an 'options' argument and additional argumentsz expected a z parameter, got ) TypeError isinstancersr})rireoptionsargskwargss r\_handle_optionsrs .v.  ,D,,,-- -}d-f--- gt $ $  =++7++ +  / / N # # #M # #== # #$$ $ 4r^c@ ddfd }n dddfd }|S)N memory_poolc 2tur8t|kr%tddt|d|r=t|dtr"t jt |S|d|S)N takes  positional argument(s), but were givenr)EllipsislenrrrR_calllistcall)rrrjr[ func_names r\rz&_make_generic_wrapper..wrappersH$$Te);); 2222t99222 ? 47J77 ?!' 4::>>>99T455 5r^)rrc turMt|kr%tddt|d|d}|d}nd}t|||}|r>t |dt r#t jt||S|||S)Nrrrrr) rrrrrrRrrr) rrrr option_argsrjr[rres r\rz&_make_generic_wrapper..wrappersH$$t99u$$#$66U66"4yy666#566l FUF| %i&16;;G H 47J77 H!' 4::wGGG99T7K88 8r^r)rr[rerjrs```` r\_make_generic_wrapperrs'+ 6 6 6 6 6 6 6 6 6 6(,T 9 9 9 9 9 9 9 9 9 9 Nr^clddlm}g}|D]&}||||j'|D]&}||||j'|tj|}|jD]K}|j|j |j fvsJ|r| |j }||L||d|j d||d|j dtj |S)Nr) Parameter)r|r)defaultr) rrrxPOSITIONAL_ONLYVAR_POSITIONALrrrr|POSITIONAL_OR_KEYWORD KEYWORD_ONLYreplace Signature)rZ var_arg_namesrerr`rirrs r\_make_signaturers!!!!!! FBB iii&?@@AAAAAA iii&>??@@@@ ' 66 '..00  A6i='466666 ;II9#9I:: MM!     ii 9+A(,... / / / MM))M9+A$(***+++  V $ $$r^cRt|}t|}|o|dd}|r)|dg}ng}t ||||j}t||||_t||||S)N*)rj) rr] startswithpoplstriprrjr __signature__r)rir[rerZ has_varargrrs r\_wrap_functionr*s&t,,Mt$$I>> 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]') [ 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'Fcast) ValueErrorpatypeslib ensure_typerunsafesaferH)arr target_typerrrsafe_vars_passeds r\rr\slD(Fk.E;W0:;; ;hl..{;; 5==!(55GG!&{33G # = ==r^rcv|2|||||z }n.||}n||d|}t|tjstj||j}n=|j|jkr-tj||j}t|}td|g||}|T|dkr>> import pyarrow as pa >>> import pyarrow.compute as pc >>> arr = pa.array(["Lorem", "ipsum", "dolor", "sit", "Lorem", "ipsum"]) >>> pc.index(arr, "ipsum") >>> pc.index(arr, "ipsum", start=2) >>> pc.index(arr, "amet") Nrr}valueindex) slicerrScalarscalarr}as_pyrrHint64)datarstartendrrresults r\rrs>  ?::eS5[11DD::e$$DD zz!S!! eRY ' '9 %di000 ej  %++--di888'''G 7TFG[ A AF V\\^^q006<<>>E1 CCC Mr^T) boundscheckrcJt|}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. 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) [ "a", null, "e", null ] )rtake)r@rH)rindicesrrrs r\rrs-Pk222G $'; G GGr^c:t|tjtjtjfstj||j}n=|j|jkr-tj||j}td||gS)aeReplace 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) [ 1, 2, 5, 3 ] >>> arr = pa.array([1, 2, None, 4, None]) >>> arr.fill_null(pa.array([10, 20, 30, 40, 50])) [ 1, 2, 30, 4, 50 ] rcoalesce) rrArray ChunkedArrayrrr}rrH)r fill_values r\ fill_nullrsf j28R_bi"H I IEYz <<<   ' 'Yz//11 DDD fj%9 : ::r^c|g}t|tjtjfr|dnt d|}t ||}td|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) [ 5, 4, 2 ] N)dummy descendingc |dfS)Nrrkey_names r\z top_k_unstable..ds (L)Ar^select_k_unstablerrrrrxmapr6rHrk sort_keysrrs r\top_k_unstabler:s}J &28R_566N01111AA9MM Q **G ,vh M MMr^c|g}t|tjtjfr|dnt d|}t ||}td|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) [ 0, 1, 2 ] N)r ascendingc |dfS)Nrrrs r\rz#bottom_k_unstable..s (K)@r^rrrs r\bottom_k_unstableris}J &28R_566M/0000@@)LL Q **G ,vh M MMr^system) initializerrrcJt|}tdg|||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+rH)nr rrs r\r r s-, 444G 2w A F F FFr^ct|}|dkrt|dttfrt j|dSt|dt rt j|dStdt|dt j|S)aReference 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") >>> pc.field(1) >>> pc.field(("a", "b")) >> pc.field("a", "b") r?r@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrR collectionsrSrtextwraprTrpyarrowrrUpyarrow.vendoredrVr]r_rgrrrrrrrr utf8_zfillrrrrrrrr rrrr^r\rs$UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUn#"""""''''''&&&&&&:0+>>///PPPf   (>%%%. J J J ;;;:%gii(899 ^B>B>B>B>J/D/////d(,)H)H)H)H)HX8;8;8;v,NT,N,N,N,N,N^,N,N,N,N,N,N^&tGGGGG4.7.7.7b%%%%%r^