
    .i                    *   U d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 ddlZddlmZ ddlmZmZmZ ddlmZmZmZmZmZ dd	lmZ dd
lmZ ddlmZmZm Z m!Z!m"Z" ddl#m$Z$m%Z%m&Z& ddl'm(Z(m)Z)m*Z* erddl+m,Z, ddlm-Z- ddl.m/Z/ ed   Z0de1d<   d8dZ2d9dZ3e
dd	 	 	 	 	 d:d       Z4e
	 	 	 	 	 	 d;d       Z4dd	 	 	 	 	 d<dZ4g dZ5g dZ6d=dZ7d>dZ8	 	 	 	 d?d Z9d@d!Z:	 	 	 	 	 	 dAd"Z;dBd#Z<	 	 	 	 	 	 dC	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dDd$Z=dEd%Z>	 	 	 	 	 	 	 	 dF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dGd&Z?	 	 	 dH	 	 	 	 	 	 	 	 	 dId'Z@	 	 	 dJ	 	 	 	 	 	 	 	 	 dKd(ZA	 	 dL	 	 	 	 	 	 	 	 	 dMd)ZB	 	 	 dN	 	 	 	 	 	 	 	 	 	 	 	 	 dOd*ZC	 	 	 	 dP	 	 	 	 	 	 	 	 	 	 	 dQd+ZD	 dR	 	 	 dSd,ZEdTd-ZFeF	 	 	 dU	 	 	 	 	 	 	 	 	 dVd.       ZGeF	 	 	 dU	 	 	 	 	 	 	 	 	 dVd/       ZHeF	 	 	 dU	 	 	 	 	 	 	 	 	 dVd0       ZIeF	 	 	 dU	 	 	 	 	 dWd1       ZJ	 	 	 	 	 	 dXd2ZK	 	 	 	 	 	 dXd3ZLeGeHd4ZMdYdZd5ZNd[d6ZO	 	 	 	 	 	 	 	 d\d7ZPy)]z$
Routines for filling missing data.
    )annotations)wraps)TYPE_CHECKINGAnyLiteralcastoverloadN)	is_nan_na)NaTalgoslib)	ArrayLikeAxisIntFReindexMethodnpt)import_optional_dependency)infer_dtype_from)is_array_likeis_bool_dtypeis_numeric_dtypeis_object_dtypeneeds_i8_conversion)
ArrowDtypeBaseMaskedDtypeDatetimeTZDtype)is_valid_na_for_dtypeisnana_value_for_dtype)Callable)	TypeAlias)Index)
not-a-knotclampednaturalperiodicr!   _CubicBCc                v    t        |       r-t        |       |k7  rt        dt        |        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)valuemasklengths      Q/var/www/app/trading-bot/venv/lib/python3.12/site-packages/pandas/core/missing.pycheck_value_sizer/   >   sP     Uu:9#e* F#H&  dL    c                   t        |      \  }}t        | j                  t        t        f      rt        j                  |      rt        j                  |      rt               s| j                  j                  dk(  rt        | j                  t              r3t        j                  | j                        | j                          z  }|S ddlm} |j                  | j                         j#                  d      j%                         }|S | j                  j                  dv r't        j&                  | j(                  t*              }|S t        |      rt        |       S t        j&                  | j(                  t*              }t-        | j                        r-t/        | j                        st        j0                  |      r	 |S t/        | j                        r#t-        |      rt        j0                  |      s	 |S t-        | j                        rt        |t2              r	 |S t5        | j                        rt        |        }| |   |k(  ||<   |S | |k(  }t        |t        j6                        s|j%                  t*        d      }|}|S )a?  
    Return a masking array of same size/shape as arr
    with entries equaling value set to True.

    Parameters
    ----------
    arr : ArrayLike
    value : scalar-like
        Caller has ensured `not is_list_like(value)` and that it can be held
        by `arr`.

    Returns
    -------
    np.ndarray[bool]
    fr   NFiudtype)r5   na_value)r   
isinstancer5   r   r   r   is_floatnpisnanr
   kind_datar   pyarrow.computecomputeis_nan	_pa_array	fill_nullto_numpyzerosshapeboolr   r   is_boolstrr   ndarray)arrr+   r5   r,   pcarr_masknew_masks          r.   mask_missingrM   M   s     $E*LE5 	399
;<LLHHUO 99>>S #))_5xx		*chhj[8 -yy/99%@IIKYY^^t#88CIIT2DKE{Cy 88CIIT*D#cii(KK 	, K) 	cii %5e%<S[[QVEW 	" K! 
#))	$E3)? K 
	# I:X%/X K %<(BJJ/((te(DHKr0   .allow_nearestc                    y N methodrO   s     r.   clean_fill_methodrU      s    
 "%r0   c                    y rQ   rR   rS   s     r.   rU   rU      s    
 -0r0   Fc                   t        | t              r| j                         } | dk(  rd} n| dk(  rd} ddg}d}|r|j                  d       d}| |vrt	        d| d	|        | S )
Nffillpadbfillbackfillzpad (ffill) or backfill (bfill)nearestz(pad (ffill), backfill (bfill) or nearestzInvalid fill method. Expecting z. Got )r7   rG   lowerappendr*   )rT   rO   valid_methods	expectings       r.   rU   rU      s    
 &# WFwFJ'M1IY'>	]":9+VF8TUUMr0   )lineartimeindexvalues)r\   zeroslinear	quadraticcubicbarycentrickroghspline
polynomialfrom_derivativespiecewise_polynomialpchipakimacubicsplinec                    |j                  d      }| dv r|t        d      t        t        z   }| |vrt        d| d|  d      | dv r|j                  st        |  d      | S )	Norder)rk   rl   z7You must specify the order of the spline or polynomial.zmethod must be one of z. Got 'z
' instead.)rj   rn   ro   z4 interpolation requires that the index be monotonic.)getr*   
NP_METHODS
SP_METHODSis_monotonic_increasing)rT   rc   kwargsrs   valids        r.   clean_interp_methodrz      s    JJwE))emRSS#EU1%xzRSS;;,,(NO  Mr0   c                   | dv sJ t        |      dk(  ry|j                  dk(  r|j                  d      }| dk(  r|dd j                         }n*| dk(  r%t        |      dz
  |ddd	   j                         z
  }|   }|sy|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lastr   N      axisr|   r}   )r)   ndimanyargmax)howis_valididxpos	chk_notnas       r.   find_valid_indexr      s     ####
8}}}<<Q<'
g~"$$&	X"Xdd^%:%:%<< I Mr0   c                Z    g d}| j                         } | |vrt        d| d|  d      | S )N)forwardbackwardbothz*Invalid limit_direction: expecting one of z, got 'z'.r]   r*   )limit_directionvalid_limit_directionss     r.   validate_limit_directionr     sN     =%++-O448%&go->bB
 	
 r0   c                ^    | *ddg}| j                         } | |vrt        d| d|  d      | S )Ninsideoutsidez%Invalid limit_area: expecting one of z, got .r   )
limit_areavalid_limit_areass     r.   validate_limit_arear   %  sV    %y1%%'
..78I7J&,a!  r0   c                    | |dv rd} | S d} | S |dv r| dk7  rt        d| d      |dv r| dk7  rt        d| d      | S )N)r[   rZ   r   r   )rY   rX   z0`limit_direction` must be 'forward' for method ``z1`limit_direction` must be 'backward' for method `)r*   )r   rT   s     r.   infer_limit_directionr   3  s     **(O  (O  %%/Y*FB6(!L  ***/LCF81M  r0   c                   | dk(  rddl m}  |t        |            }nh d}t        |j                        xs< t        |j                  t              xs  t        j                  |j                  d      }t        t        z   }| |v r| |vr |st        d|  d      t        d|  d	      t        |      j                         rt        d
      |S )Nra   r   )
RangeIndex>   rb   rc   rd   r\   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. Can not interpolate with method=r   zkInterpolation with NaNs in the index has not been implemented. Try filling those NaNs before interpolating.)pandasr   r)   r   r5   r7   r   r   is_np_dtyperu   rv   r*   r   r   NotImplementedError)rT   rc   r   methodsis_numeric_or_datetimery   s         r.   get_interp_indexr   H  s    %3u:&8U[[) 2%++72u{{D1 	
 Z'U?W$-C #H %%%  ?xqIJJE{!/
 	

 Lr0   c	           	       	 t        |fi 	 t        | j                        rt        | j                  d      dk(  r"t	        |j                        st        d      dt              t        |      t        j                  d      t        |      d		fd}
t        j                  |
||        y)
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)compatrb   zStime-weighted interpolation only works on Series or DataFrames with a DatetimeIndexrd   N)nobslimitc                0    t        d| dd	 y )NF)	indicesyvaluesrT   r   r   r   
fill_valuebounds_errorr,   rR   )_interpolate_1d)	r   r   r   rx   r   limit_area_validatedr   r,   rT   s	    r.   funcz$interpolate_2d_inplace.<locals>.func  s7     	 	
++!	
 	
r0   )r   
np.ndarrayreturnNone)rz   r   r5   r   r   r*   r   r   r   validate_limit_index_to_interp_indicesr9   apply_along_axis)datarc   r   rT   r   r   r   r   r,   rx   r   r   r   s      ``` ``` @@r.   interpolate_2d_inplacer   k  s    . 00Z4'

5A
"5;;/  
 .?O.z:   d%8E&uf5G
 
  dD)r0   c                F   | j                   }t        |j                        r|j                  d      }|dk(  r|}t	        t
        j                  |      }|S t        j                  |      }|dv r2|j                  t
        j                  k(  rt        j                  |      }|S )zE
    Convert Index to ndarray of indices to pass to NumPy/SciPy.
    i8ra   )rd   rc   )_valuesr   r5   viewr   r9   rH   asarrayobject_r   maybe_convert_objects)rc   rT   xarrindss       r.   r   r     s     ==D4::&yyBJJ% K zz$((zzRZZ'006Kr0   c
                   |	|	}nt        |      }| }|j                         sy|j                         ryt        j                  |      }t        d|      }|d}t        j                  |      }t        d|      }|t        |      }t        j                  d|z   t        |            }|dk(  r"t        j                  |t        ||d            }nG|dk(  r"t        j                  |t        |d|            }n t        j                  t        |||            }|d	k(  r-t        j                  ||      }t        j                  ||      }nK|d
k(  rFt        j                  ||d      }t        j                  ||d      }t        j                  ||      }|j                  j                  dv }|r|j                  d      }|t        v rBt        j                   | |         }t        j"                  | |   | |   |   ||   |         ||<   nt%        | |   ||   | |   f||||d|
||<   |	d|	dd d|	|<   y|rt&        j(                  ||<   yt        j*                  ||<   y)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   r   r}   r   r   r   r   r   Tassume_uniquer   r   )rT   r   r   rs   F)r   r   allr9   flatnonzeror   aranger)   union1d_interp_limitunique	setdiff1dr5   r;   r   ru   argsortinterp_interpolate_scipy_wrapperr   r+   nan)r   r   rT   r   r   r   r   r   rs   r,   rx   invalidry   all_nansfirst_valid_index
start_nanslast_valid_indexend_nanspreserve_nansmid_nansis_datetimelikeindexers                         r.   r   r     sj   0 w-HE99;yy{ ~~g&H(WuE ,-J'FUCw<yy--s5z:H )#

:}WeQ/OP	J	&

8]7Au-MN 		-"FG X

=*=

=(;	y	 <<*DI<<($G

=(;mm((D0O,,t$ **WU^,99GgenW5wu~g7N
 6ENENG	
 !%	
 	
 Q"]
 	 
!$  "$
r0   c                   | d}t        d|       ddlm}	 t        j                  |      }|	j
                  |	j                  t        t        t        t        |	j                  d}
g d}||v r*|dk(  r|}n|}|	j                  | ||||	      } ||      }|S |d
k(  r>t        |      s|dk  rt        d|        |	j                  | |fd|i|} ||      }|S | j                  j                   s| j#                         } |j                  j                   s|j#                         }|j                  j                   s|j#                         }|
j%                  |d      }|t        d| d      |j'                  dd        || ||fi |}|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)ri   rj   rm   rn   rq   rp   ro   )r\   re   rf   rg   rh   rl   rl   )r;   r   r   rk   z;order needs to be specified and greater than 0; got order: kNr   r   downcast)r   r   r   r9   r   barycentric_interpolatekrogh_interpolate_from_derivatives_cubicspline_interpolate_akima_interpolatepchip_interpolateinterp1dr   r*   UnivariateSplineflags	writeablecopyrt   pop)xynew_xrT   r   r   rs   rx   r   r   alt_methodsinterp1d_methodsr;   terpnew_ys                  r.   r   r   1  s    h45Ewe4!JJuE #::..- 1/#..9K !!\!DD##qt
 $ 
 U2 L1 
8	;5A:MeWU  ,{++AqDEDVDU" L ww  Aww  A{{$$JJLEvt,<?xqIJJ 	

:t$Q5+F+Lr0   c                    ddl m} |j                  j                  } || |j	                  dd      ||      } ||      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.
    r   r   r   r   )ordersextrapolate)r   r   BPolyrm   reshape)	xiyir   rs   derr   r   rT   ms	            r.   r   r   ~  s?    R " //Fr2::b!$ULAQ4Kr0   c                J    ddl m} |j                  | ||      } |||      S )a  
    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. 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,

    r   r   r   )nu)r   r   Akima1DInterpolator)r   r   r   r   r   r   Ps          r.   r   r     s+    P "''BT':AQ3<r0   c                J    ddl m} |j                  | ||||      } ||      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.
    r   r   )r   bc_typer   )r   r   CubicSpline)r   r   r   r   r  r   r   r  s           r.   r   r     s3    Z "
BT7 	  	A Q4Kr0   c                    |dk(  rd nd }| j                   dk(  r/|dk7  rt        d      | j                  dg| j                        } t	        |      } ||       }t        |d      } ||||       y	)
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.
    r   c                    | S rQ   rR   r   s    r.   <lambda>z)pad_or_backfill_inplace.<locals>.<lambda>Q  s     r0   c                    | j                   S rQ   )Tr  s    r.   r	  z)pad_or_backfill_inplace.<locals>.<lambda>Q  s
     r0   r   z1cannot interpolate on an ndim == 1 with axis != 0r~   )r   )r   r   N)r   AssertionErrorr   rD   rU   get_fill_func)rd   rT   r   r   r   transftvaluesr   s           r.   pad_or_backfill_inplacer  5  sw    8 #aikmF {{a19 !TUU 2V\\ 23v&FVnGa(D*5r0   c                     |t        |       }|S rQ   )r   )rd   r,   s     r.   _fillna_prepr  a  s    
 |F|Kr0   c                Z     t               	 	 	 d	 	 	 d fd       }t        t        |      S )z>
    Wrapper to handle datetime64 and timedelta64 dtypes.
    c                    t        | j                        rH|t        |       } | j                  d      |||      \  }}|j                  | j                        |fS  | |||      S )Nr   )r   r   r,   )r   r5   r   r   )rd   r   r   r,   resultr   s        r.   new_funcz&_datetimelike_compat.<locals>.new_funcq  sj     v||,|F|D!:DLFD ;;v||,d22F%JTJJr0   NNN)r   
int | Noner   #Literal['inside', 'outside'] | None)r   r   r   )r   r  s   ` r.   _datetimelike_compatr  l  sK    
 4[ !:>	KK 8K K$ 8r0   c                    t        | |      }||j                         st        ||       t        j                  | ||       | |fS N)r   )r  r   _fill_limit_area_1dr   pad_inplacerd   r   r   r,   s       r.   _pad_1dr     sD     %DdhhjD*-	fd%04<r0   c                    t        | |      }||j                         st        ||       t        j                  | ||       | |fS r  )r  r   r  r   backfill_inplacer  s       r.   _backfill_1dr#    sD     %DdhhjD*-	64u54<r0   c                    t        | |      }|t        ||       | j                  rt        j                  | ||       | |fS r  )r  _fill_limit_area_2dsizer   pad_2d_inplacer  s       r.   _pad_2dr(    sC     %DD*-{{VT74<r0   c                    t        | |      }|t        ||       | j                  rt        j                  | ||       | |fS 	 | |fS r  )r  r%  r&  r   backfill_2d_inplacer  s       r.   _backfill_2dr+    sT     %DD*-{{!!&$e< 4< 	4<r0   c                    |  }|j                         }t        |      |ddd   j                         z
  dz
  }|dk(  rd| d| d| |dz   d y|dk(  r	d| |dz   | yy)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{      uHOOEx=8DbD>0022Q6DXVe TAXZ	y	 !&UQY 
!r0   c                   | j                    }|dk(  rPt        j                  j                  |d      t        j                  j                  |ddd   d      ddd   z  }nQt        j                  j                  |d       t        j                  j                  |ddd   d      ddd    z  }d| |j                   <   y)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   r   r   Nr   F)r  r9   maximum
accumulate)r,   r   r-  la_masks       r.   r%  r%    s     wHY JJ!!(!3jj##HTrTN#;DbDAB 	 ZZ""8!"44zz$$Xdd^!$<TrTBBC 	 DOr0   rY   r[   c                T    t        |       } |dk(  r	t        |    S t        t        d|    S )Nr   r2  )rU   _fill_methodsr(  r+  )rT   r   s     r.   r  r    s.    v&FqyV$$5f==r0   c                "    | y t        | d      S )NTrN   )rU   )rT   s    r.   clean_reindex_fill_methodr6  	  s    ~V488r0   c                   t        |       t        j                  g t        j                        }t        j                  g t        j                        }d}d
fd}|)|dk(  rt        j                  |       d   }d}n	 || |      }|#|dk(  r|S dz
   || ddd   |      z
  }|dk(  r|S t        j
                  |||	      S )am  
    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
    r4   Tc           	     R   t        |      }t        j                  j                  j	                  | |dz         j                  d      }t        j                  t        j                  |      d   |z   t        j                  | d |dz     j                         dk(        d         }|S )Nr   r   )	minr9   r   stride_trickssliding_window_viewr   r   wherecumsum)r   r   windowedidxNs       r.   innerz_interp_limit.<locals>.inner5  s    E166'';;GUQYOSSTUVjjHHXq!E)HHw{++335:;A>
 
r0   Nr   Fr   r   r   )r   int)r)   r9   arrayint64r<  intersect1d)r   fw_limitbw_limitf_idxb_idxr   rA  r@  s          @r.   r   r     s    B 	GAHHRrxx(EHHRrxx(EM q=HHW%a(E!M'8,Eq= LEE'$B$-::E1}>>%mDDr0   )r,   npt.NDArray[np.bool_]r-   rB  )rI   r   r   rJ  )rT   z,Literal['ffill', 'pad', 'bfill', 'backfill']rO   zLiteral[False]r   Literal['pad', 'backfill'])rT   7Literal['ffill', 'pad', 'bfill', 'backfill', 'nearest']rO   zLiteral[True]r   %Literal['pad', 'backfill', 'nearest'])rT   rL  rO   rE   r   rM  )rT   rG   rc   r"   r   rG   )r   rG   r   rJ  r   r  )r   rG   r   z&Literal['forward', 'backward', 'both'])r   
str | Noner   r  )r   z-Literal['backward', 'forward', 'both'] | NonerT   rG   r   z&Literal['backward', 'forward', 'both'])rc   r"   r   r"   )ra   Nr   NNN)r   r   rc   r"   r   r   rT   rG   r   r  r   rG   r   rN  r   
Any | Noner   r   )rc   r"   rT   rG   r   r   )ra   Nr   NNFNN)r   r   r   r   rT   rG   r   r  r   rG   r   r  r   rO  r   rE   rs   r  r   r   )NFN)
r   r   r   r   r   r   rT   rG   r   rE   )Nr   F)
r   r   r   r   r   r   r   zint | list[int] | Noner   rE   )r   r   )
r   r   r   r   r   r   r   rB  r   r   )r   r#   N)r   r   r   r   r   r   r   r   r  z_CubicBC | tuple[Any, Any]r   z!Literal['periodic'] | bool | Noner   r   )rY   r   NN)rd   r   rT   rK  r   r   r   r  r   r  r   r   rQ   )r,   npt.NDArray[np.bool_] | Noner   rJ  )r   r   r   r   r  )
rd   r   r   r  r   r  r,   rP  r   z(tuple[np.ndarray, npt.NDArray[np.bool_]])r   r  r   r  r,   rP  )r,   rJ  r   zLiteral['outside', 'inside']r   r   )r   )r   rB  )r   zReindexMethod | None)r   rJ  rF  r  rG  r  r   r   )Q__doc__
__future__r   	functoolsr   typingr   r   r   r   r	   numpyr9   pandas._configr
   pandas._libsr   r   r   pandas._typingr   r   r   r   r   pandas.compat._optionalr   pandas.core.dtypes.castr   pandas.core.dtypes.commonr   r   r   r   r   pandas.core.dtypes.dtypesr   r   r   pandas.core.dtypes.missingr   r   r   collections.abcr    r!   r   r"   r'   __annotations__r/   rM   rU   ru   rv   rz   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r#  r(  r+  r  r%  r4  r  r6  r   rR   r0   r.   <module>r`     s   #    $ 
  ? 4  
  ( !"PQHiQL^ 
 %(%8% "%  	% 
% 
0C0 !0 +	0 
0  C  +	4 3

$&$N+BLO+* N $!!	=*
=*=* =* 	=*
 =* =* =* =* 
=*@2 $6:!	mmm m 	m
 m 4m m m m 
mj 
JJJ J 	J Jb "#/// /
 
 / /l ,,, , 
	,
 ,f *659SSS S 	S
 (S 3S Sp */6:)6)6&)6 )6 	)6
 4)6 
)6Z 26.6  6:)-	


 4
 '	

 .
 
  6:)-	


 4
 '	

 .
 
  6:)-	 4 '	
 .   6:)-	 4 '	 $'
'-I'	'4
-I	>  \:>9@E"@E.8@EDN@E@Er0   