a
    d3C                  2   @  s  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& ddl'm(Z( erddl)m*Z*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0 dd Z1dd Z2dddddZ3dd Z4dd Z5ddddZ6ddd d!Z7ddd"d#Z8ddd$d%Z9d&dd'd(Z:edd*d+d,d-d.d/Z;edd0d+d1d-d2d/Z;dd0d+d1d-d3d/Z;dd4d+d,d5d6d7Z<d8d9 Z=d:d;d<d=d>Z>ddd?d@Z?dddAdBZ@dCddDdEZAd&ddFdGdHZBdIdJ ZCdKdL ZDdMdN ZEedOdOdPdQdRZFedSdTdPdUdRZFddVdWdXdRZFdYdZd[d\d]ZGd^d_ ZHd`dadbdcddZIejJddfddgdhdidjZKdkdldmdndoZLejMejMejNejOjPejQejRjPiZSejMdpejNdqejQdriZTejMdsejNdtejQduejUdvejVdwejMdsejWdsejXdxejYdxejZdyej[dyej\dzej]dzej^d{ej_d{ej`d|ejad|ejNdtejbdtejQduejcduejdd}ejed}ejfd~ejgd~iZhdddddZidd ZjdddddZkd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	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"   [/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/pandas/core/common.pyr   =   s    r   c              	   C  sJ   | d j }| dd  D ].}z|j |kr*d }W q tyB   d }Y q0 q|S )Nr      )name
ValueError)objsr%   objr"   r"   r#   consensus_name_attrU   s    

r)   r   bool)keyreturnc                 C  s   t | ttjttfrf| jtjkrVt| }t	
|sRd}t	j
|ddrNt|dS dS t| jrdS n4t | trt| dkrt| turt| } 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)ZskipnaFr   )
isinstancer   npndarrayr   r   dtypeobject_asarrayr   Zis_bool_arrayr&   r   listlentypeZis_bool_list)r+   Z	key_arrayZna_msgr"   r"   r#   is_bool_indexer`   s"    




r6   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   Zis_floatr   
IndexError)valr"   r"   r#   cast_scalar_indexer   s
    r9   c                  G  s   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>       znot_none.<locals>.<genexpr>r"   argsr"   r"   r#   not_none   s    rB   )r,   c                  G  s   t dd | D S )z?
    Returns a boolean indicating if any argument is None.
    c                 s  s   | ]}|d u V  qd S r:   r"   r;   r"   r"   r#   r>      r?   zany_none.<locals>.<genexpr>anyr@   r"   r"   r#   any_none   s    rE   c                  G  s   t dd | D S )zA
    Returns a boolean indicating if all arguments are None.
    c                 s  s   | ]}|d u V  qd S r:   r"   r;   r"   r"   r#   r>      r?   zall_none.<locals>.<genexpr>allr@   r"   r"   r#   all_none   s    rH   c                  G  s   t dd | D S )zC
    Returns a boolean indicating if any argument is not None.
    c                 s  s   | ]}|d uV  qd S r:   r"   r;   r"   r"   r#   r>      r?   zany_not_none.<locals>.<genexpr>rC   r@   r"   r"   r#   any_not_none   s    rI   c                  G  s   t dd | D S )zE
    Returns a boolean indicating if all arguments are not None.
    c                 s  s   | ]}|d uV  qd S r:   r"   r;   r"   r"   r#   r>      r?   zall_not_none.<locals>.<genexpr>rF   r@   r"   r"   r#   all_not_none   s    rJ   intc                  G  s   t dd | D S )z;
    Returns the count of arguments that are not None.
    c                 s  s   | ]}|d uV  qd S r:   r"   r<   xr"   r"   r#   r>      r?   z!count_not_none.<locals>.<genexpr>)sumr@   r"   r"   r#   count_not_none   s    rO   .zArrayLike | list | tuple | zipzNpDtype | Nonez
np.ndarray)valuesr0   r,   c                 C  s   d S r:   r"   rP   r0   r"   r"   r#   asarray_tuplesafe   s    rR   r   r   c                 C  s   d S r:   r"   rQ   r"   r"   r#   rR      s    c                 C  s   t | ttfs"t| ds"t| } nt | tr2| jS t | trR|tjtfv rRt	| S zLt
 0 tspt
dtj tj| |d}W d    n1 s0    Y  W n ty   t	|  Y S 0 t|jjtrtj| td}|jdkrdd | D } t	| }|S )NZ	__array__ignorer0      c                 S  s   g | ]}t |qS r"   )tuplerL   r"   r"   r#   
<listcomp>   r?   z%asarray_tuplesafe.<locals>.<listcomp>)r-   r3   rV   hasattrr   Z_valuesr.   r1   objectr   warningscatch_warningsr   simplefilterZVisibleDeprecationWarningr2   r&   
issubclassr0   r5   strndim)rP   r0   resultr"   r"   r#   rR      s&    


0
znp.ndarray | Iterable)labelsr0   r,   c                 C  sZ   t | ttfr| g} t | ttjfsJzt| } W n tyH   | g} Y n0 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
    rT   )r-   r^   rV   r3   r.   r/   	TypeErrorrR   )ra   r0   r"   r"   r#   index_labels_to_array  s    rc   c                 C  s    | d urt | ttfs| gS | S r:   )r-   rV   r3   r(   r"   r"   r#   maybe_make_list"  s    re   zIterable[T] | TzCollection[T] | T)r(   r,   c                 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   Sizedr3   r   r   rd   r"   r"   r#   maybe_iterable_to_list(  s    
rg   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steprd   r"   r"   r#   is_null_slice2  s    
rm   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-   ri   rj   rk   rd   r"   r"   r#   is_empty_slice>  s    

rn   z
list[bool]c                 C  s   dd | D S )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-   ri   rm   )r<   kr"   r"   r#   rW   N  r?   z"is_true_slices.<locals>.<listcomp>r"   )r    r"   r"   r#   is_true_slicesJ  s    rp   )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   Nrh   )r(   r    r"   r"   r#   is_full_sliceR  s    
rq   c                 C  s>   t | drt| dS t| tr(t| jS t| r:t| jS d S )N__name__)	rX   getattrr-   r
   get_callable_namefunccallabler5   rr   rd   r"   r"   r#   rt   ^  s    




rt   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
    )rv   )Zmaybe_callabler(   kwargsr"   r"   r#   apply_if_callableo  s    rx   c                 C  sV   t | s(t| tr tt| jS t| } t| tj	sBt
d|  | tkrRt
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_factoryr5   r]   r   Mappingrb   )Zintor"   r"   r#   standardize_mapping  s    

r}   znp.random.Generator)stater,   c                 C  s   d S r:   r"   r~   r"   r"   r#   random_state  s    r   zHint | np.ndarray | np.random.BitGenerator | np.random.RandomState | Noneznp.random.RandomStatec                 C  s   d S r:   r"   r   r"   r"   r#   r     s    zRandomState | Noner   c                 C  sf   t | st| tjtjjfr(tj| S t| tjjr:| S t| tjjrL| S | du rZtjS tddS )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-   r.   r/   randomZBitGeneratorr   r   r&   r   r"   r"   r#   r     s    z/Callable[..., T] | tuple[Callable[..., T], str]r   )ru   r,   c                 O  s\   t |trB|\}}||v r,| d}t|| ||< ||i |S || g|R i |S d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 argumentN)r-   rV   r&   )r(   ru   rA   rw   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 d S r:   r"   )rM   mapperr"   r#   f  s    zget_rename_function.<locals>.f)r-   r   r|   r   )r   r   r"   r   r#   get_rename_function  s    r   z"Hashable | Iterable | AnyArrayLikezlist | AnyArrayLike)rP   r,   c                 C  s>   t | ttjtttfr| S t | tjr8t | t	s8t| 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-   r3   r.   r/   r   r   r   r   r   r^   )rP   r"   r"   r#   convert_to_list_like  s
    r   Tr^   zGenerator[None, None, None])attr	conditionr,   c              
   c  sL   |rt | |}t| || z| V  W |rHt| || n|rFt| || 0 dS )a~  Temporarily set attribute on an object.

    Args:
        obj: Object whose attribute will be modified.
        attr: Attribute to modify.
        value: Value to temporarily set attribute to.
        condition: Whether to set the attribute. Provided in order to not have to
            conditionally use this context manager.

    Yields:
        obj with modified attribute.
    N)rs   setattr)r(   r   valuer   	old_valuer"   r"   r#   temp_setattr  s    
r   r   None)indexr,   c                 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)r4   r&   )datar   r"   r"   r#   require_length_match,  s    r   znp.sumznp.maximum.reduceznp.minimum.reducerN   maxminrG   rD   meanprodstdvarmediancumprodcumsumr   z
str | None)r=   r,   c                 C  s
   t | S )zH
    if we define an internal function for this argument, return it
    )_cython_tablegetr=   r"   r"   r#   get_cython_funcf  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_funcm  s    r   zSequence[Hashable | None]zlist[Hashable])namesr,   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 )NZlevel_r"   )r<   ir%   r"   r"   r#   rW     r?   z&fill_missing_names.<locals>.<listcomp>)	enumerate)r   r"   r"   r#   fill_missing_namesu  s    r   ).).)N)N)N)T)l__doc__
__future__r   builtinscollectionsr   r   collections.abcr   r   r   r   r	   
contextlib	functoolsr
   ry   typingr   r   r   r   r   rZ   numpyr.   Zpandas._libsr   Zpandas.compat.numpyr   Zpandas.core.dtypes.castr   Zpandas.core.dtypes.commonr   r   Zpandas.core.dtypes.genericr   r   r   Zpandas.core.dtypes.inferencer   Zpandas._typingr   r   r   r   r   Zpandasr   r   r)   r6   r9   rB   rE   rH   rI   rJ   rO   rR   rc   re   rg   rm   rn   rp   rq   rt   rx   r}   r   r   r   r   contextmanagerr   r   rN   r   maximumreducer   Zminimumr   Z_builtin_table_aliasrG   rD   Znansumr   Znanmeanr   Znanprodr   Znanstdr   Znanvarr   Z	nanmedianZnanmaxZnanminr   Z
nancumprodr   Z	nancumsumr   r   r   r   r"   r"   r"   r#   <module>   s   5 	" 
 #% 

