
    q-Ph                    t   d dl mZ d dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ erJd dlmZ d d	lmZ d d
lmZ ej        dk    rd dlmZ nd dlmZ  e
d          Z ed          Ze	def         Zd-dZ d.dZ!d/dZ"d0dZ#d1dZ$ G d  d!          Z% e%            Z&d2d)Z'd3d,Z(dS )4    )annotationsN)wraps)TYPE_CHECKINGAnyCallableTypeVar)	functions)wrap_s)dtype_to_ffiname)Series)PolarsDataType)PySeries)   
   )	ParamSpecTP.clstype[T]returnc                   t          | dd          }t          |          }t          |           D ]}|                    d          s|dk    rt          | |          }t	          |          rat          |          }|j        j        d|j        j                 }|||f|v r-t          |          rt          | |t          |                     | S )a  
    Series/NameSpace class decorator that sets up expression dispatch.

    * Applied to the Series class, and/or any Series 'NameSpace' classes.
    * Walks the class attributes, looking for methods that have empty function
      bodies, with signatures compatible with an existing Expr function.
    * IFF both conditions are met, the empty method is decorated with @call_expr.
    	_accessorN_plot)getattr_expr_lookupdir
startswithcallable_undecorated__code__co_varnamesco_argcount_is_empty_methodsetattr	call_expr)r   	namespaceexpr_lookupnameattrargss         S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/series/utils.pyexpr_dispatchr-      s     [$//Iy))KC 8 8 $$	8 3%%D~~ 8#D)) }01L4=3L1LM tT*k99>Nt>T>T9Cy777J    r'   
str | None,set[tuple[str | None, str, tuple[str, ...]]]c                   t          j                    }d|_        | t          ||           }t	                      }t          |          D ]}|                    d          sv	 t          ||          }n# t          $ r Y 5w xY wt          |          rEt          |          }|j
        j        d|j
        j                 }|                    | ||f           |S )zACreate lookup of potential Expr methods (in the given namespace).Nr   )plExpr_pyexprr   setr   r   AttributeErrorr   r    r!   r"   r#   add)r'   exprlookupr)   mr+   s         r,   r   r   ?   s     799DDL tY''UUFD		 4 4s## 
	4D$''!   {{ 4 !OOz-.F
0F.FG

ItT2333Ms   "A33
B ?B functionCallable[P, T]c                T    t          | d          r| j        } t          | d          | S )z1Return the given function without any decorators.__wrapped__)hasattrr>   )r;   s    r,   r    r    Y   s5    
(M
*
* (' (M
*
* (Or.   funcSeriesMethodc                     t                     d fd	            }t          |d
t          j                              |S )z7Dispatch Series method to an expression implementation.selfr   r+   P.argskwargsP.kwargsr   r   c                L   t          | j                  }t          j        |j                  }t          | dd           x}t          ||          }t          |j                  }|                                                     ||i |          	                                S )Nr   )
r
   _sFcolr)   r   __name__to_frame
select_seq	to_series)rC   r+   rE   sr8   r'   fr@   s          r,   wrapperzcall_expr.<locals>.wrapperc   s    47OOuQV}} {D999IF4++DD$-((zz||&&qq$'9&'9'9::DDFFFr.   __signature__)rC   r   r+   rD   rE   rF   r   r   )r   r%   inspect	signature)r@   rQ   s   ` r,   r&   r&   `   s]     4[[G G G G G [G G_g&7&=&=>>>Nr.   boolc                    | j         }|j        t          v oFt          |j                  dk    r|j        d         du pt
          j        j        dk    o
|j        dk    S )z
    Confirm that the given function has no implementation.

    Definitions of empty:

    - only has a docstring (body is empty)
    - has no docstring and just contains 'pass' (or equivalent)
          NN)r!   co_code_EMPTY_BYTECODElen	co_constssysflagsoptimize)r@   fcs     r,   r$   r$   r   s`     
BJ/) 	R\		a		;BLOt$; 	AI!#?(?r.   c                      e Zd Zd	dZd
dZdS )_EmptyBytecodeHelperr   Nonec                P    dd}dd}|j         j        |j         j        f| _        d S )Nr   rd   c                     dS ) N rh   r.   r,   _empty_with_docstringz<_EmptyBytecodeHelper.__init__.<locals>._empty_with_docstring   s      r.   c                     d S rY   rh   rh   r.   r,   _empty_without_docstringz?_EmptyBytecodeHelper.__init__.<locals>._empty_without_docstring   s    Dr.   r   rd   )r!   rZ   empty_bytecode)rC   ri   rk   s      r,   __init__z_EmptyBytecodeHelper.__init__   sN    	 	 	 		 	 	 	 "*2$-5
r.   itembytesrU   c                    || j         v S rY   )rm   )rC   ro   s     r,   __contains__z!_EmptyBytecodeHelper.__contains__   s    t***r.   Nrl   )ro   rp   r   rU   )rK   
__module____qualname__rn   rr   rh   r.   r,   rc   rc      s<        
 
 
 
+ + + + + +r.   rc   r)   strdtyper   objr   Callable[..., Any] | Nonec                n    t          |          }|                     d|          }t          ||d          S )az  
    Dynamically obtain the proper FFI function/ method.

    Parameters
    ----------
    name
        function or method name where dtype is replaced by <>
        for example
            "call_foo_<>"
    dtype
        polars dtype.
    obj
        Object to find the method for.

    Returns
    -------
    callable or None
        FFI function, or None if not found.
    z<>N)r   replacer   )r)   rv   rw   ffi_namefnames        r,   get_ffi_funcr}      s6    ,  &&HLLx((E3t$$$r.   Callable[..., Any]r   c                    ddl m} 	  |d            |             } |d           |S # t          $ r  |d            w xY w)Nr   )check_lengthFT)polars.polarsr   	Exception)r@   r   results      r,   _with_no_check_lengthr      s{    ******UT
 	    Ts	    * A)r   r   r   r   )r'   r/   r   r0   )r;   r<   r   r<   )r@   rA   r   rA   )r@   rA   r   rU   )r)   ru   rv   r   rw   r   r   rx   )r@   r~   r   r   ))
__future__r   rS   r^   	functoolsr   typingr   r   r   r   polars._reexport	_reexportr2   polarsr	   rI   polars._utils.wrapr
   polars.datatypesr   r   polars._typingr   r   r   version_infor   typing_extensionsr   r   rA   r-   r   r    r&   r$   rc   r[   r}   r   rh   r.   r,   <module>r      s   " " " " " "  



       8 8 8 8 8 8 8 8 8 8 8 8       ! ! ! ! ! ! % % % % % % - - - - - - )------&&&&&&
7""$$$$$$$//////A	#ACK(L       F   4      $   "+ + + + + + + +$ '&((% % % %6     r.   