a
    DBìjv‰  ã                   @  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 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/m0Z0m1Z1m2Z2 d dl3m4Z4m5Z5 d dl6m7Z7m8Z8 d dl9m:Z:m;Z; e�rzd dl<m=Z=m>Z>m?Z? d dl@mAZAmBZB d dlCmDZD ddddddœdd„ZEdddd œd!d"„ZFG d#d$„ d$e:ƒZGG d%d&„ d&e;eGƒZHG d'd(„ d(eGƒZIdS ))é    )ÚannotationsN)Úpartial)Údedent)ÚTYPE_CHECKING)Ú	Timedelta)Údoc)Úis_datetime64_dtypeÚis_numeric_dtype)ÚDatetimeTZDtype)Ú	ABCSeries)Úisna)Úcommon)Údtype_to_unit)Ú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Únpt)Ú	DataFrameÚSeries)ÚNDFrameúfloat | NoneÚfloat)ÚcomassÚspanÚhalflifeÚalphaÚreturnc                 C  sÜ   t  | |||¡}|dkr tdƒ‚| d ur:| dk rÔtdƒ‚nš|d ur`|dk rRtdƒ‚|d d } nt|d urž|dkrxtdƒ‚dt t d¡| ¡ }d| d } n6|d urÌ|dks¶|dkr¾td	ƒ‚d| | } ntd
ƒ‚t| ƒS )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.   Zvalid_countZdecay© r7   úU/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pandas/core/window/ewm.pyÚget_center_of_massG   s*    
r9   znp.ndarray | NDFrameú(float | TimedeltaConvertibleTypes | Noneznpt.NDArray[np.float64])Útimesr-   r/   c                 C  sT   t | jƒ}t| tƒr| j} tj|  tj¡tj	d�}t
t|ƒ |¡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)r   r=   Ú
isinstancer   Z_valuesr4   ZasarrayÚviewZint64Úfloat64r*   r   Zas_unitÚ_valueÚdiff)r;   r-   ÚunitZ_timesZ	_halflifer7   r7   r8   Ú_calculate_deltash   s    

rD   c                      s„  e Zd ZdZg d¢ZdYddœd	d
d
dd
ddddddddœ‡ fdd„Zdddddœdd„Zddœdd„ZdZddd œd!d"„Ze	e
d# ed$ƒed%ƒd&d'd(�‡ fd)d*„ƒZeZe	eed+ƒeeƒ ed,ƒeed-ƒeed.ƒeed/ƒed0ƒd1d2d3d4�d[dd5œd6d7„ƒZe	eed+ƒeeƒ ed,ƒeed-ƒeed.ƒeed/ƒed8ƒd1d9d:d4�d\dd5œd;d<„ƒZe	eed+ƒed=ƒeed,ƒeed-ƒeed/ƒed>ƒd1d?d@d4�d]dddAœdBdC„ƒZe	eed+ƒed=ƒeed,ƒeed-ƒeed/ƒedDƒd1dEdFd4�d^dddAœdGdH„ƒZe	eed+ƒedIƒeed,ƒeed-ƒeed/ƒedJƒd1dKdLd4�d_dMdNdddOœdPdQ„ƒZe	eed+ƒedRƒeed,ƒeed-ƒeed/ƒedSƒd1dTdUd4�d`dMdNddVœdWdX„ƒZ‡  ZS )aÚ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Úaxisr;   ÚmethodNr   TFÚsingle©Ú	selectionr(   r)   r:   ú
int | NoneÚboolr#   únp.ndarray | NDFrame | NoneÚstrÚNone)ÚobjrF   r,   r-   r.   rG   rH   rI   rJ   r;   rK   r/   c             
     s¤  t ƒ j||d u rdntt|ƒdƒd dd ||	|d� || _|| _|| _|| _|| _|| _	|
| _
| j
d u�r6| jsvtdƒ‚t| j
dd ƒ}t|ƒsžt|tƒsžtdƒ‚t| j
ƒt|ƒkr¸tdƒ‚t| jttjtjfƒsÖtdƒ‚t| j
ƒ ¡ rìtd	ƒ‚t| j
| jƒ| _t | j| j| j¡d
k�r.t| j| jd | jƒ| _nd| _nj| jd u�rbt| jttjtjfƒ�rbtdƒ‚tjt| j j!| j" d d
ƒtj#d�| _t| j| j| j| jƒ| _d S )Nr0   F)rT   rG   ÚonÚcenterÚclosedrK   rJ   rN   z)times is not supported with adjust=False.r=   ztimes must be datetime64 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ÚintrF   r,   r-   r.   rH   rI   r;   ÚNotImplementedErrorÚgetattrr   r>   r
   r3   ÚlenrR   ÚdatetimeÚ	timedeltar4   Ztimedelta64r   ÚanyrD   Ú_deltasr   r2   r9   Ú_comÚonesrT   ÚshaperJ   r@   )ÚselfrT   rF   r,   r-   r.   rG   rH   rI   rJ   r;   rK   rN   Ztimes_dtype©Ú	__class__r7   r8   rY   P  sf    ø
ÿþÿÿÿùz ExponentialMovingWindow.__init__z
np.ndarrayr[   )ÚstartÚendÚnum_valsr/   c                 C  s   d S ©Nr7   )rf   ri   rj   rk   r7   r7   r8   Ú_check_window_bounds�  s    z,ExponentialMovingWindow._check_window_boundsr   ©r/   c                 C  s   t ƒ S )z[
        Return an indexer class that will compute the window start and end bounds
        )r   ©rf   r7   r7   r8   Ú_get_window_indexer¤  s    z+ExponentialMovingWindow._get_window_indexerÚnumbaÚOnlineExponentialMovingWindow)Úenginer/   c                 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
        )rT   rF   r,   r-   r.   rG   rH   rI   rJ   r;   rs   Úengine_kwargsrN   )rr   rT   rF   r,   r-   r.   rG   rH   rI   rJ   r;   Z
_selection)rf   rs   rt   r7   r7   r8   Ú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Ú )Zsee_alsoZexamplesÚklassrJ   c                   s   t ƒ j|g|¢R i |¤ŽS rl   )rX   rv   ©rf   ÚfuncÚargsÚkwargsrg   r7   r8   rv   Ö  s    z!ExponentialMovingWindow.aggregateZ
ParametersZReturnszSee AlsoZNotesZ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)Zwindow_methodZaggregation_descriptionZ
agg_method)Únumeric_onlyc              	   C  s¼   t |ƒrX| jdkrt}nt}|f i t|ƒ¤| j| j| jt| j	ƒddœ¤Ž}| j
|dd�S |dv r°|d urptdƒ‚| jd u r~d n| j	}ttj| j| j| j|dd�}| j
|d|d�S td	ƒ‚d S )
NrL   T©rF   rH   rI   ÚdeltasÚ	normalizer~   ©Úname©ÚcythonNú+cython engine does not accept engine_kwargs©r„   r   ú)engine must be either 'numba' or 'cython')r   rK   r   r   r   rc   rH   rI   Útuplerb   Ú_applyr3   r;   r   Úwindow_aggregationsr}   ©rf   r   rs   rt   rz   Zewm_funcr�   Úwindow_funcr7   r7   r8   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|ƒrf| jdkr&t}nt}|f i t|ƒ¤| j| j | jt	| j
ƒddœ¤Ž}| j|dd�S |dv r¾|d ur~tdƒ‚| jd u rŒd n| j
}ttj| j| j | j|dd�}| j|d|d	�S td
ƒ‚d S )Nz(sum is not implemented with adjust=FalserL   Fr€   r�   rƒ   r…   r‡   rˆ   r‰   )rH   r\   r   rK   r   r   r   rc   rI   rŠ   rb   r‹   r3   r;   r   rŒ   r}   r�   r7   r7   r8   r�   9  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©Úbiasr   c                 C  sB   |r0| j jdkr0t| j jƒs0tt| ƒj› d�ƒ‚t| j||d�ƒS )Nr0   z$.std does not implement numeric_onlyr‘   )	Ú_selected_objÚndimr	   r=   r\   ÚtypeÚ__name__r   Úvar©rf   r’   r   r7   r7   r8   r�   {  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)rF   rH   rI   r’   c                   s   ˆ | |||| ƒS rl   r7   )ÚvaluesÚbeginrj   rG   ©Zwfuncr7   r8   Úvar_funcÍ  s    z-ExponentialMovingWindow.var.<locals>.var_funcr—   rˆ   )rŒ   Úewmcovr   rc   rH   rI   r‹   )rf   r’   r   rŽ   rœ   r7   r›   r8   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úDataFrame | Series | Noneúbool | None©ÚotherÚpairwiser’   r   c                   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©Z
num_valuesrG   rV   rW   ÚstepF©Úindexr„   Úcopy)Ú_prep_valuesrp   rG   Úwindow_sizeÚget_window_boundsr^   rV   rW   r¦   rŒ   r�   rc   rH   rI   r¨   r„   )	ÚxÚyÚx_arrayÚy_arrayÚwindow_indexerrG   ri   rj   Úresult©r'   r’   rf   r7   r8   Úcov_func  s4    

ÿýû
õz-ExponentialMovingWindow.cov.<locals>.cov_func©Úpandasr'   Z_validate_numeric_onlyZ_apply_pairwiser“   )rf   r¢   r£   r’   r   r´   r7   r³   r8   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Úcorr©r¢   r£   r   c                   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¶0    Y  ˆ|	| j| jdd�S )Nr¥   c                   s    t  | ˆˆ ˆ|ˆjˆjˆjd¡	S )NT)rŒ   r�   rc   rH   rI   )ÚXÚY)rj   rG   rf   ri   r7   r8   Ú_covk  s    ÷z<ExponentialMovingWindow.corr.<locals>.cov_func.<locals>._covÚignore)ÚallFr§   )rª   rp   rG   r«   r¬   r^   rV   rW   r¦   r4   Zerrstater   r¨   r„   )
r­   r®   r¯   r°   r±   r»   rž   Zx_varZy_varr²   ©r'   rf   )rj   rG   ri   r8   r´   Z  s*    

ÿýû



.z.ExponentialMovingWindow.corr.<locals>.cov_funcrµ   )rf   r¢   r£   r   r´   r7   r¾   r8   r·   )  s    -%ÿzExponentialMovingWindow.corr)
NNNNr   TFr   NrL   )rq   N)FNN)FNN)FF)FF)NNFF)NNF)r–   Ú
__module__Ú__qualname__Ú__doc__Ú_attributesrY   rm   rp   ru   r   r   r   rv   Zaggr   r   r   r   r   r   r   r~   r�   r�   r—   rž   r·   Ú__classcell__r7   r7   rg   r8   rE   …   sL   >          ôò,M ÿ,ÿÿäÿç   ü%ÿç   ü'ÿÿäÿÿäÿÿÙ+    û.ÿÿÛ)   ürE   c                      sF   e Zd ZdZejej Zddœddœ‡ fdd„Zddœd	d
„Z‡  Z	S )ÚExponentialMovingWindowGroupbyzF
    Provide an exponential moving window groupby implementation.
    N)Ú_grouperrS   rn   c                  s^   t ƒ j|g|¢R d|i|¤Ž |jsZ| jd urZt t| jj 	¡ ƒ¡}t
| j |¡| jƒ| _d S )NrÅ   )rX   rY   Úemptyr;   r4   ÚconcatenateÚlistrÅ   Úindicesr™   rD   Ztaker-   rb   )rf   rT   rÅ   r{   r|   Zgroupby_orderrg   r7   r8   rY   ‹  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
        )Zgroupby_indicesr±   )r   rÅ   rÉ   r   )rf   r±   r7   r7   r8   rp   –  s
    þz2ExponentialMovingWindowGroupby._get_window_indexer)
r–   r¿   rÀ   rÁ   rE   rÂ   r"   rY   rp   rÃ   r7   r7   rg   r8   rÄ   „  s   rÄ   c                      s´   e Zd Zd*ddœdddd	dd
ddddddddœ‡ fdd„Zddœdd„Zdd„ Zd+ddœdd„Zd,ddddœdd „Zd-ddddd!œd"d#„Zd.ddd$œd%d&„Z	ddd'œd(d)„Z
‡  ZS )/rr   Nr   TFrq   rM   r(   r)   r:   rO   rP   r#   rQ   rR   zdict[str, bool] | NonerS   )rT   rF   r,   r-   r.   rG   rH   rI   rJ   r;   rs   rt   r/   c                  sp   |
d urt dƒ‚tƒ j|||||||||	|
|d� t| j| j| j| j|jƒ| _	t
|ƒrd|| _|| _ntdƒ‚d S )Nz0times is not implemented with online operations.)rT   rF   r,   r-   r.   rG   rH   rI   rJ   r;   rN   z$'numba' is the only supported engine)r\   rX   rY   r   rc   rH   rI   rJ   re   Ú_meanr   rs   rt   r3   )rf   rT   rF   r,   r-   r.   rG   rH   rI   rJ   r;   rs   rt   rN   rg   r7   r8   rY   ¦  s0    ÿõÿz&OnlineExponentialMovingWindow.__init__rn   c                 C  s   | j  ¡  dS )z=
        Reset the state captured by `update` calls.
        N)rÊ   Úresetro   r7   r7   r8   rË   Ñ  s    z#OnlineExponentialMovingWindow.resetc                 O  s   t dƒ‚d S )Nzaggregate is not implemented.©r\   ry   r7   r7   r8   rv   ×  s    z'OnlineExponentialMovingWindow.aggregate)r’   c                 O  s   t dƒ‚d S )Nzstd is not implemented.rÌ   )rf   r’   r{   r|   r7   r7   r8   r�   Ú  s    z!OnlineExponentialMovingWindow.stdrŸ   r    r¸   c                 C  s   t dƒ‚d S )Nzcorr is not implemented.rÌ   )rf   r¢   r£   r   r7   r7   r8   r·   Ý  s    z"OnlineExponentialMovingWindow.corrr¡   c                 C  s   t dƒ‚d S )Nzcov is not implemented.rÌ   )rf   r¢   r£   r’   r   r7   r7   r8   rž   å  s    z!OnlineExponentialMovingWindow.covr‘   c                 C  s   t dƒ‚d S )Nzvar is not implemented.rÌ   r˜   r7   r7   r8   r—   î  s    z!OnlineExponentialMovingWindow.var)ÚupdateÚupdate_timesc                O  st  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 rdtdƒ‚d}|j|d< |r˜| j	j
tjdd…f }	|j|d	< n| j	j
}	|j|d
< t |	| ¡ f¡}
nDd}| j j|d< |rà| j j|d	< n| j j|d
< | j jtjdd� ¡ }
tf i t| jƒ¤Ž}| j	 |�r&|
n|
dd…tjf || j|¡}|�sP| ¡ }||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
        r1   Nz update_times is not implemented.r0   r   r<   z;Must call mean with update=None first before passing updater¨   Úcolumnsr„   F)r©   )r“   r”   r\   r4   rd   rZ   re   rJ   r@   rÊ   Zlast_ewmr3   r¨   ZnewaxisrÏ   r„   rÇ   Zto_numpyZastyper    r   rt   Zrun_ewmrG   ZsqueezeZ_constructor)rf   rÍ   rÎ   r{   r|   Zresult_kwargsZis_frameZupdate_deltasZresult_fromÚ
last_valueZnp_arrayZ	ewma_funcr²   r7   r7   r8   r~   ñ  sP    ,ÿÿ

ÿüz"OnlineExponentialMovingWindow.mean)NNNNr   TFr   Nrq   N)F)NNF)NNFF)FF)r–   r¿   rÀ   rY   rË   rv   r�   r·   rž   r—   r~   rÃ   r7   r7   rg   r8   rr   ¥  s8              óñ.+   ü
    û	rr   )JÚ
__future__r   r_   Ú	functoolsr   Útextwrapr   Útypingr   Únumpyr4   Zpandas._libs.tslibsr   Z pandas._libs.window.aggregationsZ_libsZwindowZaggregationsrŒ   Zpandas.util._decoratorsr   Zpandas.core.dtypes.commonr   r	   Zpandas.core.dtypes.dtypesr
   Zpandas.core.dtypes.genericr   Zpandas.core.dtypes.missingr   Zpandas.corer   Zpandas.core.arrays.datetimeliker   Zpandas.core.indexers.objectsr   r   r   Zpandas.core.util.numba_r   r   Zpandas.core.window.commonr   Zpandas.core.window.docr   r   r   r   r   r   r   r   Zpandas.core.window.numba_r   r   Zpandas.core.window.onliner   r    Zpandas.core.window.rollingr!   r"   Zpandas._typingr#   r$   r%   r¶   r&   r'   Zpandas.core.genericr(   r9   rD   rE   rÄ   rr   r7   r7   r7   r8   Ú<module>   sH   (
!      !