
    q-Ph              	      X   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZ  ej        e          5  d dlmZ ddd           n# 1 swxY w Y   e	rd dlmZ d d	lmZ d d
lmZ dgZdddddddddd+d Zd,d"Z ed#$          dd%d-d(            Zd.d)Zdd%d/d*ZdS )0    )annotationsN)	lru_cache)Path)TYPE_CHECKINGAny)parse_into_list_of_expressions)	wrap_expr)Iterable)Expr)IntoExprregister_plugin_functionF)kwargsis_elementwisechanges_lengthreturns_scalarcast_to_supertypeinput_wildcard_expansionpass_name_to_applyuse_abs_pathplugin_path
Path | strfunction_namestrargsIntoExpr | Iterable[IntoExpr]r   dict[str, Any] | Noner   boolr   r   r   r   r   r   returnr   c                    t          |          }t          |          }t          | |
          } t          t	          j        t          |           ||||||||	|
  
                  S )a  
    Register a plugin function.

    See the `user guide <https://docs.pola.rs/user-guide/plugins/expr_plugins>`_
    for more information about plugins.

    Parameters
    ----------
    plugin_path
        Path to the plugin package. Accepts either the file path to the dynamic library
        file or the path to the directory containing it.
    function_name
        The name of the Rust function to register.
    args
        The arguments passed to this function. These get passed to the `input`
        argument on the Rust side, and have to be expressions (or be convertible
        to expressions).
    kwargs
        Non-expression arguments to the plugin function. These must be
        JSON serializable.
    is_elementwise
        Indicate that the function operates on scalars only. This will potentially
        trigger fast paths.
    changes_length
        Indicate that the function will change the length of the expression.
        For example, a `unique` or `slice` operation.
    returns_scalar
        Automatically explode on unit length if the function ran as final aggregation.
        This is the case for aggregations like `sum`, `min`, `covariance` etc.
    cast_to_supertype
        Cast the input expressions to their supertype.
    input_wildcard_expansion
        Expand wildcard expressions before executing the function.
    pass_name_to_apply
        If set to `True`, the `Series` passed to the function in a group-by operation
        will ensure the name is set. This is an extra heap allocation per group.
    use_abs_path
        If set to `True`, the path will be resolved to an absolute path.
        The path to the dynamic library is relative to the virtual environment by
        default.

    Returns
    -------
    Expr

    Warnings
    --------
    This is highly unsafe as this will call the C function loaded by
    `plugin::function_name`.

    The parameters you set dictate how Polars will handle the function.
    Make sure they are correct!
    r   )
r   r   r   r   r   r   r   r   r   r   )r   _serialize_kwargs_resolve_plugin_pathr	   plrr   r   )r   r   r   r   r   r   r   r   r   r   r   pyexprsserialized_kwargss                N/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/plugins.pyr   r      s    F -T22G)&11&{NNNK$K(('$)%=)/1)	
 	
 	
      bytesc                @    | sdS ddl }|                    | d          S )z+Serialize the function's keyword arguments.r'   r   N   )protocol)pickledumps)r   r,   s     r&   r!   r!   o   s0     sMMM <<<+++r'      )maxsizer    pathr   c               .   t          | t                    st          |           } |                                 rt          | |          S |                                 D ]$}t          |          rt          ||          c S %d|  }t          |          )z.Get the file path of the dynamic library file.r    z"no dynamic library found at path: )
isinstancer   is_file_resolve_file_pathiterdir_is_dynamic_libFileNotFoundError)r0   r   pmsgs       r&   r"   r"   {   s     dD!! Dzz||~~ C!$\BBBB\\^^ D D1 	D%alCCCCCC	D 6t
5
5C
C
 
  r'   c                <    |                                  o| j        dv S )N)z.soz.dllz.pyd)r3   suffix)r0   s    r&   r6   r6      s    <<>>Ddk-DDDr'   c                   t          t          j                  }|r|                                 S 	 |                     |          }n$# t
          $ r |                                 }Y nw xY w|S )N)r   sysprefixresolverelative_to
ValueError)r0   r   	venv_path	file_paths       r&   r4   r4      su    SZ  I '||~~	'((33II 	' 	' 	'III	' s   A A('A()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   r   r   r   r   r   )r0   r   r   r   )r0   r   r   r   r   r   )
__future__r   
contextlibr=   	functoolsr   pathlibr   typingr   r   polars._utils.parser   polars._utils.wrapr	   suppressImportErrorpolars.polarspolarsr#   collections.abcr
   r   polars._typingr   __all__r   r!   r"   r6   r4    r'   r&   <module>rS      s"   " " " " " "     



             % % % % % % % % > > > > > > ( ( ( ( ( (Z%%                                   (((((((''''''%
& %)   #%*$T T T T T Tn	, 	, 	, 	, 2CH ! ! ! ! ! ! E E E E <A        s   AAA