
    n[we}                    t   d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
 ddl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" ddl#m$Z$m%Z%m&Z& erddl'm(Z( dldZ)dmdZ*dndodZ+g dZ,g dZ-dpd!Z.dqd%Z/drd(Z0dsd,Z1d- Z2dtd.Z3	 	 	 	 	 dudvd9Z4dwd:Z5	 	 	 	 	 	 	 dxdyd?Z6	 	 	 dzd{dCZ7	 	 	 d|d}dIZ8	 	 d~ddJZ9	 	 	 dddNZ:ddRZ;	 	 	 	 dddTZ<	 dddVZ=ddYZ>e>	 	 ddd[            Z?e>	 	 ddd\            Z@e>	 	 ddd]            ZAe>	 ddd^            ZBe?e@d_ZCdddbZDdddZEddhZFddkZGdS )z$
Routines for filling missing data.
    )annotations)partialwraps)TYPE_CHECKINGAnyLiteralcastN)NaTalgoslib)	ArrayLikeAxisIntFReindexMethodnpt)import_optional_dependency)infer_dtype_from)is_array_like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          |           |k    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)valuer   r!   s      3lib/python3.11/site-packages/pandas/core/missing.pycheck_value_sizer(   4   sk     U u::&#e** & &#& &   dL    arrr   returnc                :   t          |          \  }}t          |t          j                  rt          j        ||          }nC|                                }t          j        |          s|g}|                    ||d          }d}t          | j                  rd}t          |            }t          |          }||          }t          j        | j        t                    }|D ]}	t          | |	          r|r5t          j        | j        t          j                  }
| |         |	k    |
|<   n<| |	k    }
t          |
t          j                  s|
                    t          d          }
||
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_sequencer   r   zerosshapeboolr   bool_ndarrayto_numpyany)r*   values_to_maskr-   clspotential_naarr_maskna_masknonnar   xnew_masks              r'   mask_missingrE   C   s   " -^<<E>%"" U.>>>((**// 	.,-N++N%e+TTLsy!! II:>""GG8$E 8CIT***D  #C++ 	 M8CIRX>>>%(]a%7""!8!(BJ77 M'00te0LLHHDD{{}} S		Kr)   Fmethodstrallow_nearestr8   c                    t          | t                    r%|                                 } | dk    rd} n| dk    rd} ddg}d}|r|                    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 )r0   rG   lowerappendr%   )rF   rH   valid_methods	expectings       r'   clean_fill_methodrS      s    &#  WFFwFJ'M1I ?Y'''>	]""T9TTFTTUUUMr)   )lineartimeindexvalues)rN   zeroslinear	quadraticcubicbarycentrickroghspline
polynomialfrom_derivativespiecewise_polynomialpchipakimacubicsplinerV   r   c                    |                     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)r^   r_   z7You must specify the order of the spline or polynomial.zmethod must be one of z. Got 'z
' instead.)r]   ra   rb   z4 interpolation requires that the index be monotonic.)getr%   
NP_METHODS
SP_METHODSis_monotonic_increasing)rF   rV   kwargsrf   valids        r'   clean_interp_methodrm      s    JJwE)))em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   | dv sJ t          |          dk    rdS |j        dk    r|                    d          }| dk    r|dd                                         }n6| dk    r0t          |          dz
  |ddd	                                         z
  }||         }|sdS |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      axisrr   rs   )r$   ndimr<   argmax)rn   ro   idxpos	chk_notnas       r'   find_valid_indexr}      s     #####
8}}t}<<Q<''
g~~"""$$&&	X"Xddd^%:%:%<%<< I t Mr)   limit_direction&Literal['forward', 'backward', 'both']c                j    g d}|                                  } | |vrt          d| d|  d          | S )N)forwardbackwardbothz*Invalid limit_direction: expecting one of z, got 'z'.rO   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    | 2ddg}|                                  } | |vrt          d| 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)   c                    | 
|dv rd} n=d} n:|dv r| dk    rt          d| d          |dv r| dk    rt          d| d          | S )N)rM   rL   r   r   )rK   rJ   z0`limit_direction` must be 'forward' for method ``z1`limit_direction` must be 'backward' for method `)r%   )r~   rF   s     r'   infer_limit_directionr      s    ***(OO'OO%%%/Y*F*FL6LLL   ****/L/LMFMMM   r)   c                   | dk    r1ddl m}  |t          j        t	          |                              }neh d}t          |j                  p3t          |j        t                    pt          j
        |j        d          }| |vr|st          d|  d          t          |                                          rt          d          |S )	NrT   r   r   >   rU   rV   rW   rN   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.)pandasr   r1   aranger$   r   r-   r0   r   r   is_np_dtyper%   r   r<   NotImplementedError)rF   rV   r   methodsis_numeric_or_datetimes        r'   get_interp_indexr     s          biE

++,,888U[)) 2%+772u{D11 	
   )? !! ! !   E{{ 
!/
 
 	

 Lr)   rT   r   data
np.ndarrayrw   r   limit
fill_value
Any | NoneNonec                  
 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        |	||            dS )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)compatrU   zStime-weighted interpolation only works on Series or DataFrames with a DatetimeIndexrW   N)nobsr   yvaluesr   r+   r   c                2    t          d| dd d S )NF)indicesr   rF   r   r~   r   r   bounds_error )_interpolate_1d)r   r   r   rk   r   limit_area_validatedr~   rF   s    r'   funcz$interpolate_2d_inplace.<locals>.func]  sM     	 
	
++!
	
 
	
 
	
 
	
 
	
 
	
 
	
r)   )r   r   r+   r   )rm   r   r-   r   r   r%   r   r   r   validate_limit_index_to_interp_indicesr1   apply_along_axis)r   rV   rw   rF   r   r~   r   r   rk   r   r   r   s      ``` `` @@r'   interpolate_2d_inplacer   1  s!   , 00000Z44 B'
5AAA
"5;// 	   
 .??O.z::  d%888E&uf55G
 
 
 
 
 
 
 
 
 
 
 
* dD)))))r)   c                .   | j         }t          |j                  r|                    d          }|dk    r|}t	          t
          j        |          }nAt          j        |          }|dv r)|j        t
          j        k    rt          j
        |          }|S )zE
    Convert Index to ndarray of indices to pass to NumPy/SciPy.
    i8rT   )rW   rV   )_valuesr   r-   viewr	   r1   r:   asarrayobject_r   maybe_convert_objects)rV   rF   xarrindss       r'   r   r   u  s     =D4:&& yyBJ%%z$(((zRZ''066Kr)   r   r   r   rf   c	                   t          |          }
|
 }|                                sdS |                                rdS t          t	          j        |
                    }t          d|          }|d}t          t          |                    }t          d|          }|t          |          }t          t          d|z   t          |                              }|dk    r"|t          t          |
|d                    z  }nF|dk    r"|t          t          |
d|                    z  }nt          t          |
||                    }|d	k    r	|||z  z  }n|d
k    r||z
  |z
  }||z  }t          |          }|j        j        dv }|r|                    d          }|t          v rRt	          j        | |                   }t	          j        | |
         | |         |         ||         |                   ||
<   n)t#          | |         ||         | |
         f||||d|	||
<   |rt$          j        ||<   nt          j        ||<   dS )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.
    Nrr   rn   ro   r   rs   ru   r   r   r   r   r   r   )rF   r   r   rf   )r   r<   allsetr1   flatnonzeror}   ranger$   _interp_limitsortedr-   kindr   rh   argsortinterp_interpolate_scipy_wrapperr
   r&   nan)r   r   rF   r   r~   r   r   r   rf   rk   invalidrl   all_nansfirst_valid_index
start_nanslast_valid_indexend_nanspreserve_nansmid_nansis_datetimelikeindexers                        r'   r   r     s   0 7mmGHE99;; yy{{  2>'**++H(WuEEE U,--..J'FUCCCw<<5--s5zz::;;H )##"Swq)I)I%J%JJ	J	&	& 3}Wa'G'G#H#HH M'5%@@AA Xh..	y	 	 j(83! =))Mm(D0O %,,t$$ *WU^,,9GgenW5wu~g7N
 
 6ENENG	
 !%	
 	
 	
 	
  (!$!#
Fr)   rC   ynew_xc                   | d}t          d|           ddlm}	 t          j        |          }|	j        |	j        t          t          t          t          |	j
        d}
g d}||v r1|dk    r|}n|}|	                    | ||||	          } ||          }n|d
k    rDt          |          s|dk    rt          d|            |	j        | |fd|i|} ||          }ns| j        j        s|                                 } |j        j        s|                                }|j        j        s|                                }|
|         } || ||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)r\   r]   r`   ra   rd   rc   rb   )rN   rX   rY   rZ   r[   r_   r_   )r   r   r   r^   z;order needs to be specified and greater than 0; got order: k)r   r   r   r1   r   barycentric_interpolatekrogh_interpolate_from_derivatives_cubicspline_interpolate_akima_interpolatepchip_interpolateinterp1dr   r%   UnivariateSplineflags	writeabler.   )rC   r   r   rF   r   r   rf   rk   r   r   alt_methodsinterp1d_methodsr   terpnew_ys                  r'   r   r     s    555Ewe4444!!!!!!JuE #:.- 1/#. K   !!!\!!DDD##qt
 $ 
 
 U	8		;; 	5A::UeUU   ,{+AqDDEDVDDU w  	Aw  	A{$ 	!JJLLE6"Q5++F++Lr)   xiyiderint | list[int] | Noneextrapolatec                    ddl m} |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   rx   ru   )ordersr   )r   r   BPolyr`   reshape)	r   r   rC   rf   r   r   r   rF   ms	            r'   r   r   >  sW    R "!!!!! /Fr2::b!$$ULLLA1Q44Kr)   c                X    ddl m} |                    | ||          } |||          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,

    r   r   rv   )nu)r   r   Akima1DInterpolator)r   r   rC   r   rw   r   Ps          r'   r   r   p  sC    T "!!!!!''BT'::A1Q3<<<r)   
not-a-knotbc_typestr | tuple[Any, Any]c                X    ddl m} |                    | ||||          } ||          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   )rw   r   r   )r   r   CubicSpline)r   r   rC   rw   r   r   r   r   s           r'   r   r     sK    Z "!!!!!
BT7 	  	 	A 1Q44Kr)   rW   Literal['pad', 'backfill']Literal['inside', 'outside']c                v   t          |           }| }|                                st          d|          }|d}t          d|          }|t          |           }t	          | ||           |dk    rd|||d	z   <   n'|d
k    rdx|d|<   ||d	z   d<   nt          d          t          j        | |<   dS dS )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.
    rr   r   Nr   rs   )rF   r   r   Fru   r   z*limit_area should be 'inside' or 'outside')r   r   r}   r$   pad_or_backfill_inplacer%   r1   r   )rW   rF   r   r   r   ro   rr   rs   s           r'   _interpolate_with_limit_arear     s    2 6llGxH;;== ! Wx@@@=EFX>>><v;;D	
 	
 	
 	
 !!(-GED1H$%%9$$499GFUFOgdQhjj11IJJJ&w+! !r)   rK   c                   |.t          j        t          t          |||          ||            dS |dk    rd nd }| j        dk    r?|dk    rt          d          |                     t          d| j        z                       } 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.
    N)rF   r   r   r   c                    | S Nr   rC   s    r'   <lambda>z)pad_or_backfill_inplace.<locals>.<lambda>\  s     r)   c                    | j         S r  )Tr  s    r'   r  z)pad_or_backfill_inplace.<locals>.<lambda>\  s     r)   ru   z0cannot interpolate on a ndim == 1 with axis != 0ru   rt   )ry   r   )r1   r   r   r   ry   AssertionErrorr   tupler7   rS   get_fill_func)rW   rF   rw   r   r   transftvaluesr   s           r'   r   r   +  s    8 
 ,%	   !	
 	
 	
$ 	"aiikkkmmF {a199 !STTTdV\&9 : :;;v&&FfVnnGa(((DD
Fr)   npt.NDArray[np.bool_] | Nonec                f    |t          |           }|                    t          j                  }|S r  )r   r   r1   uint8)rW   r   s     r'   _fillna_prepr  m  s,    
 |F||99RXDKr)   r   r   c                f     t                     dd fd            }t          t          |          S )z>
    Wrapper to handle datetime64 and timedelta64 dtypes.
    Nr   rp   c                    t          | j                  rQ|t          |           } |                     d          ||          \  }}|                    | j                  |fS  | ||          S )Nr   )r   r   )r   r-   r   r   )rW   r   r   resultr   s       r'   new_funcz&_datetimelike_compat.<locals>.new_func~  s{    v|,, 	3|F||4D 1 1TJJJLFD;;v|,,d22tF%d3333r)   NN)r   rp   )r   r	   r   )r   r  s   ` r'   _datetimelike_compatr  y  sJ    
 4[[	4 	4 	4 	4 	4 	4 [	4 8r)   (tuple[np.ndarray, npt.NDArray[np.bool_]]c                X    t          | |          }t          j        | ||           | |fS Nr  )r  r   pad_inplacerW   r   r   s      r'   _pad_1dr    s5     %%D	fd%00004<r)   c                X    t          | |          }t          j        | ||           | |fS r  )r  r   backfill_inplacer  s      r'   _backfill_1dr    s5     %%D	64u55554<r)   c                j    t          | |          }| j        rt          j        | ||           n	 | |fS r  )r  sizer   pad_2d_inplacer  s      r'   _pad_2dr#    sG     %%D{ VT77777 	4<r)   c                j    t          | |          }| j        rt          j        | ||           n	 | |fS r  )r  r!  r   backfill_2d_inplacer  s      r'   _backfill_2dr&    sG     %%D{ !&$e<<<<< 	4<r)   rK   rM   ru   ry   c                p    t          |           } |dk    rt          |          S t          t          d|          S )Nru   r'  )rS   _fill_methodsr#  r&  )rF   ry   s     r'   r
  r
    s6    v&&FqyyV$$55f==r)   ReindexMethod | Nonec                ,    | d S t          | d          S )NT)rH   )rS   )rF   s    r'   clean_reindex_fill_methodr,    s    ~tV48888r)   r   fw_limitbw_limitc                   t          |           t                      }t                      }dfd}|:|dk    r(t          t          j        |           d                   }n || |          }|Y|dk    r|S t	           || ddd         |                    }t          dz
  t          j        |          z
            }|dk    r|S ||z  S )	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          | |dz                                 d          }t          t	          j        |          d         |z             t          t	          j        | d |dz                                             dk              d                   z  }|S )Nru   r   )min_rolling_windowr   r   r1   wherecumsum)r   r   windowedidxNs       r'   innerz_interp_limit.<locals>.inner  s    E1"7EAI66::1=="(8$$Q'%/003Hw{{++3355:;;A>4
 4
 
 
r)   Nr   rx   ru   )r   r"   )r$   r   r1   r3  listr   )r   r-  r.  f_idxb_idxr8  	b_idx_invr7  s          @r'   r   r     s    B 	GAEEEEEE      q==))!,--EEE'8,,Eq== LUU744R4=(;;<<IA
9 5 5566E1}}5=r)   awindowc                    | j         dd         | j         d         |z
  dz   |fz   }| j        | j        d         fz   }t          j        j                            | ||          S )z
    [True, True, False, True, False], 2 ->

    [
        [True,  True],
        [True, False],
        [False, True],
        [True, False],
    ]
    Nrx   ru   )r7   strides)r7   r@  r1   r   stride_tricks
as_strided)r=  r>  r7   r@  s       r'   r2  r2    sb     GCRCLAGBK&014f==Ei19R=**G6**1E7*KKKr)   )r   r    r!   r"   )r*   r   r+   r    )F)rF   rG   rH   r8   )rF   rG   rV   r   r+   rG   )rn   rG   ro   r    r+   rp   )r~   rG   r+   r   )r   r   r+   r   )rV   r   r+   r   )rT   Nr   NN)r   r   rV   r   rw   r   rF   rG   r   rp   r~   rG   r   r   r   r   r+   r   )rV   r   rF   rG   r+   r   )rT   Nr   NNFN)r   r   r   r   rF   rG   r   rp   r~   rG   r   r   r   r   r   r8   rf   rp   r+   r   )NFN)
rC   r   r   r   r   r   rF   rG   r   r8   )Nr   F)
r   r   r   r   rC   r   r   r   r   r8   )r   r   )
r   r   r   r   rC   r   r   r   rw   r   )r   r   N)
r   r   r   r   rC   r   rw   r   r   r   )
rW   r   rF   r   r   rp   r   r   r+   r   )rK   r   NN)rW   r   rF   r   rw   r   r   rp   r   r   r+   r   r  )r   r  r+   r    )r   r   r+   r   r  )rW   r   r   rp   r   r  r+   r  )rW   r   r   rp   r   r  )r   rp   r   r  r  )ry   r"   )r+   r*  )r   r    r-  rp   r.  rp   )r=  r    r>  r"   r+   r    )H__doc__
__future__r   	functoolsr   r   typingr   r   r   r	   numpyr1   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   pandas.core.dtypes.missingr   r   r   r   r   r(   rE   rS   rh   ri   rm   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r#  r&  r)  r
  r,  r   r2  r   r)   r'   <module>rO     s\    # " " " " "                               
              ? > > > > > 4 4 4 4 4 4              6 5 5 5 5 5              9 9 9 9x    ( 322
  
$   &# # # #L        &   F $!!A* A* A* A* A*H   2 $6:!i i i i ib 
D D D D DV "#/ / / / /l #$. . . . .j %1S S S S Sl1! 1! 1! 1!l */6:? ? ? ? ?F 26	 	 	 	 	   (  )-      )-      )-     KO
 
 
 
 
  \::> > > > >9 9 9 9> > > >BL L L L L Lr)   