a
    pÝEbþB  ã                2   @  s¦  d Z ddlmZ ddlZddl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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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* ddl+m,Z,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2 e�rddl3m4Z4 G dd„ de5ƒZ6G dd„ de7ƒZ8dd„ Z9dd„ Z:dddœdd„Z;d‚ddœdd „Z<d!d"„ Z=dd#œd$d%„Z>dd#œd&d'„Z?dd#œd(d)„Z@dd#œd*d+„ZAd,d#œd-d.„ZBdƒd/d0d1œd2d3„ZCd„d/d0d1œd4d5„ZDd6d7„ ZEd8d9d:œd;d<„ZFdd#œd=d>„ZGd?d#œd@dA„ZHd,ddBœdCdD„ZIdEdF„ ZJdGdH„ ZKdIdJ„ ZLedKdKdLœdMdN„ƒZMedOdPdLœdQdN„ƒZMd…dRdSœdTdN„ZMdUdVdWœdXdY„ZNdZd[„ ZOd\d]d^œd_d`„ZPejQdadbdcœddde„ƒZRdfdgœdhdi„ZSejTejTejUejVjWejXejYjWiZZejTdjejUdkejXdlej[dmej\dnejTdjej]djej^doej_doej`dpejadpejbdqejcdqejddrejedrejfdsejgdsejUdkejhdkejXdlejidlejjdtejkdtejlduejmduiZndvdwdxœdydz„Zod{d|„ Zpd}d~dœd€d�„ZqdS )†zh
Misc tools for implementing data structures

Note: pandas.core.common is *not* part of the public API.
é    )ÚannotationsN)ÚabcÚdefaultdict)Úpartial)
ÚTYPE_CHECKINGÚAnyÚCallableÚ
CollectionÚHashableÚIterableÚIteratorÚSequenceÚcastÚoverload)Úlib)ÚAnyArrayLikeÚ	ArrayLikeÚNpDtypeÚRandomStateÚScalarÚT)Úfind_stack_level)Ú'construct_1d_object_array_from_listlike)Úis_array_likeÚis_bool_dtypeÚis_extension_array_dtypeÚ
is_integer)ÚABCExtensionArrayÚABCIndexÚ	ABCSeries)Úiterable_not_string)Úisna)ÚIndexc                   @  s   e Zd ZdS )ÚSettingWithCopyErrorN©Ú__name__Ú
__module__Ú__qualname__© r(   r(   úR/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/pandas/core/common.pyr#   >   s   r#   c                   @  s   e Zd ZdS )ÚSettingWithCopyWarningNr$   r(   r(   r(   r)   r*   B   s   r*   c                 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Úelementr(   r(   r)   r+   F   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_attr^   s    

r3   r   Úbool)ÚkeyÚreturnc                 C  sº   t | ttjtfƒs$t| ƒr‚t| jƒr‚| jtjkrrt 	| ¡} t
 | ¡snd}t
 | ¡dkrjt| ƒ ¡ rjt|ƒ‚dS dS t| jƒr¶dS n4t | tƒr¶t| ƒdkr¶t| ƒtur¬t| ƒ} 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 valuesÚbooleanFTr   )Ú
isinstancer   ÚnpÚndarrayr   r   r   ÚdtypeÚobject_Úasarrayr   Zis_bool_arrayZinfer_dtyper!   Úanyr0   r   ÚlistÚlenÚtypeZis_bool_list)r5   Zna_msgr(   r(   r)   Úis_bool_indexeri   s*    ÿÿ




rB   F)Ú
warn_floatc                 C  s4   t  | ¡r0|  ¡ r0|r(tjdttƒ d� t| ƒS | S )a  
    To avoid numpy DeprecationWarnings, cast float to integer where valid.

    Parameters
    ----------
    val : scalar
    warn_float : bool, default False
        If True, issue deprecation warning for a float indexer.

    Returns
    -------
    outval : scalar
    z„Indexing with a float is deprecated, and will raise an IndexError in pandas 2.0. You can manually convert to an integer key instead.)Ú
stacklevel)r   Zis_floatr   ÚwarningsÚwarnÚFutureWarningr   Úint)ÚvalrC   r(   r(   r)   Úcast_scalar_indexer    s    ürJ   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    rS   )r6   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 rK   r(   rL   r(   r(   r)   rO   Æ   rP   zany_none.<locals>.<genexpr>©r>   rQ   r(   r(   r)   Úany_noneÂ   s    rU   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 rK   r(   rL   r(   r(   r)   rO   Í   rP   zall_none.<locals>.<genexpr>©ÚallrQ   r(   r(   r)   Úall_noneÉ   s    rX   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 rK   r(   rL   r(   r(   r)   rO   Ô   rP   zany_not_none.<locals>.<genexpr>rT   rQ   r(   r(   r)   Úany_not_noneÐ   s    rY   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 rK   r(   rL   r(   r(   r)   rO   Û   rP   zall_not_none.<locals>.<genexpr>rV   rQ   r(   r(   r)   Úall_not_none×   s    rZ   rH   c                  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 rK   r(   ©rM   Úxr(   r(   r)   rO   â   rP   z!count_not_none.<locals>.<genexpr>)ÚsumrQ   r(   r(   r)   Úcount_not_noneÞ   s    r^   zNpDtype | Nonez
np.ndarray)r;   r6   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 tj
| |d�}t|jjtƒr|tj
| td�}|jdkrœdd„ | D ƒ} t	| ƒ}|S )NZ	__array__©r;   é   c                 S  s   g | ]}t |ƒ‘qS r(   )Útupler[   r(   r(   r)   Ú
<listcomp>ø   rP   z%asarray_tuplesafe.<locals>.<listcomp>)r8   r?   ra   Úhasattrr   Z_valuesr9   r<   Úobjectr   r=   Ú
issubclassr;   rA   ÚstrÚndim)Úvaluesr;   Úresultr(   r(   r)   Úasarray_tuplesafeå   s    


rj   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
    r_   )r8   rf   ra   r?   r9   r:   Ú	TypeErrorrj   )Úlabelsr;   r(   r(   r)   Úindex_labels_to_arrayþ   s    rm   c                 C  s    | d urt | ttfƒs| gS | S rK   )r8   ra   r?   ©r2   r(   r(   r)   Úmaybe_make_list  s    ro   zIterable[T] | TzCollection[T] | T)r2   r6   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.
    )r8   r   r   ÚSizedr?   r   r	   rn   r(   r(   r)   Úmaybe_iterable_to_list  s    
rq   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©r8   ÚsliceÚstartÚstopÚsteprn   r(   r(   r)   Úis_null_slice)  s    
ÿþürw   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(   )r8   rs   rw   )rM   Úkr(   r(   r)   rb   9  rP   z"is_true_slices.<locals>.<listcomp>r(   )r,   r(   r(   r)   Úis_true_slices5  s    ry   )r,   r6   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   Nrr   )r2   r,   r(   r(   r)   Úis_full_slice=  s    
ÿþürz   c                 C  s>   t | dƒrt| dƒS t| tƒr(t| jƒS t| ƒr:t| ƒjS d S )Nr%   )	rc   Úgetattrr8   r   Úget_callable_nameÚfuncÚcallablerA   r%   rn   r(   r(   r)   r|   I  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~   )Zmaybe_callabler2   Úkwargsr(   r(   r)   Úapply_if_callableZ  s    r€   c                 C  sX   t  | ¡s(t| tƒr tt| jƒS t| ƒ} t| tj	ƒsDt
d| › �ƒ‚n| tkrTt
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Úisclassr8   r   r   Údefault_factoryrA   re   r   ÚMappingrk   )Zintor(   r(   r)   Ústandardize_mappingk  s    

r…   znp.random.Generator)Ústater6   c                 C  s   d S rK   r(   ©r†   r(   r(   r)   Úrandom_state‹  s    rˆ   zGint | ArrayLike | np.random.BitGenerator | np.random.RandomState | Noneznp.random.RandomStatec                 C  s   d S rK   r(   r‡   r(   r(   r)   rˆ   �  s    zRandomState | Noner‡   c                 C  sh   t | ƒst| ƒst| tjjƒr*tj | ¡S t| tjjƒr<| S t| tjjƒrN| S | du r\tjS tdƒ‚dS )aþ  
    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.

        .. versionchanged:: 1.1.0

            array-like and BitGenerator object now passed to np.random.RandomState()
            as seed

        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   r8   r9   ÚrandomZBitGeneratorr   Ú	Generatorr0   r‡   r(   r(   r)   rˆ   —  s     ÿþýÿz/Callable[..., T] | tuple[Callable[..., T], str]r   )r}   r6   c                 O  s\   t |tƒrB|\}}||v r,|› d�}t|ƒ‚| ||< ||i |¤ŽS || g|¢R i |¤ŽS dS )ar  
    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)r8   ra   r0   )r2   r}   rR   r   ÚtargetÚmsgr(   r(   r)   ÚpipeÏ  s    

r�   c                   s&   t ˆ tjtfƒr‡ fdd„}nˆ }|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 rK   r(   )r\   ©Úmapperr(   r)   Úfû  s    zget_rename_function.<locals>.f)r8   r   r„   r   )r�   r�   r(   rŽ   r)   Úget_rename_functionô  s    r‘   z Scalar | Iterable | AnyArrayLikezlist | AnyArrayLike)rh   r6   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.
    )
r8   r?   r9   r:   r   r   r   r   r   rf   )rh   r(   r(   r)   Úconvert_to_list_like  s
    r’   rf   zIterator[None])Úattrr6   c                 c  s,   t | |ƒ}t| ||ƒ | V  t| ||ƒ dS )zø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.

    Yields:
        obj with modified attribute.
    N)r{   Úsetattr)r2   r“   ÚvalueÚ	old_valuer(   r(   r)   Útemp_setattr  s    
r—   r"   )Úindexc                 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)r@   r0   )Údatar˜   r(   r(   r)   Úrequire_length_match(  s    ÿýÿr›   r]   ÚmaxÚminrW   r>   ÚmeanÚprodÚstdÚvarÚmedianÚcumprodÚcumsumr   z
str | None)rN   r6   c                 C  s
   t  | ¡S )zH
    if we define an internal function for this argument, return it
    )Ú_cython_tableÚget©rN   r(   r(   r)   Úget_cython_func[  s    r¨   c                 C  s   t  | | ¡S )ze
    if we define an builtin function for this argument, return it,
    otherwise return the arg
    )Ú_builtin_tabler¦   r§   r(   r(   r)   Úis_builtin_funcb  s    rª   zSequence[Hashable | None]zlist[Hashable])Únamesr6   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(   )rM   Úir/   r(   r(   r)   rb   z  rP   z&fill_missing_names.<locals>.<listcomp>)Ú	enumerate)r«   r(   r(   r)   Úfill_missing_namesj  s    r®   )F)N)N)N)rÚ__doc__Ú
__future__r   ÚbuiltinsÚcollectionsr   r   Ú
contextlibÚ	functoolsr   r�   Útypingr   r   r   r	   r
   r   r   r   r   r   rE   Únumpyr9   Zpandas._libsr   Zpandas._typingr   r   r   r   r   r   Zpandas.util._exceptionsr   Zpandas.core.dtypes.castr   Zpandas.core.dtypes.commonr   r   r   r   Zpandas.core.dtypes.genericr   r   r   Zpandas.core.dtypes.inferencer    Zpandas.core.dtypes.missingr!   Zpandasr"   r0   r#   ÚWarningr*   r+   r3   rB   rJ   rS   rU   rX   rY   rZ   r^   rj   rm   ro   rq   rw   ry   rz   r|   r€   r…   rˆ   r�   r‘   r’   Úcontextmanagerr—   r›   r]   rœ   ÚmaximumÚreducer�   Úminimumr©   rW   r>   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ª   0 7
 8%

ýç