a
    Of                     @  sP   d dl mZ d dlmZ d dlZd dlmZ ddddddZG d	d
 d
Z	dS )    )annotations)TYPE_CHECKINGN)import_optional_dependencyboolnopythonnogilparallelc              
     sJ   t rddl ntd  j| ||dddddddddd	 fd
d}|S )ak  
    Generate a numba jitted groupby ewma function specified by values
    from engine_kwargs.

    Parameters
    ----------
    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numbar   z
np.ndarrayintfloatr   )valuesdeltasminimum_periodsold_wt_factornew_wtold_wtadjust	ignore_nac              	     sj  t | j}| d  }	t |	 t j}
t |
|k|	t j|d< t	dt
| D ]}| | }t | }|
|t j7 }
 t
|D ]}t |	| s2|| s|sF||  |||d   9  < || rF|	| || kr|| |	|  |||   || |  |	|< |r(||  |7  < nd||< q|| r|| |	|< qt |
|k|	t j||< qR||fS )z
        Compute online exponentially weighted mean per column over 2D values.

        Takes the first observation as is, then computes the subsequent
        exponentially weighted mean accounting minimum periods.
        r            ?)npemptyshapecopyisnanZastypeZint64wherenanrangelenZprange)r   r   r   r   r   r   r   r   resultweighted_avgZnobsicurZis_observationsjr
    R/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/core/window/online.pyonline_ewma%   s0    


z4generate_online_numba_ewma_func.<locals>.online_ewma)r   r
   r   Zjit)r   r   r	   r(   r&   r%   r'   generate_online_numba_ewma_func
   s    
"0r)   c                   @  s0   e Zd ZddddZdd ZddddZd	S )
EWMMeanStateNone)returnc                 C  s^   dd|  }|| _ || _|| _|| _|r,dn|| _d| | _t| j| j d  | _d | _	d S )Nr   r   )
axisr   r   r   r   r   r   onesr   last_ewm)selfcomr   r   r-   r   alphar&   r&   r'   __init__Z   s    
zEWMMeanState.__init__c              	   C  s8   ||||| j | j| j| j| j\}}|| _|d | _|S )N)r   r   r   r   r   r/   )r0   r!   r   Zmin_periodsZewm_funcr    r   r&   r&   r'   run_ewme   s    

zEWMMeanState.run_ewmc                 C  s"   t | j| jd  | _d | _d S )Nr   )r   r.   r   r-   r   r/   )r0   r&   r&   r'   resett   s    zEWMMeanState.resetN)__name__
__module____qualname__r3   r5   r6   r&   r&   r&   r'   r*   Y   s   r*   )

__future__r   typingr   numpyr   Zpandas.compat._optionalr   r)   r*   r&   r&   r&   r'   <module>   s
   O