o
    _~#g)D                     @  sr  d Z ddlmZ ddlZddlmZ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ZddlmZmZmZmZmZ ddlZddlZddlmZ dd	lm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(m)Z) erddl*m+Z+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1 dd Z2dd Z3dddZ4dd Z5dd Z6dddZ7dd d!Z8dd"d#Z9dd$d%Z:dd'd(Z;e	)ddd/d0Z<eddd3d0Z<ddd4d0Z<	ddd7d8Z=d9d: Z>dd>d?Z?dd@dAZ@ddBdCZAddEdFZBddHdIZCdJdK ZDdLdM ZEdNdO ZFeddRdSZGeddVdSZGdddXdSZGdd\d]ZHd^d_ ZIddbdcZJejK	ddddidjZLddndoZMejNejNejOejPjQejRejSjQiZTejNdpejOdqejRdriZUi ejNdsejOdtejRduejVdvejWdwejNdsejXdsejYdxejZdxej[dyej\dyej]dzej^dzej_d{ej`d{ejad|ejbd|ejOdtejcdtejRduejdduejed}ejfd}ejgd~ejhd~iZidddZjdd ZkdddZldS )zh
Misc tools for implementing data structures

Note: pandas.core.common is *not* part of the public API.
    )annotationsN)abcdefaultdict)
Collection	GeneratorHashableIterableSequence)partial)TYPE_CHECKINGAnyCallablecastoverload)lib)np_version_gte1p24)'construct_1d_object_array_from_listlike)is_bool_dtype
is_integer)ABCExtensionArrayABCIndexABCMultiIndex	ABCSeries)iterable_not_string)AnyArrayLike	ArrayLikeNpDtypeRandomStateT)Indexc                 c  s.    | D ]}t |rt|E dH  q|V  qdS )a  
    Flatten an arbitrarily nested sequence.

    Parameters
    ----------
    line : sequence
        The non string sequence to flatten

    Notes
    -----
    This doesn't consider strings sequences.

    Returns
    -------
    flattened : generator
    N)r   flatten)lineelement r#   w/var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/pandas/core/common.pyr    >   s   r    c              	   C  sH   | d j }| dd  D ]}z	|j |krd }W q ty!   d }Y qw |S )Nr      )name
ValueError)objsr&   objr#   r#   r$   consensus_name_attrV   s   

r*   keyr   returnboolc                 C  s   t | ttjttfr9t | ts9| jtjkr0t	| }t
|s.d}t
j|ddr,t|dS dS t| jr7dS dS t | trSt| dkrSt| turNt| } t
| S dS )a  
    Check whether `key` is a valid boolean indexer.

    Parameters
    ----------
    key : Any
        Only list-likes may be considered boolean indexers.
        All other types are not considered a boolean indexer.
        For array-like input, boolean ndarrays or ExtensionArrays
        with ``_is_boolean`` set are considered boolean indexers.

    Returns
    -------
    bool
        Whether `key` is a valid boolean indexer.

    Raises
    ------
    ValueError
        When the array is an object-dtype ndarray or ExtensionArray
        and contains missing values.

    See Also
    --------
    check_array_indexer : Check that `key` is a valid array to index,
        and convert to an ndarray.
    z=Cannot mask with non-boolean array containing NA / NaN valuesT)skipnaFr   )
isinstancer   npndarrayr   r   r   dtypeobject_asarrayr   is_bool_arrayr'   r   listlentypeis_bool_list)r+   	key_arrayna_msgr#   r#   r$   is_bool_indexera   s,   


	

r<   c                 C  s   t | r|  rtd| S )z
    Disallow indexing with a float key, even if that key is a round number.

    Parameters
    ----------
    val : scalar

    Returns
    -------
    outval : scalar
    zYIndexing with a float is no longer supported. Manually convert to an integer key instead.)r   is_floatr   
IndexError)valr#   r#   r$   cast_scalar_indexer   s
   r@   c                  G     dd | D S )zL
    Returns a generator consisting of the arguments that are not None.
    c                 s  s    | ]	}|d ur|V  qd S Nr#   .0argr#   r#   r$   	<genexpr>   s    znot_none.<locals>.<genexpr>r#   argsr#   r#   r$   not_none      rI   c                  G     t dd | D S )z?
    Returns a boolean indicating if any argument is None.
    c                 s      | ]}|d u V  qd S rB   r#   rC   r#   r#   r$   rF          zany_none.<locals>.<genexpr>anyrG   r#   r#   r$   any_none      rP   c                  G  rK   )zA
    Returns a boolean indicating if all arguments are None.
    c                 s  rL   rB   r#   rC   r#   r#   r$   rF      rM   zall_none.<locals>.<genexpr>allrG   r#   r#   r$   all_none   rQ   rT   c                  G  rK   )zC
    Returns a boolean indicating if any argument is not None.
    c                 s      | ]}|d uV  qd S rB   r#   rC   r#   r#   r$   rF      rM   zany_not_none.<locals>.<genexpr>rN   rG   r#   r#   r$   any_not_none   rQ   rV   c                  G  rK   )zE
    Returns a boolean indicating if all arguments are not None.
    c                 s  rU   rB   r#   rC   r#   r#   r$   rF      rM   zall_not_none.<locals>.<genexpr>rR   rG   r#   r#   r$   all_not_none   rQ   rW   intc                  G  rK   )z;
    Returns the count of arguments that are not None.
    c                 s  rU   rB   r#   rD   xr#   r#   r$   rF      rM   z!count_not_none.<locals>.<genexpr>)sumrG   r#   r#   r$   count_not_none   rQ   r\   .valuesArrayLike | list | tuple | zipr2   NpDtype | None
np.ndarrayc                 C     d S rB   r#   r]   r2   r#   r#   r$   asarray_tuplesafe   s   rc   r   r   c                 C  ra   rB   r#   rb   r#   r#   r$   rc         c                 C  s
  t | ttfst| dst| } nt | tr| jS t | tr!| jS t | tr1|tjt	fv r1t
| S z&t  ts@tdtj tj| |d}W d    n1 sQw   Y  W n tyd   t
|  Y S w t|jjtrstj| t	d}|jdkrdd | D } t
| }|S )N	__array__ignorer2      c                 S  s   g | ]}t |qS r#   )tuplerY   r#   r#   r$   
<listcomp>  s    z%asarray_tuplesafe.<locals>.<listcomp>)r/   r6   ri   hasattrr   _valuesr   r0   r3   objectr   warningscatch_warningsr   simplefilterVisibleDeprecationWarningr4   r'   
issubclassr2   r8   strndim)r]   r2   resultr#   r#   r$   rc      s0   




labelsnp.ndarray | Iterablec                 C  sZ   t | ttfr
| g} t | ttjfs%zt| } W n ty$   | g} Y nw t| |d} | S )z
    Transform label or iterable of labels to array, for use in Index.

    Parameters
    ----------
    dtype : dtype
        If specified, use as dtype of the resulting array, otherwise infer.

    Returns
    -------
    array
    rg   )r/   rs   ri   r6   r0   r1   	TypeErrorrc   )rv   r2   r#   r#   r$   index_labels_to_array
  s   
ry   c                 C  s    | d urt | ttfs| gS | S rB   )r/   ri   r6   r)   r#   r#   r$   maybe_make_list'  s   r{   r)   Iterable[T] | TCollection[T] | Tc                 C  s.   t | tjrt | tjst| S tt| } | S )zB
    If obj is Iterable but not list-like, consume into list.
    )r/   r   r   Sizedr6   r   r   rz   r#   r#   r$   maybe_iterable_to_list-  s   
r   c                 C  s(   t | to| jdu o| jdu o| jdu S )z
    We have a null slice.
    Nr/   slicestartstopsteprz   r#   r#   r$   is_null_slice7     
r   c                 C  s*   t | to| jduo| jduo| j| jkS )z>
    We have an empty slice, e.g. no values are selected.
    N)r/   r   r   r   rz   r#   r#   r$   is_empty_sliceC  s   

r   
list[bool]c                 C  rA   )zX
    Find non-trivial slices in "line": return a list of booleans with same length.
    c                 S  s    g | ]}t |tot| qS r#   )r/   r   r   )rD   kr#   r#   r$   rj   S  s     z"is_true_slices.<locals>.<listcomp>r#   )r!   r#   r#   r$   is_true_slicesO  rJ   r   r!   c                 C  s(   t | to| jdko| j|ko| jdu S )z&
    We have a full length slice.
    r   Nr   )r)   r!   r#   r#   r$   is_full_sliceW  r   r   c                 C  s>   t | dr
t| dS t| trt| jS t| rt| jS d S )N__name__)	rk   getattrr/   r
   get_callable_namefunccallabler8   r   rz   r#   r#   r$   r   c  s   




r   c                 K  s   t | r| |fi |S | S )z
    Evaluate possibly callable input using obj and kwargs if it is callable,
    otherwise return as it is.

    Parameters
    ----------
    maybe_callable : possibly a callable
    obj : NDFrame
    **kwargs
    )r   )maybe_callabler)   kwargsr#   r#   r$   apply_if_callablet  s   r   c                 C  sV   t | st| trtt| jS t| } t| tj	s!t
d|  | tkr)t
d| S )a  
    Helper function to standardize a supplied mapping.

    Parameters
    ----------
    into : instance or subclass of collections.abc.Mapping
        Must be a class, an initialized collections.defaultdict,
        or an instance of a collections.abc.Mapping subclass.

    Returns
    -------
    mapping : a collections.abc.Mapping subclass or other constructor
        a callable object that can accept an iterator to create
        the desired Mapping.

    See Also
    --------
    DataFrame.to_dict
    Series.to_dict
    zunsupported type: z/to_dict() only accepts initialized defaultdicts)inspectisclassr/   r   r
   default_factoryr8   rr   r   Mappingrx   )intor#   r#   r$   standardize_mapping  s   

r   statenp.random.Generatorc                 C  ra   rB   r#   r   r#   r#   r$   random_state  rd   r   Hint | np.ndarray | np.random.BitGenerator | np.random.RandomState | Nonenp.random.RandomStatec                 C  ra   rB   r#   r   r#   r#   r$   r     s   RandomState | Nonec                 C  sb   t | st| tjtjjfrtj| S t| tjjr| S t| tjjr&| S | du r-tjS td)aq  
    Helper function for processing random_state arguments.

    Parameters
    ----------
    state : int, array-like, BitGenerator, Generator, np.random.RandomState, None.
        If receives an int, array-like, or BitGenerator, passes to
        np.random.RandomState() as seed.
        If receives an np.random RandomState or Generator, just returns that unchanged.
        If receives `None`, returns np.random.
        If receives anything else, raises an informative ValueError.

        Default None.

    Returns
    -------
    np.random.RandomState or np.random.Generator. If state is None, returns np.random

    Nzdrandom_state must be an integer, array-like, a BitGenerator, Generator, a numpy RandomState, or None)	r   r/   r0   r1   randomBitGeneratorr   r   r'   r   r#   r#   r$   r     s   r   /Callable[..., T] | tuple[Callable[..., T], str]r   c                 O  sX   t |tr!|\}}||v r| d}t|| ||< ||i |S || g|R i |S )as  
    Apply a function ``func`` to object ``obj`` either by passing obj as the
    first argument to the function or, in the case that the func is a tuple,
    interpret the first element of the tuple as a function and pass the obj to
    that function as a keyword argument whose key is the value of the second
    element of the tuple.

    Parameters
    ----------
    func : callable or tuple of (callable, str)
        Function to apply to this object or, alternatively, a
        ``(callable, data_keyword)`` tuple where ``data_keyword`` is a
        string indicating the keyword of ``callable`` that expects the
        object.
    *args : iterable, optional
        Positional arguments passed into ``func``.
    **kwargs : dict, optional
        A dictionary of keyword arguments passed into ``func``.

    Returns
    -------
    object : the return type of ``func``.
    z/ is both the pipe target and a keyword argument)r/   ri   r'   )r)   r   rH   r   targetmsgr#   r#   r$   pipe  s   

r   c                   s$    fdd}t  tjtfr|S  S )zv
    Returns a function that will map names/labels, dependent if mapper
    is a dict, Series or just a function.
    c                   s   |  v r |  S | S rB   r#   )rZ   mapperr#   r$   f  s   zget_rename_function.<locals>.f)r/   r   r   r   )r   r   r#   r   r$   get_rename_function  s   r   "Hashable | Iterable | AnyArrayLikelist | AnyArrayLikec                 C  s>   t | ttjtttfr| S t | tjrt | t	st| S | gS )z
    Convert list-like or scalar input to list-like. List, numpy and pandas array-like
    inputs are returned unmodified whereas others are converted to list.
    )
r/   r6   r0   r1   r   r   r   r   r   rs   )r]   r#   r#   r$   convert_to_list_like  s
   r   Tattrrs   	conditionGenerator[None, None, None]c              
   c  sR    |rt | |}t| || z| V  W |rt| || dS dS |r(t| || w w )a  
    Temporarily set attribute on an object.

    Parameters
    ----------
    obj : object
        Object whose attribute will be modified.
    attr : str
        Attribute to modify.
    value : Any
        Value to temporarily set attribute to.
    condition : bool, default True
        Whether to set the attribute. Provided in order to not have to
        conditionally use this context manager.

    Yields
    ------
    object : obj with modified attribute.
    N)r   setattr)r)   r   valuer   	old_valuer#   r#   r$   temp_setattr  s   
r   indexr   Nonec                 C  s2   t | t |krtdt |  dt | ddS )zC
    Check the length of data matches the length of the index.
    zLength of values (z") does not match length of index ()N)r7   r'   )datar   r#   r#   r$   require_length_match8  s   r   znp.sumznp.maximum.reduceznp.minimum.reducer[   maxminrS   rO   meanprodstdvarmediancumprodcumsumrE   r   
str | Nonec                 C  s
   t | S )zH
    if we define an internal function for this argument, return it
    )_cython_tablegetrE   r#   r#   r$   get_cython_funcr  s   
r   c                 C  s   t | | S )zd
    if we define a builtin function for this argument, return it,
    otherwise return the arg
    )_builtin_tabler   r   r#   r#   r$   is_builtin_funcy  s   r   namesSequence[Hashable | None]list[Hashable]c                 C  s   dd t | D S )a,  
    If a name is missing then replace it by level_n, where n is the count

    .. versionadded:: 1.4.0

    Parameters
    ----------
    names : list-like
        list of column names or None values.

    Returns
    -------
    list
        list of column names with the None values replaced.
    c                 S  s&   g | ]\}}|d u rd| n|qS )Nlevel_r#   )rD   ir&   r#   r#   r$   rj     s   & z&fill_missing_names.<locals>.<listcomp>)	enumerate)r   r#   r#   r$   fill_missing_names  s   r   )r+   r   r,   r-   )r,   r-   )r,   rX   ).)r]   r^   r2   r_   r,   r`   )r]   r   r2   r_   r,   r   rB   )rv   rw   r2   r_   r,   r`   )r)   r|   r,   r}   )r,   r   )r!   rX   r,   r-   )r   r   r,   r   )r   r   r,   r   )r   r   )r   r   r,   r   )r]   r   r,   r   )T)r   rs   r   r-   r,   r   )r   r   r,   r   )rE   r   r,   r   )r   r   r,   r   )m__doc__
__future__r   builtinscollectionsr   r   collections.abcr   r   r   r   r	   
contextlib	functoolsr
   r   typingr   r   r   r   r   rn   numpyr0   pandas._libsr   pandas.compat.numpyr   pandas.core.dtypes.castr   pandas.core.dtypes.commonr   r   pandas.core.dtypes.genericr   r   r   r   pandas.core.dtypes.inferencer   pandas._typingr   r   r   r   r   pandasr   r    r*   r<   r@   rI   rP   rT   rV   rW   r\   rc   ry   r{   r   r   r   r   r   r   r   r   r   r   r   r   contextmanagerr   r   r[   r   maximumreducer   minimumr   _builtin_table_aliasrS   rO   nansumr   nanmeanr   nanprodr   nanstdr   nanvarr   	nanmediannanmaxnanminr   
nancumprodr   	nancumsumr   r   r   r   r#   r#   r#   r$   <module>   s    
7




	$





 
#%

 

	

