HOME


sh-3ll 1.0
DIR:/opt/cloudlinux/venv/lib/python3.11/site-packages/pandas/core/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/pandas/core/__pycache__/missing.cpython-311.pyc
�

���hƉ����dZddlmZddlmZddlmZmZmZm	Z	m
Z
ddlZddl
mZmZmZddlmZmZmZmZmZddlmZdd	lmZdd
lmZmZmZmZm Z m!Z!ddl"m#Z#ddl$m%Z%m&Z&m'Z'erdd
l(m)Z)dzd�Z*d{d�Z+e
dd�d|d���Z,e
d}d"���Z,d#d�d~d%�Z,gd&�Z-gd'�Z.dd+�Z/d�d/�Z0d�d2�Z1d�d6�Z2d�d9�Z3d�d:�Z4						d�d�dE�Z5d�dF�Z6								d�d�dK�Z7			d�d�dO�Z8			d�d�dU�Z9		d�d�dV�Z:			d�d�dZ�Z;d�d]�Z<				d�d�d_�Z=	d�d�da�Z>d�dd�Z?e?			d�d�df���Z@e?			d�d�dg���ZAe?			d�d�dh���ZBe?			d�d�di���ZCd�dk�ZDd�dl�ZEe@eAdm�ZFd�d�dp�ZGd�dr�ZHd�dv�ZId�dy�ZJdS)�z$
Routines for filling missing data.
�)�annotations)�wraps)�
TYPE_CHECKING�Any�Literal�cast�overloadN)�NaT�algos�lib)�	ArrayLike�AxisInt�F�
ReindexMethod�npt)�import_optional_dependency)�infer_dtype_from)�
is_array_like�
is_bool_dtype�is_numeric_dtype�is_numeric_v_string_like�is_object_dtype�needs_i8_conversion)�DatetimeTZDtype)�is_valid_na_for_dtype�isna�na_value_for_dtype��Index�mask�npt.NDArray[np.bool_]�length�intc��t|��r=t|��|kr"tdt|���d|�����||}|S)zJ
    Validate the size of the values passed to ExtensionArray.fillna.
    z'Length of 'value' does not match. Got (z)  expected )r�len�
ValueError)�valuer r"s   �J/opt/cloudlinux/venv/lib64/python3.11/site-packages/pandas/core/missing.py�check_value_sizer)3sk���U�����u�:�:�����&�#�e�*�*�&�&�#�&�&���
��d����L��arrr
�returnc�.�t|��\}}t|tj��rtj||���}nC|���}t
j|��s|g}|�||d���}d}t|j��rd}t|��}t|��}||}tj|jt���}t|j��r)t|j��st|j��rn�t|j��r)t|j��rt|j��sn�|D]�}	t!||	��r�|r5tj|jtj���}
|||	k|
|<n<||	k}
t|
tj��s|
�td���}
||
z}��|���r|t|��z}|S)a	
    Return a masking array of same size/shape as arr
    with entries equaling any member of values_to_mask set to True

    Parameters
    ----------
    arr : ArrayLike
    values_to_mask: list, tuple, or scalar

    Returns
    -------
    np.ndarray[bool]
    )�dtypeF)r.�copyT)r.�na_value)r�
isinstance�npr.�array�construct_array_typer�is_list_like�_from_sequencerr�zeros�shape�boolrrr�bool_�ndarray�to_numpy�any)r+�values_to_maskr.�cls�potential_na�arr_mask�na_mask�nonnar �x�new_masks           r(�mask_missingrFBs��"-�^�<�<��E�>��%���"�"�U���.��>�>�>����(�(�*�*�����/�/�	.�,�-�N��+�+�N�%�e�+�T�T���L��s�y�!�!������I�I�:���>�"�"�G��G�8�$�E��8�C�I�T�*�*�*�D����#�#�!��c�i�(�(�!�
�%�+�&�&�!�
	
��c�i� � �!��U�[�)�)�!��e�k�*�*�!�
	
��	!�	!�A�'��Q�/�/�

!���Q�!�x��	���B�B�B�H�),�X��!�);�H�X�&�&�"�a�x�H�%�h��
�;�;�Q�#+�#4�#4�4�%�#4�#P�#P���� ����{�{�}�}����S�	�	����Kr*.��
allow_nearest�method�,Literal['ffill', 'pad', 'bfill', 'backfill']rH�Literal[False]�Literal['pad', 'backfill']c��dS�N��rIrHs  r(�clean_fill_methodrQ��	���Cr*�7Literal['ffill', 'pad', 'bfill', 'backfill', 'nearest']�
Literal[True]�%Literal['pad', 'backfill', 'nearest']c��dSrNrOrPs  r(rQrQ�rRr*Fr9c���t|t��r%|���}|dkrd}n|dkrd}ddg}d}|r|�d��d}||vrt	d|�d	|�����|S)
N�ffill�pad�bfill�backfillzpad (ffill) or backfill (bfill)�nearestz(pad (ffill), backfill (bfill) or nearestzInvalid fill method. Expecting z. Got )r1�str�lower�appendr&)rIrH�
valid_methods�	expectings    r(rQrQ�s���
�&�#��� ��������W����F�F�
�w�
�
��F��J�'�M�1�I��?����Y�'�'�'�>�	�
�]�"�"��T�9�T�T�F�T�T�U�U�U��Mr*)�linear�time�index�values)r\�zero�slinear�	quadratic�cubic�barycentric�krogh�spline�
polynomial�from_derivatives�piecewise_polynomial�pchip�akima�cubicspliner]rdrc���|�d��}|dvr|�td���ttz}||vrtd|�d|�d����|dvr|jst|�d����|S)	N�order)rlrmz7You must specify the order of the spline or polynomial.zmethod must be one of z. Got 'z
' instead.)rkrorpz4 interpolation requires that the index be monotonic.)�getr&�
NP_METHODS�
SP_METHODS�is_monotonic_increasing)rIrd�kwargsrt�valids     r(�clean_interp_methodr{�s����J�J�w���E�
�)�)�)�e�m��R�S�S�S���#�E�
�U����R�%�R�R��R�R�R�S�S�S�
�;�;�;��,�	���O�O�O���
��Mr*�how�is_valid�
int | Nonec�H�|dvsJ�t|��dkrdS|jdkr|�d���}|dkr|dd����}n6|dkr0t|��dz
|ddd	����z
}||}|sdS|S)
a+
    Retrieves the positional index of the first valid value.

    Parameters
    ----------
    how : {'first', 'last'}
        Use this parameter to change between the first or last valid index.
    is_valid: np.ndarray
        Mask to find na_values.

    Returns
    -------
    int or None
    )�first�lastrN����axisr�r����)r%�ndimr=�argmax)r|r}�idxpos�	chk_notnas    r(�find_valid_indexr��s����#�#�#�#�#�
�8�}�}�����t��}�����<�<�Q�<�'�'��
�g�~�~��"�"�"��$�$�&�&���	�����X����"�X�d�d��d�^�%:�%:�%<�%<�<���� �I����t��Mr*�limit_direction�&Literal['forward', 'backward', 'both']c�j�gd�}|���}||vrtd|�d|�d����|S)N)�forward�backward�bothz*Invalid limit_direction: expecting one of z, got 'z'.�r^r&)r��valid_limit_directionss  r(�validate_limit_directionr�sq��=�<�<��%�+�+�-�-�O��4�4�4��
B�%�
B�
B�.=�
B�
B�
B�
�
�	
��r*�
limit_area�
str | None�#Literal['inside', 'outside'] | Nonec�n�|�2ddg}|���}||vrtd|�d|�d����|S)N�inside�outsidez%Invalid limit_area: expecting one of z, got �.r�)r��valid_limit_areass  r(�validate_limit_arear�sn����%�y�1���%�%�'�'�
��.�.�.��!�8I�!�!��!�!�!���
��r*�-Literal['backward', 'forward', 'both'] | None�&Literal['backward', 'forward', 'both']c��|�
|dvrd}n=d}n:|dvr|dkrtd|�d����|dvr|dkrtd|�d����|S)N)r[rZr�r�)rYrXz0`limit_direction` must be 'forward' for method `�`z1`limit_direction` must be 'backward' for method `)r&)r�rIs  r(�infer_limit_directionr�#s������*�*�*�(�O�O�'�O�O��%�%�%�/�Y�*F�*F��L�6�L�L�L���
��*�*�*��*�/L�/L��M�F�M�M�M���
��r*c��|dkr1ddlm}|tjt	|������}nehd�}t|j��p3t|jt��ptj
|jd��}||vr|std|�d����t|���
��rtd���|S)	Nrbrr>rcrdrer\�mMz9Index column must be numeric or datetime type when using z_ method other than linear. Try setting a numeric or datetime index column before interpolating.zkInterpolation with NaNs in the index has not been implemented. Try filling those NaNs before interpolating.)�pandasrr2�aranger%rr.r1rr�is_np_dtyper&rr=�NotImplementedError)rIrdr�methods�is_numeric_or_datetimes     r(�get_interp_indexr�8s���
���� � � � � � ���b�i��E�
�
�+�+�,�,���8�8�8���U�[�)�)�
2��%�+��7�7�
2���u�{�D�1�1�	�
�� � �)?� ��!��!�!�!���
��E�{�{�����
�!�
/�
�
�	
�
�Lr*rbr��data�
np.ndarrayr�r�limit�
fill_value�
Any | None�Nonec		�������	���t�|fi�	��t�|j��rt|jd�����dkr%t	|j��std���d�t
����t|���tj	d�����t|����d
���	�����fd�}
tj|
||��dS)z�
    Column-wise application of _interpolate_1d.

    Notes
    -----
    Alters 'data' in-place.

    The signature does differ from _interpolate_1d because it only
    includes what is needed for Block.interpolate.
    F)�compatrczStime-weighted interpolation only works on Series or DataFrames with a DatetimeIndexreN)�nobsr��yvaluesr�r,r�c
�4��td�|�����d�d�	���dS)NF)	�indicesr�rIr�r�r�r��bounds_errorr rO)�_interpolate_1d)	r�r�r�ryr��limit_area_validatedr�r rIs	 ��������r(�funcz$interpolate_2d_inplace.<locals>.func�sP���	�	
�����+�+�!���	
�	
��	
�	
�	
�	
�	
r*)r�r�r,r�)
r{rr.rrr&r�r�r�validate_limit�_index_to_interp_indicesr2�apply_along_axis)
r�rdr�rIr�r�r�r�r ryr�r�r�s
   ``` ``` @@r(�interpolate_2d_inplacer�Ws'����������.���0�0��0�0�0��Z���4�4�B�'��
�5�A�A�A�
�
����"�5�;�/�/�	�� ���
�
��.��?�?�O�.�z�:�:��
� �d�%�8�8�8�E�&�u�f�5�5�G�
�
�
�
�
�
�
�
�
�
�
�
�
�,���d�D�)�)�)�)�)r*c�.�|j}t|j��r|�d��}|dkr|}t	t
j|��}nAtj|��}|dvr)|jt
jkrtj
|��}|S)zE
    Convert Index to ndarray of indices to pass to NumPy/SciPy.
    �i8rb)rerd)�_valuesrr.�viewrr2r;�asarray�object_r�maybe_convert_objects)rdrI�xarr�indss    r(r�r��s����=�D��4�:�&�&���y�y�����
�������B�J��%�%����z�$�����(�(�(��z�R�Z�'�'��0��6�6���Kr*r�r�r�rtc
��|	�|	}nt|��}|}|���sdS|���rdStt	j|����}
t
d|���}|�d}tt|����}t
d|���}|�t|��}ttd|zt|������}|dkr"|tt||d����z}nF|dkr"|tt|d|����z}ntt|||����}|d	kr	|||zz}n|d
kr
|
|z
|z
}||z}t|��}|jjdv}|r|�
d��}|tvrRt	j||��}t	j||||||||��||<n)t#||||||f||||d
�|
��||<|	�
d|	dd�<d|	|<n!|rt$j||<ntj||<dS)a
    Logic for the 1-d interpolation.  The input
    indices and yvalues will each be 1-d arrays of the same length.

    Bounds_error is currently hardcoded to False since non-scipy ones don't
    take it as an argument.

    Notes
    -----
    Fills 'yvalues' in-place.
    Nr��r|r}rr�r�r�r�r�r�r�r�)rIr�r�rtFT)rr=�all�setr2�flatnonzeror��ranger%�
_interp_limit�sortedr.�kindr�rv�argsort�interp�_interpolate_scipy_wrapperr
r'�nan)r�r�rIr�r�r�r�r�rtr ry�invalidrz�all_nans�first_valid_index�
start_nans�last_valid_index�end_nans�
preserve_nans�mid_nans�is_datetimelike�indexers                      r(r�r��s���0������w�-�-��
�H�E��9�9�;�;�����y�y�{�{�����2�>�'�*�*�+�+�H�(�W�u�E�E�E��� ����U�,�-�-�.�.�J�'�F�U�C�C�C�����w�<�<���5��-�-�s�5�z�z�:�:�;�;�H��)�#�#�"�S��w��q�)I�)I�%J�%J�J�
�
�	�J�	&�	&� �3�}�W�a��'G�'G�#H�#H�H�
�
��M�'�5�%�@�@�A�A�
��X�����h�.�.�
�
�	�y�	 �	 ��j�(�8�3����!�
��=�)�)�M��m�(�D�0�O��%��,�,�t�$�$��
�����*�W�U�^�,�,���9��G��g�e�n�W�5�w�u�~�g�7N�
�
�����6��E�N��E�N��G��	
��!�%��	
�	
��	
�	
��������Q�Q�Q��"��]���	�(�!$���
���!#���
��
�Fr*rD�y�new_xc��|�d�}td|���ddlm}	tj|��}|	j|	jtttt|	j
d�}
gd�}||vr1|dkr|}n|}|	�|||||�	��}
|
|��}n�|d
krDt|��s|dkrtd|�����|	j||fd|i|��}
|
|��}ns|jjs|���}|jjs|���}|jjs|���}|
|}
|
|||fi|��}|S)
z�
    Passed off to scipy.interpolate.interp1d. method is scipy's kind.
    Returns an array interpolated at new_x.  Add any new methods to
    the list in _clean_interp_method.
    z interpolation requires SciPy.�scipy)�extrar��interpolate)rjrkrnrorrrqrp)r\rfrgrhrirmrm)r�r�r�rlz;order needs to be specified and greater than 0; got order: �k)rr�r�r2r��barycentric_interpolate�krogh_interpolate�_from_derivatives�_cubicspline_interpolate�_akima_interpolate�pchip_interpolate�interp1drr&�UnivariateSpline�flags�	writeabler/)rDr�r�rIr�r�rtryr�r��alt_methods�interp1d_methodsr��terp�new_ys               r(r�r�%s����5�5�5�E��w�e�4�4�4�4�!�!�!�!�!�!��J�u���E�#�:��.�-� 1�/�#��.���K������!�!�!��\�!�!��D�D��D��#�#�
�q�t�
��$�
�
����U�����	�8�	�	���;�;�	�5�A�:�:��U�e�U�U���
�,�{�+�A�q�D�D�E�D�V�D�D����U������w� �	������A��w� �	������A��{�$�	!��J�J�L�L�E��6�"����Q��5�+�+�F�+�+���Lr*�xi�yi�der�int | list[int] | None�extrapolatec��ddlm}|jj}|||�dd��||���}||��S)a�
    Convenience function for interpolate.BPoly.from_derivatives.

    Construct a piecewise polynomial in the Bernstein basis, compatible
    with the specified values and derivatives at breakpoints.

    Parameters
    ----------
    xi : array-like
        sorted 1D array of x-coordinates
    yi : array-like or list of array-likes
        yi[i][j] is the j-th derivative known at xi[i]
    order: None or int or array-like of ints. Default: None.
        Specifies the degree of local polynomials. If not None, some
        derivatives are ignored.
    der : int or list
        How many derivatives to extract; None for all potentially nonzero
        derivatives (that is a number equal to the number of points), or a
        list of derivatives to extract. This number includes the function
        value as 0th derivative.
     extrapolate : bool, optional
        Whether to extrapolate to ouf-of-bounds points based on first and last
        intervals, or to return NaNs. Default: True.

    See Also
    --------
    scipy.interpolate.BPoly.from_derivatives

    Returns
    -------
    y : scalar or array-like
        The result, of length R or length M or M by R.
    rr�r�r�)�ordersr�)r�r��BPolyrn�reshape)	r�r�rDrtr�r�r�rI�ms	         r(r�r�lsW��R"�!�!�!�!�!��
�
/�F���r�2�:�:�b�!�$�$�U��L�L�L�A��1�Q�4�4�Kr*c�X�ddlm}|�|||���}|||���S)aQ
    Convenience function for akima interpolation.
    xi and yi are arrays of values used to approximate some function f,
    with ``yi = f(xi)``.

    See `Akima1DInterpolator` for details.

    Parameters
    ----------
    xi : np.ndarray
        A sorted list of x-coordinates, of length N.
    yi : np.ndarray
        A 1-D array of real values.  `yi`'s length along the interpolation
        axis must be equal to the length of `xi`. If N-D array, use axis
        parameter to select correct axis.
    x : np.ndarray
        Of length M.
    der : int, optional
        How many derivatives to extract; None for all potentially
        nonzero derivatives (that is a number equal to the number
        of points), or a list of derivatives to extract. This number
        includes the function value as 0th derivative.
    axis : int, optional
        Axis in the yi array corresponding to the x-coordinate values.

    See Also
    --------
    scipy.interpolate.Akima1DInterpolator

    Returns
    -------
    y : scalar or array-like
        The result, of length R or length M or M by R,

    rr�r�)�nu)r�r��Akima1DInterpolator)r�r�rDr�r�r��Ps       r(r�r��sC��T"�!�!�!�!�!��'�'��B�T�'�:�:�A��1�Q�3�<�<�<�r*�
not-a-knot�bc_type�str | tuple[Any, Any]c�X�ddlm}|�|||||���}||��S)ag

    Convenience function for cubic spline data interpolator.

    See `scipy.interpolate.CubicSpline` for details.

    Parameters
    ----------
    xi : np.ndarray, shape (n,)
        1-d array containing values of the independent variable.
        Values must be real, finite and in strictly increasing order.
    yi : np.ndarray
        Array containing values of the dependent variable. It can have
        arbitrary number of dimensions, but the length along ``axis``
        (see below) must match the length of ``x``. Values must be finite.
    x : np.ndarray, shape (m,)
    axis : int, optional
        Axis along which `y` is assumed to be varying. Meaning that for
        ``x[i]`` the corresponding values are ``np.take(y, i, axis=axis)``.
        Default is 0.
    bc_type : string or 2-tuple, optional
        Boundary condition type. Two additional equations, given by the
        boundary conditions, are required to determine all coefficients of
        polynomials on each segment [2]_.
        If `bc_type` is a string, then the specified condition will be applied
        at both ends of a spline. Available conditions are:
        * 'not-a-knot' (default): The first and second segment at a curve end
          are the same polynomial. It is a good default when there is no
          information on boundary conditions.
        * 'periodic': The interpolated functions is assumed to be periodic
          of period ``x[-1] - x[0]``. The first and last value of `y` must be
          identical: ``y[0] == y[-1]``. This boundary condition will result in
          ``y'[0] == y'[-1]`` and ``y''[0] == y''[-1]``.
        * 'clamped': The first derivative at curves ends are zero. Assuming
          a 1D `y`, ``bc_type=((1, 0.0), (1, 0.0))`` is the same condition.
        * 'natural': The second derivative at curve ends are zero. Assuming
          a 1D `y`, ``bc_type=((2, 0.0), (2, 0.0))`` is the same condition.
        If `bc_type` is a 2-tuple, the first and the second value will be
        applied at the curve start and end respectively. The tuple values can
        be one of the previously mentioned strings (except 'periodic') or a
        tuple `(order, deriv_values)` allowing to specify arbitrary
        derivatives at curve ends:
        * `order`: the derivative order, 1 or 2.
        * `deriv_value`: array-like containing derivative values, shape must
          be the same as `y`, excluding ``axis`` dimension. For example, if
          `y` is 1D, then `deriv_value` must be a scalar. If `y` is 3D with
          the shape (n0, n1, n2) and axis=2, then `deriv_value` must be 2D
          and have the shape (n0, n1).
    extrapolate : {bool, 'periodic', None}, optional
        If bool, determines whether to extrapolate to out-of-bounds points
        based on first and last intervals, or to return NaNs. If 'periodic',
        periodic extrapolation is used. If None (default), ``extrapolate`` is
        set to 'periodic' for ``bc_type='periodic'`` and to True otherwise.

    See Also
    --------
    scipy.interpolate.CubicHermiteSpline

    Returns
    -------
    y : scalar or array-like
        The result, of shape (m,)

    References
    ----------
    .. [1] `Cubic Spline Interpolation
            <https://en.wikiversity.org/wiki/Cubic_Spline_Interpolation>`_
            on Wikiversity.
    .. [2] Carl de Boor, "A Practical Guide to Splines", Springer-Verlag, 1978.
    rr�)r�rr�)r�r��CubicSpline)r�r�rDr�rr�r�rs        r(r�r��sK��Z"�!�!�!�!�!����
�B�T�7��	 �	�	�A�
�1�Q�4�4�Kr*re�Literal['inside', 'outside']c�x�t|��}|}|���s�td|���}|�d}td|���}|�t|��}t	||||���|dkrd|||d	z�<n'|d
krdx|d|�<||d	zd�<ntd���tj||<dSdS)a�
    Apply interpolation and limit_area logic to values along a to-be-specified axis.

    Parameters
    ----------
    values: np.ndarray
        Input array.
    method: str
        Interpolation method. Could be "bfill" or "pad"
    limit: int, optional
        Index limit on interpolation.
    limit_area: {'inside', 'outside'}
        Limit area for interpolation.

    Notes
    -----
    Modifies values in-place.
    r�r�Nrr�)rIr�r�r�Fr�r�z*limit_area should be 'inside' or 'outside')rr�r�r%�pad_or_backfill_inplacer&r2r�)rerIr�r�r�r}r�r�s        r(�_interpolate_with_limit_arear%s���2�6�l�l�G��x�H��;�;�=�=�!� �W�x�@�@�@���=��E��F�X�>�>�>���<��v�;�;�D�����!�		
�	
�	
�	
���!�!�(-�G�E�D�1�H�$�%�%�
�9�
$�
$�49�9�G�F�U�F�O�g�d�Q�h�j�j�1�1��I�J�J�J��&��w����-!�!r*rYc�$�|dkrd�nd�}|jdkr?|dkrtd���|�td|jz����}t|��}||��}t
|d���}||||�	��d
S)a
    Perform an actual interpolation of values, values will be make 2-d if
    needed fills inplace, returns the result.

    Parameters
    ----------
    values: np.ndarray
        Input array.
    method: str, default "pad"
        Interpolation method. Could be "bfill" or "pad"
    axis: 0 or 1
        Interpolation axis
    limit: int, optional
        Index limit on interpolation.
    limit_area: str, optional
        Limit area for interpolation. Can be "inside" or "outside"

    Notes
    -----
    Modifies values in-place.
    rc��|SrNrO�rDs r(�<lambda>z)pad_or_backfill_inplace.<locals>.<lambda>vs���r*c��|jSrN)�Trs r(rz)pad_or_backfill_inplace.<locals>.<lambda>vs����r*r�z0cannot interpolate on a ndim == 1 with axis != 0�r�r�)r�)r�r�N)r��AssertionErrorr��tupler8rQ�
get_fill_func)rerIr�r�r��transf�tvaluesr�s        r(rrZs���8#�a�i�i�k�k�k�m�m�F��{�a����1�9�9� �!S�T�T�T�����d�V�\�&9� :� :�;�;��
�v�
&�
&�F��f�V�n�n�G���a�(�(�(�D��D���*�5�5�5�5�5�5r*�npt.NDArray[np.bool_] | Nonec�(�|�t|��}|SrN)r)rer s  r(�_fillna_prepr�s��
�|��F�|�|���Kr*r�rc�l��t���			dd�fd�
��}tt|��S)	z>
    Wrapper to handle datetime64 and timedelta64 dtypes.
    Nr�r~r�r�c����t|j��rR|�t|��}�|�d��|||���\}}|�|j��|fS�||||���S)Nr�)r�r�r )rr.rr�)rer�r�r �resultr�s     �r(�new_funcz&_datetimelike_compat.<locals>.new_func�s�����v�|�,�,�	3��|��F�|�|���4����D�!�!��:�D����L�F�D��;�;�v�|�,�,�d�2�2��t�F�%�J�T�J�J�J�Jr*�NNN)r�r~r�r�)rrr)r�rs` r(�_datetimelike_compatr!�s\���
�4�[�[�!�:>�
�	K�K�K�K�K�K��[�K�$��8���r*�(tuple[np.ndarray, npt.NDArray[np.bool_]]c��t||��}|�$|���st||��tj|||���||fS�N)r�)rr��_fill_limit_area_1dr�pad_inplace�rer�r�r s    r(�_pad_1dr(�sX�����%�%�D���d�h�h�j�j���D�*�-�-�-�	��f�d�%�0�0�0�0��4�<�r*c��t||��}|�$|���st||��tj|||���||fSr$)rr�r%r�backfill_inplacer's    r(�_backfill_1dr+�sX�����%�%�D���d�h�h�j�j���D�*�-�-�-�	��6�4�u�5�5�5�5��4�<�r*c��t||��}|�t||��|jrtj|||���n	||fSr$)r�_fill_limit_area_2d�sizer�pad_2d_inplacer's    r(�_pad_2dr0�s]�����%�%�D����D�*�-�-�-�
�{�
�
��V�T��7�7�7�7�7�	
��4�<�r*c��t||��}|�t||��|jrtj|||���n	||fSr$)rr-r.r�backfill_2d_inplacer's    r(�_backfill_2dr3�s]�����%�%�D����D�*�-�-�-�
�{�
�
�!�&�$�e�<�<�<�<�<�	
��4�<�r*�Literal['outside', 'inside']c���|}|���}t|��|ddd����z
dz
}|dkrd|d|�<d||dzd�<dS|dkrd||dz|�<dSdS)a�Prepare 1d mask for ffill/bfill with limit_area.

    Caller is responsible for checking at least one value of mask is False.
    When called, mask will no longer faithfully represent when
    the corresponding are NA or not.

    Parameters
    ----------
    mask : np.ndarray[bool, ndim=1]
        Mask representing NA values when filling.
    limit_area : { "outside", "inside" }
        Whether to limit filling to outside or inside the outer most non-NA value.
    Nr�r�r�Fr�)r�r%)r r��neg_maskr�r�s     r(r%r%�s��� �u�H��O�O���E��x�=�=�8�D�D�b�D�>�0�0�2�2�2�Q�6�D��X�����V�e�V�� ��T�A�X�Z�Z����	�y�	 �	 �!&��U�Q�Y��
����
!�	 r*c��|j}|dkrVtj�|d���tj�|ddd�d���ddd�z}nWtj�|d���tj�|ddd�d���ddd�z}d||j<dS)a�Prepare 2d mask for ffill/bfill with limit_area.

    When called, mask will no longer faithfully represent when
    the corresponding are NA or not.

    Parameters
    ----------
    mask : np.ndarray[bool, ndim=1]
        Mask representing NA values when filling.
    limit_area : { "outside", "inside" }
        Whether to limit filling to outside or inside the outer most non-NA value.
    r�rr�Nr�F)rr2�maximum�
accumulate)r r�r6�la_masks    r(r-r-s�����w�H��Y���
�J�!�!�(��!�3�3��j�#�#�H�T�T�r�T�N��#�;�;�D�D�b�D�A�
B�	���Z�
"�
"�8�!�
"�
4�
4�4��z�$�$�X�d�d��d�^�!�$�<�<�T�T�r�T�B�B�
C�	��D���O�O�Or*�rYr[r�r�c�p�t|��}|dkr
t|Sttd�|S)Nr�r;)rQ�
_fill_methodsr0r3)rIr�s  r(rr*s6��
�v�
&�
&�F��q�y�y��V�$�$���5�5�f�=�=r*�ReindexMethod | Nonec�,�|�dSt|d���S)NTrG)rQ)rIs r(�clean_reindex_fill_methodr@1s��
�~��t��V�4�8�8�8�8r*r��fw_limit�bw_limitc���t|���t��}t��}d�fd�}|�:|dkr(ttj|��d��}n|||��}|�Y|dkr|St	||ddd�|����}t�dz
tj|��z
��}|dkr|S||zS)	ak
    Get indexers of values that won't be filled
    because they exceed the limits.

    Parameters
    ----------
    invalid : np.ndarray[bool]
    fw_limit : int or None
        forward limit to index
    bw_limit : int or None
        backward limit to index

    Returns
    -------
    set of indexers

    Notes
    -----
    This is equivalent to the more readable, but slower

    .. code-block:: python

        def _interp_limit(invalid, fw_limit, bw_limit):
            for x in np.where(invalid)[0]:
                if invalid[max(0, x - fw_limit):x + bw_limit + 1].all():
                    yield x
    r�r#c	�\��t|���}t||dz���d��}tt	j|��d|z��tt	j|d|dz����dk��d��z}|S)Nr�r)�min�_rolling_windowr�r�r2�where�cumsum)r�r��windowed�idx�Ns    �r(�innerz_interp_limit.<locals>.inner\s�����E�1�
�
��"�7�E�A�I�6�6�:�:�1�=�=���"�(�8�$�$�Q�'�%�/�0�0�3��H�w�{����{�+�+�3�3�5�5��:�;�;�A�>�4
�4
�
���
r*Nrr�r�)r�r#)r%r�r2rG�listr�)r�rArB�f_idx�b_idxrL�	b_idx_invrKs       @r(r�r�7s����B	�G���A��E�E�E��E�E�E����������q�=�=�����)�)�!�,�-�-�E�E��E�'�8�,�,�E����q�=�=��L��U�U�7�4�4�R�4�=�(�;�;�<�<�I���A���
�9� 5� 5�5�6�6�E��1�}�}����5�=�r*�a�windowc���|jdd�|jd|z
dz|fz}|j|jdfz}tjj�|||���S)z�
    [True, True, False, True, False], 2 ->

    [
        [True,  True],
        [True, False],
        [False, True],
        [True, False],
    ]
    Nr�r�)r8�strides)r8rTr2r�
stride_tricks�
as_strided)rQrRr8rTs    r(rFrFxsb��
�G�C�R�C�L�A�G�B�K�&�0�1�4�f�=�=�E��i�1�9�R�=�*�*�G�
�6��*�*�1�E�7�*�K�K�Kr*)r r!r"r#)r+r
r,r!)rIrJrHrKr,rL)rIrSrHrTr,rU)rIrSrHr9r,rU)rIr]rdrr,r])r|r]r}r!r,r~)r�r]r,r�)r�r�r,r�)r�r�rIr]r,r�)rdrr,r)rbNr�NNN)r�r�rdrr�rrIr]r�r~r�r]r�r�r�r�r,r�)rdrrIr]r,r�)rbNr�NNFNN)r�r�r�r�rIr]r�r~r�r]r�r�r�r�r�r9rtr~r,r�)NFN)
rDr�r�r�r�r�rIr]r�r9)NrF)
r�r�r�r�rDr�r�r�r�r9)rr)
r�r�r�r�rDr�r�r�r�r)rrN)
r�r�r�r�rDr�r�rrr)
rer�rIrLr�r~r�r	r,r�)rYrNN)rer�rIrLr�rr�r~r�r�r,r�rN)r rr,r!)r�rr,rr )
rer�r�r~r�r�r rr,r")rer�r�r~r�r�r r)r�r~r�r�r r)r r!r�r4r,r�r)r�r#)r,r>)r�r!rAr~rBr~)rQr!rRr#r,r!)K�__doc__�
__future__r�	functoolsr�typingrrrrr	�numpyr2�pandas._libsr
rr�pandas._typingr
rrrr�pandas.compat._optionalr�pandas.core.dtypes.castr�pandas.core.dtypes.commonrrrrrr�pandas.core.dtypes.dtypesr�pandas.core.dtypes.missingrrrr�rr)rFrQrvrwr{r�r�r�r�r�r�r�r�r�r�r�r�rrrr!r(r+r0r3r%r-r=rr@r�rFrOr*r(�<module>rcs�����#�"�"�"�"�"�����������������������������������
��������������?�>�>�>�>�>�4�4�4�4�4�4�����������������6�5�5�5�5�5�����������������������F�F�F�F�R
�%(������
���
����
��� �������43�
2�
2�
����
�$����&#�#�#�#�L������������*����F��$�!�!�	
�C*�C*�C*�C*�C*�L����2��$�6:�!���	
�o�o�o�o�o�n��
�D�D�D�D�D�V�"#��
/�/�/�/�/�l#$��.�.�.�.�.�j�%1��
S�S�S�S�S�l2!�2!�2!�2!�n*/���6:�)6�)6�)6�)6�)6�Z26����������6��6:�)-�	
�
�
�
���
���6:�)-�	
�
�
�
���
���6:�)-�	�������$��6:�)-�	�������$'�'�'�'�4����> �\�:�:�
�>�>�>�>�>�9�9�9�9�>�>�>�>�BL�L�L�L�L�Lr*