
    ˀh                    l   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rEd dlmZ d d	lmZ d d
lmZ ej4                  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"ddZ#ddZ$ G d d      Z% e%       Z&	 	 	 	 	 	 	 	 ddZ'ddZ(y)     )annotationsN)wraps)TYPE_CHECKINGAnyCallableTypeVar)	functions)wrap_s)dtype_to_ffiname)Series)PolarsDataType)PySeries)   
   )	ParamSpecTP.c                z   t        | dd      }t        |      }t        |       D ]  }|j                  d      r|dk7  st        | |      }t	        |      s3t        |      }|j                  j                  d|j                  j                   }|||f|v sst        |      s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)cls	namespaceexpr_lookupnameattrargss         o/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/polars/series/utils.pyexpr_dispatchr+      s     [$/Iy)KC 8 $ 3%D~#D) }}001L4==3L3LM tT*k9>Nt>TCy7%8& J    c                   t        j                         }d|_        | t        ||       }t	               }t        |      D ]y  }|j                  d      r	 t        ||      }t        |      s.t        |      }|j                  j                  d|j                  j                   }|j                  | ||f       { |S # t        $ r Y w xY w)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     779DDL tY'UFD	 4s#D$' { !Ozz--.F

0F0FG

ItT234 M " s   B==	C	C	c                P    t        | d      r| j                  } t        | d      r| S )z1Return the given function without any decorators.__wrapped__)hasattrr8   )functions    r*   r   r   Y   s(    
(M
*'' (M
*Or,   c                p     t               d fd       }t        |dt        j                                |S )z7Dispatch Series method to an expression implementation.c                4   t        | j                        }t        j                  |j                        }t        | dd       x}t        ||      }t        |j                        }|j                         j                   ||i |      j                         S )Nr   )
r
   _sFcolr'   r   __name__to_frame
select_seq	to_series)selfr)   kwargssr4   r%   ffuncs          r*   wrapperzcall_expr.<locals>.wrapperc   s{    477OuuQVV} {D99IF4+DD$--(zz|&&q$'9&'9:DDFFr,   __signature__)rD   r   r)   zP.argsrE   zP.kwargsreturnr   )r   r"   inspect	signature)rH   rI   s   ` r*   r#   r#   `   s;     4[G G G_g&7&7&=>Nr,   c                    | j                   }|j                  t        v xr[ t        |j                        dk(  xr |j                  d   du xs. t
        j                  j                  dk(  xr |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)rH   fcs     r*   r!   r!   r   sl     
BJJ/) 	R\\	a		;BLLOt$; 	AII!#?(?r,   c                      e Zd ZddZddZy)_EmptyBytecodeHelperc                v    dd}dd}|j                   j                  |j                   j                  f| _        y )Nc                      y) N r_   r,   r*   _empty_with_docstringz<_EmptyBytecodeHelper.__init__.<locals>._empty_with_docstring   s    r,   c                      y rQ   r_   r_   r,   r*   _empty_without_docstringz?_EmptyBytecodeHelper.__init__.<locals>._empty_without_docstring   s    r,   rK   None)r   rR   empty_bytecode)rD   r`   rb   s      r*   __init__z_EmptyBytecodeHelper.__init__   s6    		 "**22$--55
r,   c                    || j                   v S rQ   )re   )rD   items     r*   __contains__z!_EmptyBytecodeHelper.__contains__   s    t****r,   Nrc   )rh   bytesrK   bool)r@   
__module____qualname__rf   ri   r_   r,   r*   r[   r[      s    
+r,   r[   c                V    t        |      }| j                  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'   dtypeobjffi_namefnames        r*   get_ffi_funcrt      s-    ,  &HLLx(E3t$$r,   c                n    ddl m} 	  |d        |        } |d       |S # t        $ r
  |d        w xY w)Nr   )check_lengthFT)polars.polarsrv   	Exception)rH   rv   results      r*   _with_no_check_lengthrz      sD    *UT
 	  Ts   ! 4)r$   type[T]rK   r{   )r%   z
str | NonerK   z,set[tuple[str | None, str, tuple[str, ...]]])r:   Callable[P, T]rK   r|   )rH   SeriesMethodrK   r}   )rH   r}   rK   rk   )r'   strrp   r   rq   r   rK   zCallable[..., Any] | None)rH   zCallable[..., Any]rK   r   ))
__future__r   rL   rV   	functoolsr   typingr   r   r   r   polars._reexport	_reexportr.   polarsr	   r>   polars._utils.wrapr
   polars.datatypesr   r   polars._typingr   rw   r   version_infor   typing_extensionsr   r   r}   r+   r   r   r#   r!   r[   rS   rt   rz   r_   r,   r*   <module>r      s    "  
  8 8  ! % --&
7"$/A#ACK(L F4$"+ +$ '(%
%$%+3%%6r,   