
    &Ph                        d Z ddlmZ ddlZddlZddlmZmZmZ ddl	Z
ddlmZ ddlmZmZ erddlmZ ddZej&                  	 	 	 	 	 	 	 	 	 	 dd	       Zej&                  	 	 	 	 	 	 	 	 	 	 dd
       Zy)z6Common utilities for Numba operations with groupby ops    )annotationsN)TYPE_CHECKINGAnyCallable)import_optional_dependency)NumbaUtilErrorjit_user_function)Scalarc                "   t        |       st        d      t        t        j                  |       j
                  j                               }ddg}t        |      }t        |      |k  s|d| |k7  rt        d| d| j                   d|       y)a^  
    Validate user defined function for ops when using Numba with groupby ops.

    The first signature arguments should include:

    def f(values, index, ...):
        ...

    Parameters
    ----------
    func : function, default False
        user defined function

    Returns
    -------
    None

    Raises
    ------
    NumbaUtilError
    z5Numba engine can only be used with a single function.valuesindexNz
The first z arguments to z	 must be )
callableNotImplementedErrorlistinspect	signature
parameterskeyslenr   __name__)funcudf_signatureexpected_argsmin_number_argss       eC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\pandas/core/groupby/numba_.pyvalidate_udfr      s    , D>!C
 	
 **40;;@@BCMw'M-(OM_,)/*m;)io
 	
 <    c                    t        |       t        rddlnt        d      j	                  |||      	 	 	 	 	 	 	 	 	 	 	 	 	 	 dfd       }|S )a  
    Generate a numba jitted agg function specified by values from engine_kwargs.

    1. jit the user's function
    2. Return a groupby agg function with the jitted function inline

    Configurations specified in engine_kwargs apply to both the user's
    function _AND_ the groupby evaluation loop.

    Parameters
    ----------
    func : function
        function to be applied to each group and will be JITed
    nopython : bool
        nopython to be passed into numba.jit
    nogil : bool
        nogil to be passed into numba.jit
    parallel : bool
        parallel to be passed into numba.jit

    Returns
    -------
    Numba function
    r   Nnumbanopythonnogilparallelc                (   t        |      t        |      k(  sJ t        |      }t        j                  ||f      }j                  |      D ]A  }|||   ||    }	j                  |      D ]   }
| ||   ||   |
f   } ||	g| |||
f<   " C |S Nr   npemptypranger   r   beginendnum_columnsargs
num_groupsresultigroup_indexjgroupr   
numba_funcs               r   	group_aggz*generate_numba_agg_func.<locals>.group_agge   s     5zSX%%%Z
:{34j)Aa3q62K\\+.uQx#a&0!34)%DtDq!t / *
 r   r   
np.ndarrayr   r8   r+   r8   r,   r8   r-   intr.   r   returnr8   r	   r   r   r   jit)r   r!   r"   r#   r6   r   r5   s        @@r   generate_numba_agg_funcr=   @   s    > #4(J*73
YYYA  	
   
 B& r   c                    t        |       t        rddlnt        d      j	                  |||      	 	 	 	 	 	 	 	 	 	 	 	 	 	 dfd       }|S )a  
    Generate a numba jitted transform function specified by values from engine_kwargs.

    1. jit the user's function
    2. Return a groupby transform function with the jitted function inline

    Configurations specified in engine_kwargs apply to both the user's
    function _AND_ the groupby evaluation loop.

    Parameters
    ----------
    func : function
        function to be applied to each window and will be JITed
    nopython : bool
        nopython to be passed into numba.jit
    nogil : bool
        nogil to be passed into numba.jit
    parallel : bool
        parallel to be passed into numba.jit

    Returns
    -------
    Numba function
    r   Nr   r    c                J   t        |      t        |      k(  sJ t        |      }t        j                  t        |       |f      }j                  |      D ]I  }|||   ||    }	j                  |      D ](  }
| ||   ||   |
f   } ||	g| |||   ||   |
f<   * K |S r%   r&   r*   s               r   group_transformz6generate_numba_transform_func.<locals>.group_transform   s     5zSX%%%Z
3v;45j)Aa3q62K\\+.uQx#a&0!34/9%/Tt/TuQx#a&(!+, / *
 r   r7   r;   )r   r!   r"   r#   r@   r   r5   s        @@r   generate_numba_transform_funcrA   |   s    > #4(J*73
YYYA  	
   
 B& r   )r   r   r:   None)
r   zCallable[..., Scalar]r!   boolr"   rC   r#   rC   r:   PCallable[[np.ndarray, np.ndarray, np.ndarray, np.ndarray, int, Any], np.ndarray])
r   zCallable[..., np.ndarray]r!   rC   r"   rC   r#   rC   r:   rD   )__doc__
__future__r   	functoolsr   typingr   r   r   numpyr'   pandas.compat._optionalr   pandas.core.util.numba_r   r	   pandas._typingr
   r   cacher=   rA    r   r   <module>rO      s    < "     >
 %$
N 8
88 8 	8
 V8 8v 8
#88 8 	8
 V8 8r   