o
    ҷhڇ                     @  s  d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	Z
d dlmZ d dlm  m  mZ d dlmZ d dlmZmZ d d	lmZ d d
lmZ d dlmZmZmZ d dlm Z m!Z! d dl"m#Z# d dl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, d dl-m.Z.m/Z/ d dl0m1Z1m2Z2 d dl3m4Z4m5Z5 erd dl6m7Z7m8Z8 d dl9m:Z:m;Z; d dl<m=Z= d*ddZ>d+d"d#Z?G d$d% d%e4Z@G d&d' d'e5e@ZAG d(d) d)e@ZBdS ),    )annotationsN)partial)dedent)TYPE_CHECKING)	Timedelta)doc)is_datetime64_ns_dtypeis_numeric_dtype)isna)common)BaseIndexerExponentialMovingWindowIndexerGroupbyIndexer)get_jit_argumentsmaybe_use_numba)zsqrt)_shared_docscreate_section_headerkwargs_numeric_onlynumba_notestemplate_headertemplate_returnstemplate_see_alsowindow_agg_numba_parameters)generate_numba_ewm_funcgenerate_numba_ewm_table_func)EWMMeanStategenerate_online_numba_ewma_func)
BaseWindowBaseWindowGroupby)AxisTimedeltaConvertibleTypes)	DataFrameSeries)NDFramecomassfloat | Nonespanhalflifealphareturnfloatc                 C  s   t | |||}|dkrtd| d ur | dk rtdt| S |d ur6|dk r,td|d d } t| S |d urX|dkrBtddttd|  }d| d } t| S |d urr|dksd|dkrhtd	d| | } t| S td
)N   z8comass, span, halflife, and alpha are mutually exclusiver   z comass must satisfy: comass >= 0zspan must satisfy: span >= 1   z#halflife must satisfy: halflife > 0g      ?z"alpha must satisfy: 0 < alpha <= 1z1Must pass one of comass, span, halflife, or alpha)r   count_not_none
ValueErrornpexplogr+   )r%   r'   r(   r)   valid_countdecay r5   I/var/www/html/venv/lib/python3.10/site-packages/pandas/core/window/ewm.pyget_center_of_massC   s0   r7   timesnp.ndarray | NDFrame(float | TimedeltaConvertibleTypes | None
np.ndarrayc                 C  s:   t j| t jt jd}tt|dj}t 	|| S )a  
    Return the diff of the times divided by the half-life. These values are used in
    the calculation of the ewm mean.

    Parameters
    ----------
    times : np.ndarray, Series
        Times corresponding to the observations. Must be monotonically increasing
        and ``datetime64[ns]`` dtype.
    halflife : float, str, timedelta, optional
        Half-life specifying the decay

    Returns
    -------
    np.ndarray
        Diff of the times divided by the half-life
    dtypens)
r0   asarrayviewint64float64r+   r   as_unit_valuediff)r8   r(   _times	_halflifer5   r5   r6   _calculate_deltasd   s   rH   c                      s`  e Zd ZdZg dZ										dedddf fddZdgd%d&Zdhd(d)Z	didjd-d.Ze	e
d/ ed0ed1d2d3d4 fd5d6ZeZe	eed7ee ed8eed9eed:eed;ed<d=d>d?d@			dkdldBdCZe	eed7ee ed8eed9eed:eed;edDd=dEdFd@			dkdldGdHZe	eed7edIeed8eed9eed;edJd=dKdLd@dmdndNdOZe	eed7edIeed8eed9eed;edPd=dQdRd@dmdndSdTZe	eed7edUeed8eed9eed;edVd=dWdXd@				dodpd]d^Ze	eed7ed_eed8eed9eed;ed`d=dadbd@			dqdrdcddZ  ZS )sExponentialMovingWindowa  
    Provide exponentially weighted (EW) calculations.

    Exactly one of ``com``, ``span``, ``halflife``, or ``alpha`` must be
    provided if ``times`` is not provided. If ``times`` is provided,
    ``halflife`` and one of ``com``, ``span`` or ``alpha`` may be provided.

    Parameters
    ----------
    com : float, optional
        Specify decay in terms of center of mass

        :math:`\alpha = 1 / (1 + com)`, for :math:`com \geq 0`.

    span : float, optional
        Specify decay in terms of span

        :math:`\alpha = 2 / (span + 1)`, for :math:`span \geq 1`.

    halflife : float, str, timedelta, optional
        Specify decay in terms of half-life

        :math:`\alpha = 1 - \exp\left(-\ln(2) / halflife\right)`, for
        :math:`halflife > 0`.

        If ``times`` is specified, a timedelta convertible unit over which an
        observation decays to half its value. Only applicable to ``mean()``,
        and halflife value will not apply to the other functions.

    alpha : float, optional
        Specify smoothing factor :math:`\alpha` directly

        :math:`0 < \alpha \leq 1`.

    min_periods : int, default 0
        Minimum number of observations in window required to have a value;
        otherwise, result is ``np.nan``.

    adjust : bool, default True
        Divide by decaying adjustment factor in beginning periods to account
        for imbalance in relative weightings (viewing EWMA as a moving average).

        - When ``adjust=True`` (default), the EW function is calculated using weights
          :math:`w_i = (1 - \alpha)^i`. For example, the EW moving average of the series
          [:math:`x_0, x_1, ..., x_t`] would be:

        .. math::
            y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... + (1 -
            \alpha)^t x_0}{1 + (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t}

        - When ``adjust=False``, the exponentially weighted function is calculated
          recursively:

        .. math::
            \begin{split}
                y_0 &= x_0\\
                y_t &= (1 - \alpha) y_{t-1} + \alpha x_t,
            \end{split}
    ignore_na : bool, default False
        Ignore missing values when calculating weights.

        - When ``ignore_na=False`` (default), weights are based on absolute positions.
          For example, the weights of :math:`x_0` and :math:`x_2` used in calculating
          the final weighted average of [:math:`x_0`, None, :math:`x_2`] are
          :math:`(1-\alpha)^2` and :math:`1` if ``adjust=True``, and
          :math:`(1-\alpha)^2` and :math:`\alpha` if ``adjust=False``.

        - When ``ignore_na=True``, weights are based
          on relative positions. For example, the weights of :math:`x_0` and :math:`x_2`
          used in calculating the final weighted average of
          [:math:`x_0`, None, :math:`x_2`] are :math:`1-\alpha` and :math:`1` if
          ``adjust=True``, and :math:`1-\alpha` and :math:`\alpha` if ``adjust=False``.

    axis : {0, 1}, default 0
        If ``0`` or ``'index'``, calculate across the rows.

        If ``1`` or ``'columns'``, calculate across the columns.

        For `Series` this parameter is unused and defaults to 0.

    times : np.ndarray, Series, default None

        Only applicable to ``mean()``.

        Times corresponding to the observations. Must be monotonically increasing and
        ``datetime64[ns]`` dtype.

        If 1-D array like, a sequence with the same shape as the observations.

    method : str {'single', 'table'}, default 'single'
        .. versionadded:: 1.4.0

        Execute the rolling operation per single column or row (``'single'``)
        or over the entire object (``'table'``).

        This argument is only implemented when specifying ``engine='numba'``
        in the method call.

        Only applicable to ``mean()``

    Returns
    -------
    pandas.api.typing.ExponentialMovingWindow

    See Also
    --------
    rolling : Provides rolling window calculations.
    expanding : Provides expanding transformations.

    Notes
    -----
    See :ref:`Windowing Operations <window.exponentially_weighted>`
    for further usage details and examples.

    Examples
    --------
    >>> df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]})
    >>> df
         B
    0  0.0
    1  1.0
    2  2.0
    3  NaN
    4  4.0

    >>> df.ewm(com=0.5).mean()
              B
    0  0.000000
    1  0.750000
    2  1.615385
    3  1.615385
    4  3.670213
    >>> df.ewm(alpha=2 / 3).mean()
              B
    0  0.000000
    1  0.750000
    2  1.615385
    3  1.615385
    4  3.670213

    **adjust**

    >>> df.ewm(com=0.5, adjust=True).mean()
              B
    0  0.000000
    1  0.750000
    2  1.615385
    3  1.615385
    4  3.670213
    >>> df.ewm(com=0.5, adjust=False).mean()
              B
    0  0.000000
    1  0.666667
    2  1.555556
    3  1.555556
    4  3.650794

    **ignore_na**

    >>> df.ewm(com=0.5, ignore_na=True).mean()
              B
    0  0.000000
    1  0.750000
    2  1.615385
    3  1.615385
    4  3.225000
    >>> df.ewm(com=0.5, ignore_na=False).mean()
              B
    0  0.000000
    1  0.750000
    2  1.615385
    3  1.615385
    4  3.670213

    **times**

    Exponentially weighted mean with weights calculated with a timedelta ``halflife``
    relative to ``times``.

    >>> times = ['2020-01-01', '2020-01-03', '2020-01-10', '2020-01-15', '2020-01-17']
    >>> df.ewm(halflife='4 days', times=pd.DatetimeIndex(times)).mean()
              B
    0  0.000000
    1  0.585786
    2  1.523889
    3  1.523889
    4  3.233686
    )
comr'   r(   r)   min_periodsadjust	ignore_naaxisr8   methodNr   TFsingle	selectionobjr$   rJ   r&   r'   r(   r:   r)   rK   
int | NonerL   boolrM   rN   r    r8   np.ndarray | NDFrame | NonerO   strr*   Nonec             
     s  t  j||d u r
dntt|dd dd ||	|d || _|| _|| _|| _|| _|| _	|
| _
| j
d ur| js:tdt| j
sCtdt| j
t|krPtdt| jttjtjfs_tdt| j
 rjtdt| j
| j| _t| j| j| jd	krt| j| jd | j| _d S d
| _d S | jd urt| jttjtjfrtdtjt| jj| j  d d	tj!d| _t| j| j| j| j| _d S )Nr,   F)rS   rK   oncenterclosedrO   rN   rR   z)times is not supported with adjust=False.z#times must be datetime64[ns] dtype.z,times must be the same length as the object.z/halflife must be a timedelta convertible objectz$Cannot convert NaT values to integerr   g      ?zKhalflife can only be a timedelta convertible argument if times is not None.r<   )"super__init__maxintrJ   r'   r(   r)   rL   rM   r8   NotImplementedErrorr   r/   len
isinstancerW   datetime	timedeltar0   timedelta64r
   anyrH   _deltasr   r.   r7   _comonesrS   shaperN   rB   )selfrS   rJ   r'   r(   r)   rK   rL   rM   rN   r8   rO   rR   	__class__r5   r6   r]   J  s^   




z ExponentialMovingWindow.__init__startr;   endnum_valsr_   c                 C  s   d S Nr5   )rk   rn   ro   rp   r5   r5   r6   _check_window_bounds  s   z,ExponentialMovingWindow._check_window_boundsr   c                 C  s   t  S )z[
        Return an indexer class that will compute the window start and end bounds
        )r   rk   r5   r5   r6   _get_window_indexer  s   z+ExponentialMovingWindow._get_window_indexernumbaengineOnlineExponentialMovingWindowc                 C  s8   t | j| j| j| j| j| j| j| j| j	| j
||| jdS )a  
        Return an ``OnlineExponentialMovingWindow`` object to calculate
        exponentially moving window aggregations in an online method.

        .. versionadded:: 1.3.0

        Parameters
        ----------
        engine: str, default ``'numba'``
            Execution engine to calculate online aggregations.
            Applies to all supported aggregation methods.

        engine_kwargs : dict, default None
            Applies to all supported aggregation methods.

            * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
              and ``parallel`` dictionary keys. The values must either be ``True`` or
              ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
              ``{{'nopython': True, 'nogil': False, 'parallel': False}}`` and will be
              applied to the function

        Returns
        -------
        OnlineExponentialMovingWindow
        )rS   rJ   r'   r(   r)   rK   rL   rM   rN   r8   rv   engine_kwargsrR   )rw   rS   rJ   r'   r(   r)   rK   rL   rM   rN   r8   
_selection)rk   rv   rx   r5   r5   r6   online  s   zExponentialMovingWindow.online	aggregatezV
        See Also
        --------
        pandas.DataFrame.rolling.aggregate
        a  
        Examples
        --------
        >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
        >>> df
           A  B  C
        0  1  4  7
        1  2  5  8
        2  3  6  9

        >>> df.ewm(alpha=0.5).mean()
                  A         B         C
        0  1.000000  4.000000  7.000000
        1  1.666667  4.666667  7.666667
        2  2.428571  5.428571  8.428571
        zSeries/Dataframe )see_alsoexamplesklassrN   c                   s   t  j|g|R i |S rq   )r\   r{   rk   funcargskwargsrl   r5   r6   r{     s   z!ExponentialMovingWindow.aggregate
ParametersReturnszSee AlsoNotesExamplesz        >>> ser = pd.Series([1, 2, 3, 4])
        >>> ser.ewm(alpha=.2).mean()
        0    1.000000
        1    1.555556
        2    2.147541
        3    2.775068
        dtype: float64
        ewmz"(exponential weighted moment) meanmean)window_methodaggregation_description
agg_methodnumeric_onlyc              	   C  s   t |r,| jdkrt}nt}|d
i t|| j| j| jt| j	dd}| j
|ddS |dv rX|d ur8td| jd u r?d n| j	}ttj| j| j| j|dd}| j
|d|dS td	)NrP   TrJ   rL   rM   deltas	normalizer   namecythonN+cython engine does not accept engine_kwargsr   r   )engine must be either 'numba' or 'cython'r5   )r   rO   r   r   r   rh   rL   rM   tuplerg   _applyr/   r8   r   window_aggregationsr   rk   r   rv   rx   r   ewm_funcr   window_funcr5   r5   r6   r     s8   !

zExponentialMovingWindow.meanz        >>> ser = pd.Series([1, 2, 3, 4])
        >>> ser.ewm(alpha=.2).sum()
        0    1.000
        1    2.800
        2    5.240
        3    8.192
        dtype: float64
        z!(exponential weighted moment) sumsumc              	   C  s   | j stdt|r3| jdkrt}nt}|di t|| j| j | jt	| j
dd}| j|ddS |dv r_|d ur?td| jd u rFd n| j
}ttj| j| j | j|dd}| j|d|d	S td
)Nz(sum is not implemented with adjust=FalserP   Fr   r   r   r   r   r   r   r5   )rL   r`   r   rO   r   r   r   rh   rM   r   rg   r   r/   r8   r   r   r   r   r5   r5   r6   r   /  s<   !

zExponentialMovingWindow.sumzb        bias : bool, default False
            Use a standard estimation bias correction.
        z        >>> ser = pd.Series([1, 2, 3, 4])
        >>> ser.ewm(alpha=.2).std()
        0         NaN
        1    0.707107
        2    0.995893
        3    1.277320
        dtype: float64
        z0(exponential weighted moment) standard deviationstdbiasc                 C  sB   |r| j jdkrt| j jstt| j dt| j||dS )Nr,   z$.std does not implement numeric_only)r   r   )	_selected_objndimr	   r=   r`   type__name__r   varrk   r   r   r5   r5   r6   r   q  s    
zExponentialMovingWindow.stdz        >>> ser = pd.Series([1, 2, 3, 4])
        >>> ser.ewm(alpha=.2).var()
        0         NaN
        1    0.500000
        2    0.991803
        3    1.631547
        dtype: float64
        z&(exponential weighted moment) variancer   c                   s:   t j}t|| j| j| j|d  fdd}| j|d|dS )N)rJ   rL   rM   r   c                   s    | |||| S rq   r5   )valuesbeginro   rK   wfuncr5   r6   var_func  s   z-ExponentialMovingWindow.var.<locals>.var_funcr   r   )r   ewmcovr   rh   rL   rM   r   )rk   r   r   r   r   r5   r   r6   r     s   zExponentialMovingWindow.vara          other : Series or DataFrame , optional
            If not supplied then will default to self and produce pairwise
            output.
        pairwise : bool, default None
            If False then only matching columns between self and other will be
            used and the output will be a DataFrame.
            If True then all pairwise combinations will be calculated and the
            output will be a MultiIndex DataFrame in the case of DataFrame
            inputs. In the case of missing elements, only complete pairwise
            observations will be used.
        bias : bool, default False
            Use a standard estimation bias correction.
        z        >>> ser1 = pd.Series([1, 2, 3, 4])
        >>> ser2 = pd.Series([10, 11, 13, 16])
        >>> ser1.ewm(alpha=.2).cov(ser2)
        0         NaN
        1    0.500000
        2    1.524590
        3    3.408836
        dtype: float64
        z/(exponential weighted moment) sample covariancecovotherDataFrame | Series | Nonepairwisebool | Nonec                   s<   ddl m  d|  fdd}j||||S )Nr   r#   r   c           	        s    | } |} }jd urjn|j}|jt||jjjd\}}t	
|||j|jjj	} || j| jddS )N
num_valuesrK   rZ   r[   stepFindexr   copy)_prep_valuesrt   rK   window_sizeget_window_boundsra   rZ   r[   r   r   r   rh   rL   rM   r   r   )	xyx_arrayy_arraywindow_indexerrK   rn   ro   resultr#   r   rk   r5   r6   cov_func  s4   



z-ExponentialMovingWindow.cov.<locals>.cov_funcpandasr#   _validate_numeric_only_apply_pairwiser   )rk   r   r   r   r   r   r5   r   r6   r     s   0zExponentialMovingWindow.covaK          other : Series or DataFrame, optional
            If not supplied then will default to self and produce pairwise
            output.
        pairwise : bool, default None
            If False then only matching columns between self and other will be
            used and the output will be a DataFrame.
            If True then all pairwise combinations will be calculated and the
            output will be a MultiIndex DataFrame in the case of DataFrame
            inputs. In the case of missing elements, only complete pairwise
            observations will be used.
        z        >>> ser1 = pd.Series([1, 2, 3, 4])
        >>> ser2 = pd.Series([10, 11, 13, 16])
        >>> ser1.ewm(alpha=.2).corr(ser2)
        0         NaN
        1    1.000000
        2    0.982821
        3    0.977802
        dtype: float64
        z0(exponential weighted moment) sample correlationcorrc                   s:   ddl m  d|  fdd}j||||S )Nr   r   r   c           
        s    | } |} }jd urjn|j|jt|jjjd\  fdd}t	j
dd |||}|||}|||}|t||  }	W d    n1 s[w   Y  |	| j| jddS )Nr   c                   s    t |  |jjjd	S )NT)r   r   rh   rL   rM   )XY)ro   rK   rk   rn   r5   r6   _cova  s   z<ExponentialMovingWindow.corr.<locals>.cov_func.<locals>._covignore)allFr   )r   rt   rK   r   r   ra   rZ   r[   r   r0   errstater   r   r   )
r   r   r   r   r   r   r   x_vary_varr   r#   rk   )ro   rK   rn   r6   r   P  s,   






z.ExponentialMovingWindow.corr.<locals>.cov_funcr   )rk   r   r   r   r   r5   r   r6   r     s   -%zExponentialMovingWindow.corr)
NNNNr   TFr   NrP   )rS   r$   rJ   r&   r'   r&   r(   r:   r)   r&   rK   rT   rL   rU   rM   rU   rN   r    r8   rV   rO   rW   r*   rX   )rn   r;   ro   r;   rp   r_   r*   rX   )r*   r   )ru   N)rv   rW   r*   rw   )FNN)r   rU   FFr   rU   r   rU   NNFFr   r   r   r   r   rU   r   rU   NNFr   r   r   r   r   rU   )r   
__module____qualname____doc___attributesr]   rr   rt   rz   r   r   r   r{   aggr   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r5   r5   rl   r6   rI      sN    >
I
,%'+.)rI   c                      s>   e Zd ZdZejej Zddd fddZdd	d
Z  Z	S )ExponentialMovingWindowGroupbyzF
    Provide an exponential moving window groupby implementation.
    N)_grouperr*   rX   c                  sf   t  j|g|R d|i| |js/| jd ur1tt| jj	 }t
| j|| j| _d S d S d S )Nr   )r\   r]   emptyr8   r0   concatenatelistr   indicesr   rH   taker(   rg   )rk   rS   r   r   r   groupby_orderrl   r5   r6   r]     s   

z'ExponentialMovingWindowGroupby.__init__r   c                 C  s   t | jjtd}|S )z
        Return an indexer class that will compute the window start and end bounds

        Returns
        -------
        GroupbyIndexer
        )groupby_indicesr   )r   r   r   r   )rk   r   r5   r5   r6   rt     s
   z2ExponentialMovingWindowGroupby._get_window_indexerr*   rX   )r*   r   )
r   r   r   r   rI   r   r   r]   rt   r   r5   r5   rl   r6   r   z  s
    r   c                      s   e Zd Z											d5ddd6 fddZd7d d!Zd"d# Zd8d9d%d&Z			d:d;d,d-Z				d<d=d.d/Zd>d?d0d1Z	ddd2d3d4Z
  ZS )@rw   Nr   TFru   rQ   rS   r$   rJ   r&   r'   r(   r:   r)   rK   rT   rL   rU   rM   rN   r    r8   rV   rv   rW   rx   dict[str, bool] | Noner*   rX   c                  sn   |
d urt dt j|||||||||	|
|d t| j| j| j| j|j| _	t
|r3|| _|| _d S td)Nz0times is not implemented with online operations.)rS   rJ   r'   r(   r)   rK   rL   rM   rN   r8   rR   z$'numba' is the only supported engine)r`   r\   r]   r   rh   rL   rM   rN   rj   _meanr   rv   rx   r/   )rk   rS   rJ   r'   r(   r)   rK   rL   rM   rN   r8   rv   rx   rR   rl   r5   r6   r]     s0   
z&OnlineExponentialMovingWindow.__init__c                 C  s   | j   dS )z=
        Reset the state captured by `update` calls.
        N)r   resetrs   r5   r5   r6   r     s   z#OnlineExponentialMovingWindow.resetc                 O     t d)Nzaggregate is not implemented.r`   r   r5   r5   r6   r{        z'OnlineExponentialMovingWindow.aggregater   c                 O  r   )Nzstd is not implemented.r   )rk   r   r   r   r5   r5   r6   r     r   z!OnlineExponentialMovingWindow.stdr   r   r   r   r   c                 C  r   )Nzcorr is not implemented.r   )rk   r   r   r   r5   r5   r6   r     s   z"OnlineExponentialMovingWindow.corrc                 C  r   )Nzcov is not implemented.r   )rk   r   r   r   r   r5   r5   r6   r     s   z!OnlineExponentialMovingWindow.covc                 C  r   )Nzvar is not implemented.r   r   r5   r5   r6   r     r   z!OnlineExponentialMovingWindow.var)updateupdate_timesc                O  sl  i }| j jdk}|durtdtjt| j j| jd  d dtjd}|dur_| j	j
du r2tdd}|j|d< |rL| j	j
tjddf }	|j|d	< n	| j	j
}	|j|d
< t|	| f}
n d}| j j|d< |rp| j j|d	< n| j j|d
< | j tj }
tdi t| j}| j	|r|
n|
ddtjf || j|}|s| }||d }| j j|fi |}|S )a[  
        Calculate an online exponentially weighted mean.

        Parameters
        ----------
        update: DataFrame or Series, default None
            New values to continue calculating the
            exponentially weighted mean from the last values and weights.
            Values should be float64 dtype.

            ``update`` needs to be ``None`` the first time the
            exponentially weighted mean is calculated.

        update_times: Series or 1-D np.ndarray, default None
            New times to continue calculating the
            exponentially weighted mean from the last values and weights.
            If ``None``, values are assumed to be evenly spaced
            in time.
            This feature is currently unsupported.

        Returns
        -------
        DataFrame or Series

        Examples
        --------
        >>> df = pd.DataFrame({"a": range(5), "b": range(5, 10)})
        >>> online_ewm = df.head(2).ewm(0.5).online()
        >>> online_ewm.mean()
              a     b
        0  0.00  5.00
        1  0.75  5.75
        >>> online_ewm.mean(update=df.tail(3))
                  a         b
        2  1.615385  6.615385
        3  2.550000  7.550000
        4  3.520661  8.520661
        >>> online_ewm.reset()
        >>> online_ewm.mean()
              a     b
        0  0.00  5.00
        1  0.75  5.75
        r-   Nz update_times is not implemented.r,   r   r<   z;Must call mean with update=None first before passing updater   columnsr   r5   )r   r   r`   r0   ri   r^   rj   rN   rB   r   last_ewmr/   r   newaxisr   r   r   to_numpyastyper   r   rx   run_ewmrK   squeeze_constructor)rk   r   r   r   r   result_kwargsis_frameupdate_deltasresult_from
last_valuenp_array	ewma_funcr   r5   r5   r6   r     sP   ,

z"OnlineExponentialMovingWindow.mean)NNNNr   TFr   Nru   N)rS   r$   rJ   r&   r'   r&   r(   r:   r)   r&   rK   rT   rL   rU   rM   rU   rN   r    r8   rV   rv   rW   rx   r   r*   rX   r   )F)r   rU   r   r   r   r   r   r   )r   r   r   r]   r   r{   r   r   r   r   r   r   r5   r5   rl   r6   rw     s:    
+
	rw   )
r%   r&   r'   r&   r(   r&   r)   r&   r*   r+   )r8   r9   r(   r:   r*   r;   )C
__future__r   rc   	functoolsr   textwrapr   typingr   numpyr0   pandas._libs.tslibsr    pandas._libs.window.aggregations_libswindowaggregationsr   pandas.util._decoratorsr   pandas.core.dtypes.commonr   r	   pandas.core.dtypes.missingr
   pandas.corer   pandas.core.indexers.objectsr   r   r   pandas.core.util.numba_r   r   pandas.core.window.commonr   pandas.core.window.docr   r   r   r   r   r   r   r   pandas.core.window.numba_r   r   pandas.core.window.onliner   r   pandas.core.window.rollingr   r   pandas._typingr    r!   r   r"   r#   pandas.core.genericr$   r7   rH   rI   r   rw   r5   r5   r5   r6   <module>   sD    (


!      !