Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/site-packages/pandas/core/window/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/site-packages/pandas/core/window/__pycache__/ewm.cpython-312.pyc

�

Mٜgv�����ddlmZddlZddlmZddlmZddlmZddl	Z
ddlmZddl
mcmcmZddlmZddlmZmZdd	lmZdd
lmZddlmZddlmZdd
lm Z ddl!m"Z"m#Z#m$Z$ddl%m&Z&m'Z'ddl(m)Z)ddl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2ddl3m4Z4m5Z5ddl6m7Z7m8Z8ddl9m:Z:m;Z;erddl<m=Z=m>Z>m?Z?ddl@mAZAmBZBddlCmDZD										d d�ZE						d!d�ZFGd�de:�ZGGd�de;eG�ZHGd�deG�ZIy)"�)�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)�NDFramec���tj||||�}|dkDrtd��|�|dkr�td��|�#|dkrtd��|dz
dz}t
|�S|�Q|dkrtd��dtjtj
d�|z�z
}d|zdz
}t
|�S|�(|dks|dkDrtd	��d|z
|z}t
|�Std
��t
|�S)N�z8comass, span, halflife, and alpha are mutually exclusiverz comass must satisfy: comass >= 0zspan 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�log�float)�comass�span�halflife�alpha�valid_count�decays      �A/usr/local/lib/python3.12/site-packages/pandas/core/window/ewm.py�get_center_of_massr:Gs!���'�'���h��F�K��Q���S�T�T����A�:��?�@�@�	
�	��!�8��;�<�<���(�a�����=��
�	��q�=��B�C�C��B�F�F�2�6�6�#�;��1�2�2���U��Q�����=��
�	��A�:�����A�B�B��e�)�u�$����=���L�M�M���=��c�r�t|j�}t|t�r|j}tj|jt
j�t
j��}tt|�j|�j�}tj|�|zS)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)rr>�
isinstancer�_valuesr/�asarray�view�int64�float64r2r�as_unit�_value�diff)�timesr5�unit�_times�	_halflifes     r9�_calculate_deltasrLhsy��*����%�D��%��#��
�
��
�Z�Z��
�
�2�8�8�,�B�J�J�
?�F��i��)�1�1�$�7�>�>�?�I�
�7�7�6�?�Y�&�&r;c�R��eZdZdZgd�Z										d2dd�																							d3�fd�Z								d4d�Zd5d�Z	d6			d7d�Ze	e
d	ed
�ed�dd
���fd��ZeZ
e	eed�ee�ed�eed�eed�eed�ed�ddd��			d8	d9d��Ze	eed�ee�ed�eed�eed�eed�ed�ddd��			d8	d9d��Ze	eed�ed�eed�eed�eed�ed �dd!d"��
d:d;d#��Ze	eed�ed�eed�eed�eed�ed$�dd%d&��
d:d;d'��Ze	eed�ed(�eed�eed�eed�ed)�dd*d+��
				d<							d=d,��Ze	eed�ed-�eed�eed�eed�ed.�dd/d0��
			d>					d?d1��Z�xZS)@�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
    )
�comr4r5r6�min_periods�adjust�	ignore_na�axisrH�methodN��	selectionc
���t�|�||�dntt|�d�ddd||	|��||_||_||_||_||_||_	|
|_
|j���|jstd��t|jdd�}
t|
�st|
t�st!d��t#|j�t#|�k7rt!d��t|jt$t&j(t*j,f�st!d��t/|j�j1�rt!d	��t3|j|j�|_t7j8|j|j
|j�d
kDr2t;|j|j
d|j�|_yd|_y|j�Dt|jt$t&j(t*j,f�rt!d��t+j>t|j@jB|jDdz
d
�t*jF�
�|_t;|j|j
|j|j�|_y)Nr+F)�objrP�on�center�closedrTrSrVz)times is not supported with adjust=False.r>ztimes 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 integerrg�?zKhalflife can only be a timedelta convertible argument if times is not None.r=)$�super�__init__�max�intrOr4r5r6rQrRrH�NotImplementedError�getattrr	r?rr.�len�str�datetime�	timedeltar/�timedelta64r
�anyrL�_deltasrr-r:�_com�onesrX�shaperSrD)�selfrXrOr4r5r6rPrQrRrSrHrTrV�times_dtype�	__class__s              �r9r]z ExponentialMovingWindow.__init__Ps1��� 	����(�0��c�#�k�:J�A�6N�������	�		
������	� ��
���
����"�����
��:�:�!��;�;�)�*U�V�V�!�$�*�*�g�t�<�K�#�K�0��k�?�;� �!B�C�C��4�:�:��#�c�(�*� �!O�P�P��d�m�m�c�8�3E�3E�r�~�~�-V�W� �!R�S�S��D�J�J��#�#�%� �!G�H�H�,�T�Z�Z����G�D�L��$�$�T�X�X�t�y�y�$�*�*�E��I�.�t�x�x����D�$�*�*�U��	���	��}�}�(�Z��
�
��X�%7�%7����H�.�!�)���
�7�7��D�H�H�N�N�4�9�9�-��1�1�5�R�Z�Z��D�L�+�����	�	��
�
��
�
��D�Ir;c��y�N�)rl�start�end�num_valss    r9�_check_window_boundsz,ExponentialMovingWindow._check_window_bounds�s��
	
r;c��t�S)z[
        Return an indexer class that will compute the window start and end bounds
        )r�rls r9�_get_window_indexerz+ExponentialMovingWindow._get_window_indexer�s
��.�/�/r;c��t|j|j|j|j|j
|j|j|j|j|j|||j��
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
        )
rXrOr4r5r6rPrQrRrSrH�engine�
engine_kwargsrV)�OnlineExponentialMovingWindowrXrOr4r5r6rPrQrRrSrH�
_selection)rlrzr{s   r9�onlinezExponentialMovingWindow.online�sf��8-�����������]�]��*�*��(�(��;�;��n�n�����*�*��'��o�o�
�	
r;�	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
        zSeries/Dataframe�)�see_also�examples�klassrSc�*��t�|�|g|��i|��Srp)r\r)rl�func�args�kwargsrns    �r9rz!ExponentialMovingWindow.aggregate�s���>�w� ��7��7��7�7r;�
Parameters�ReturnszSee 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_methodc
��t|�ry|jdk(rt}nt}|d
it	|��|j
|j|jt|j�dd���}|j|d��S|dvrx|�td��|j�dn|j}ttj|j
|j|j|d��}|j|d|��Std	��)N�singleT�rOrQrR�deltas�	normalizer���name��cythonN�+cython engine does not accept engine_kwargs�r��numeric_only�)engine must be either 'numba' or 'cython'rq)rrTrrrrirQrR�tuplerh�_applyr.rHr�window_aggregationsr��rlr�rzr{r��ewm_funcr��window_funcs        r9r�zExponentialMovingWindow.mean�s���B�6�"��{�{�h�&�.��4����#�M�2���I�I��{�{��.�.��T�\�\�*��
�H��;�;�x�f�;�5�5�
�'�
'��(� �!N�O�O�!�Z�Z�/�T�T�\�\�F�!�#�'�'��I�I��{�{��.�.���
�K��;�;�{��l�;�S�S��H�I�Ir;z�        >>> 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
�F�|jstd��t|�ry|jdk(rt}nt
}|dit
|��|j|j|jt|j�dd���}|j|d��S|dvrx|�td��|j�dn|j}ttj |j|j|j|d��}|j|d|�	�Std
��)Nz(sum is not implemented with adjust=Falser�Fr�r�r�r�r�r�r�rq)rQr`rrTrrrrirRr�rhr�r.rHrr�r�r�s        r9r�zExponentialMovingWindow.sum9s��B�{�{�%�&P�Q�Q��6�"��{�{�h�&�.��4����#�M�2���I�I��{�{��.�.��T�\�\�*��
�H��;�;�x�e�;�4�4�
�'�
'��(� �!N�O�O�!�Z�Z�/�T�T�\�\�F�!�#�'�'��I�I��{�{��.�.���
�K��;�;�{��\�;�R�R��H�I�Ir;zb        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�stdc���|rY|jjdk(r@t|jj�s!t	t|�j�d���t|j||���S)Nr+z$.std does not implement numeric_only)�biasr�)	�
_selected_obj�ndimr
r>r`�type�__name__r�var�rlr�r�s   r9r�zExponentialMovingWindow.std{so��@
��"�"�'�'�1�,�$�T�%7�%7�%=�%=�>�&���:�&�&�'�'K�L��
��T�X�X�4�l�X�C�D�Dr;z�        >>> 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���tj}t||j|j|j
|����fd�}|j
|d|��S)N)rOrQrRr�c����|||||�Srprq)�values�beginrsrP�wfuncs    �r9�var_funcz-ExponentialMovingWindow.var.<locals>.var_func�s�������[�&�A�Ar;r�r�)r��ewmcovrrirQrRr�)rlr�r�r�r�r�s     @r9r�zExponentialMovingWindow.var�sR���>*�0�0�����	�	��;�;��n�n��
��	B��{�{�8�%�l�{�K�Kr;a�        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�covc�����ddlm��jd|����fd�}�j�j||||�S)Nr�r(r�c����j|�}�j|�}�j�}�j��jn|j}|j	t|�|�j�j�j��\}}tj|||�j|�j�j�j�
�	}�	||j|jd��S)N��
num_valuesrPrZr[�stepF��indexr��copy)�_prep_valuesrxrP�window_size�get_window_boundsrbrZr[r�r�r�rirQrRr�r�)�x�y�x_array�y_array�window_indexerrPrrrs�resultr(r�rls         ���r9�cov_funcz-ExponentialMovingWindow.cov.<locals>.cov_funcs�����'�'��*�G��'�'��*�G�!�5�5�7�N��#�#�/�� � �#�/�/�
�
(�9�9��w�<�'��{�{��{�{��Y�Y�:��J�E�3�)�/�/����� � ���	�	���������F��&����a�f�f�5�I�Ir;��pandasr(�_validate_numeric_only�_apply_pairwiser�)rl�other�pairwiser�r�r�r(s`  `  @r9r�zExponentialMovingWindow.cov�sE���`	"��#�#�E�<�8�	J�>�#�#�����x��<�
�	
r;aK        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����ddlm��jd|���fd�}�j�j||||�S)Nrr�r�c�4��
����j|�}�j|�}�j�}�j��jn|j�|j	t|���j�j�j��\��
�
���fd�}tjd��5|||�}|||�}|||�}|t||z�z}	ddd��
	|j|jd��S#1swY�)xYw)Nr�c�z��tj|���|�j�j�jd�	S)NT)r�r�rirQrR)�X�YrsrPrlrrs  ����r9�_covz<ExponentialMovingWindow.corr.<locals>.cov_func.<locals>._covks=���*�1�1�������I�I��K�K��N�N��
�
r;�ignore)�allFr�)r�rxrPr�r�rbrZr[r�r/�errstaterr�r�)r�r�r�r�r�r�r��x_var�y_varr�rsrPrrr(rls          @@@��r9r�z.ExponentialMovingWindow.corr.<locals>.cov_funcZs����'�'��*�G��'�'��*�G�!�5�5�7�N��#�#�/�� � �#�/�/�
�
(�9�9��w�<�'��{�{��{�{��Y�Y�:��J�E�3�
�����*��7�G�,���W�g�.���W�g�.���u�U�U�]�3�3��	+�
�&����a�f�f�5�I�I�+�*�s�9-D�Dr�)rlr�r�r�r�r(s`    @r9r�zExponentialMovingWindow.corr)sF���Z	"��#�#�F�L�9�#	J�J�#�#�����x��<�
�	
r;)
NNNNrTFrNr�)rXr)rO�float | Noner4r�r5�(float | TimedeltaConvertibleTypes | Noner6r�rP�
int | NonerQ�boolrRr�rSr$rH�np.ndarray | NDFrame | NonerTrc�return�None)rr�
np.ndarrayrsr�rtr_r�r�)r�r)�numbaN)rzrcr�r|)FNN)r�r��FF�r�r�r�r��NNFF�r��DataFrame | Series | Noner��bool | Noner�r�r�r��NNF�r�r�r�r�r�r�)r��
__module__�__qualname__�__doc__�_attributesr]rurxr~rrrr�aggrrrrrrrr�r�r�r�r�r��
__classcell__�rns@r9rNrN�sv���{�z�K� !�!�=A�"�"#����-1��K��K�
�K��K��	K�
;�K��
K� �K��K��K��K�+�K��K�
�K�Z
��
�&0�
�<?�
�	
�
�0�48�*
��*
�	&�*
�X	��[�!��
�
��
�
�$!�
�9�<8�=�<8��C����l�+��#�%��i�(���j�)���g�&���j�)��
�
	
�� D��3�:#���	#J��#J�7�6#J�J	���l�+��#�%��i�(���j�)���g�&���j�)��
�
	
�� C��3�:#���	%J��%J�7�6%J�N	���l�+��
�	
�	��i�(���j�)���j�)��
�
	
�� R��9�<
E�=�<
E�	���l�+��
�	
�	��i�(���j�)���j�)��
�
	
�� H��9�<
L�=�<
L�	���l�+��

�	
� 	��i�(���j�)���j�)��	
�	
�� Q��O(�V,0� $��"�,
�(�,
��,
��	,
�
�,
�S(�R,
�\	���l�+��
�
	
�	��i�(���j�)���j�)��	
�	
�� R��K&�R,0� $�"�	1
�(�1
��1
��	1
�O&�N1
r;rNc�d��eZdZdZej
ej
zZdd�d�fd�Zdd�Z�xZ	S)�ExponentialMovingWindowGroupbyzF
    Provide an exponential moving window groupby implementation.
    N)�_grouperc�L��t�|�|g|��d|i|��|js�|j�ut	j
t
|jjj���}t|jj|�|j�|_
yyy)Nr�)r\r]�emptyrHr/�concatenate�listr��indicesr�rL�taker5rh)rlrXr�r�r��
groupby_orderrns      �r9r]z'ExponentialMovingWindowGroupby.__init__�s���
����A�t�A�h�A�&�A��y�y�T�Z�Z�3��N�N�4��
�
�0E�0E�0L�0L�0N�+O�P�M�,��
�
���
�.��
�
��D�L�4�yr;c�P�t|jjt��}|S)z�
        Return an indexer class that will compute the window start and end bounds

        Returns
        -------
        GroupbyIndexer
        )�groupby_indicesr�)rr�r�r)rlr�s  r9rxz2ExponentialMovingWindowGroupby._get_window_indexer�s&��(� �M�M�1�1�9�
���r;�r�r�)r�r)
r�r�r�r�rNr�r#r]rxr�r�s@r9r�r��s.����*�5�5�8I�8U�8U�U�K�,0�	�r;r�c����eZdZ											ddd�																									d
�fd�Zdd�Zd�Zddd�Z			d					dd�Z				d							dd�Zddd	�Z	ddd
�d�Z
�xZS)r|NrUc

�(��|
�td��t�|�	|||||||||	|
|
��t|j|j
|j|j|j�|_	t|�r||_||_ytd��)Nz0times is not implemented with online operations.)rXrOr4r5r6rPrQrRrSrHrVz$'numba' is the only supported engine)r`r\r]r rirQrRrSrk�_meanrrzr{r.)rlrXrOr4r5r6rPrQrRrSrHrzr{rVrns              �r9r]z&OnlineExponentialMovingWindow.__init__�s����"��%�B��
�	��������#������	�	
�"��I�I�t�{�{�D�N�N�D�I�I�s�y�y�
��
��6�"� �D�K�!.�D���C�D�Dr;c�8�|jj�y)z=
        Reset the state captured by `update` calls.
        N)r�resetrws r9rz#OnlineExponentialMovingWindow.reset�s��	
�
�
���r;c��td��)Nzaggregate is not implemented.�r`)rlr�r�r�s    r9rz'OnlineExponentialMovingWindow.aggregate�s��!�"A�B�Br;c��td��)Nzstd is not implemented.r)rlr�r�r�s    r9r�z!OnlineExponentialMovingWindow.std����!�";�<�<r;c��td��)Nzcorr is not implemented.r)rlr�r�r�s    r9r�z"OnlineExponentialMovingWindow.corr�s��"�"<�=�=r;c��td��)Nzcov is not implemented.r)rlr�r�r�r�s     r9r�z!OnlineExponentialMovingWindow.cov�s��"�";�<�<r;c��td��)Nzvar is not implemented.rr�s   r9r�z!OnlineExponentialMovingWindow.var�r	r;)�update�update_timesc��i}|jjdk(}|�td��tjt|jj|jdz
dz
d�tj��}|��|jj�td��d}|j|d<|r;|jjtjdd�f}	|j|d	<n%|jj}	|j|d
<tj |	|j#�f�}
n�d}|jj|d<|r|jj|d	<n|jj|d
<|jj%tjd��j#�}
t'd
it)|j*���}|jj-|r|
n|
dd�tjf||j.|�}|s|j1�}||d}|jj2|fi|��}|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+rr=z;Must call mean with update=None first before passing updater��columnsr�F)r�rq)r�r�r`r/rjr^rkrSrDr�last_ewmr.r��newaxisrr�r��to_numpy�astyper!rr{�run_ewmrP�squeeze�_constructor)
rlr
rr�r��
result_kwargs�is_frame�
update_deltas�result_from�
last_value�np_array�	ewma_funcr�s
             r9r�z"OnlineExponentialMovingWindow.mean�s��X�
��%�%�*�*�a�/���#�%�&H�I�I������"�"�(�(����Q��7�!�;�Q�?�r�z�z�
�
����z�z�"�"�*� �Q����K�%+�\�\�M�'�"��!�Z�Z�0�0����Q��?�
�+1�>�>�
�i�(�!�Z�Z�0�0�
�(.���
�f�%��~�~�z�6�?�?�3D�&E�F�H��K�%)�%7�%7�%=�%=�M�'�"��+/�+=�+=�+E�+E�
�i�(�(,�(:�(:�(?�(?�
�f�%��)�)�0�0����%�0�H�Q�Q�S�H�3�
��� 2� 2�3�
�	����#�#� �H�h�q�"�*�*�}�&=������	
����^�^�%�F����%��0��#�#�0�0��I�=�I���
r;)NNNNrTFrNr�N)rXr)rOr�r4r�r5r�r6r�rPr�rQr�rRr�rSr$rHr�rzrcr{zdict[str, bool] | Noner�r�r)F)r�r�r�r�r�r�r�r�)r�r�r�r]rrr�r�r�r�r�r�r�s@r9r|r|�sR���!�!�=A�"�"#����-1��04�)E��)E�
�)E��)E��	)E�
;�)E��
)E� �)E��)E��)E��)E�+�)E��)E�.�)E� 
�!)E�V�C�=�
,0� $�"�	>�(�>��>��	>�,0� $��"�=�(�=��=��	=�
�=�=�"&�D�V�Vr;r|)
r3r�r4r�r5r�r6r�r�r2)rHznp.ndarray | NDFramer5r�r�znpt.NDArray[np.float64])J�
__future__rrd�	functoolsr�textwrapr�typingr�numpyr/�pandas._libs.tslibsr� pandas._libs.window.aggregations�_libs�window�aggregationsr��pandas.util._decoratorsr�pandas.core.dtypes.commonr	r
�pandas.core.dtypes.dtypesr�pandas.core.dtypes.genericr�pandas.core.dtypes.missingr
�pandas.corer�pandas.core.arrays.datetimeliker�pandas.core.indexers.objectsrrr�pandas.core.util.numba_rr�pandas.core.window.commonr�pandas.core.window.docrrrrrrrr�pandas.core.window.numba_rr�pandas.core.window.onliner r!�pandas.core.window.rollingr"r#�pandas._typingr$r%r&r�r'r(�pandas.core.genericr)r:rLrNr�r|rqr;r9�<module>r9s��"���� ��)�>�>�'��6�0�+��9���
�,�	�	�	����
����,����
�����	�
��B'��'�6�'��'�:|
�j�|
�~�%6�8O��Bb�$;�br;

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists