
    dE                    ^   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  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,m-Z- ddl.m/Z/ erddl0m1Z1 d Z2d Z3dgdZ4d Z5d Z6dhdZ7dhdZ8dhdZ9dhdZ:didZ;e	 djdkd$            Z<edjdld'            Z<dmdld(Z<	 dmdnd+Z=d, Z>dod0Z?dhd1Z@dhd2ZAdpd4ZBdqd6ZCd7 ZDd8 ZEd9 ZFedrd<            ZGedsd?            ZGdmdtdAZGdudEZHdF ZIdvdIZJejK        dwdM            ZLdxdQZMejN        ejN        ejO        ejP        jQ        ejR        ejS        jQ        iZTi ejN        dRejO        dSejR        dTejU        dUejV        dVejN        dRejW        dRejX        dWejY        dWejZ        dXej[        dXej\        dYej]        dYej^        dZej_        dZej`        d[eja        d[ejO        dSejb        dSejR        dTejc        dTejd        d\eje        d\ejf        d]ejg        d]iZhdydaZidb ZjdzdfZkd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	GeneratorHashableIterableSequencecastoverload)lib)AnyArrayLike	ArrayLikeNpDtypeRandomStateT)'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              #  f   K   | D ]+}t          |          rt          |          E d{V  '|V  ,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elements     N/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/pandas/core/common.pyr#   r#   <   s_      "   w'' 	w''''''''''MMMM	     c                z    | d         j         }| dd          D ]"}	 |j         |k    rd }# t          $ r d }Y w xY w|S )Nr      )name
ValueError)objsr*   objs      r&   consensus_name_attrr.   T   se    7<DABBx  	x4 	 	 	DDD	Ks   )88keyr   returnboolc                   t          | t          t          j        t          f          s#t          |           rt          | j                  r| j        t          j        k    rvt          j	        |           }t          j        |          sLd}t          j        |          dk    r0t          |                                          rt          |          dS dS t!          | j                  rdS nat          | t"                    rLt%          |           dk    r9t'          |           t"          urt#          |           } t          j        |           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   is_bool_arrayinfer_dtyper    anyr+   r   listlentypeis_bool_list)r/   	key_arrayna_msgs      r&   is_bool_indexerrC   _   s,   8 #	2:x899 )c)7	BB) 9
""
3I$Y// X?9--::tI?R?R?T?T: %V,,,u439%% 	4		C		 )s88a<<Cyy$$3ii#C(((5r'   c                t    t          j        |           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)vals    r&   cast_scalar_indexerrH      sE     |C 
S^^-- 
)
 
 	

 Jr'   c                     d | D             S )zL
    Returns a generator consisting of the arguments that are not None.
    c              3     K   | ]}||V  	d S N .0args     r&   	<genexpr>znot_none.<locals>.<genexpr>   s"      33C3?C????33r'   rL   argss    r&   not_nonerS      s     4343333r'   c                 4    t          d | D                       S )z?
    Returns a boolean indicating if any argument is None.
    c              3     K   | ]}|d u V  	d S rK   rL   rM   s     r&   rP   zany_none.<locals>.<genexpr>   &      ++ssd{++++++r'   r<   rQ   s    r&   any_nonerX      !     ++d++++++r'   c                 4    t          d | D                       S )zA
    Returns a boolean indicating if all arguments are None.
    c              3     K   | ]}|d u V  	d S rK   rL   rM   s     r&   rP   zall_none.<locals>.<genexpr>   rV   r'   allrQ   s    r&   all_noner^      rY   r'   c                 4    t          d | D                       S )zC
    Returns a boolean indicating if any argument is not None.
    c              3     K   | ]}|d uV  	d S rK   rL   rM   s     r&   rP   zany_not_none.<locals>.<genexpr>   &      //3s$//////r'   rW   rQ   s    r&   any_not_nonerb      !     //$//////r'   c                 4    t          d | D                       S )zE
    Returns a boolean indicating if all arguments are not None.
    c              3     K   | ]}|d uV  	d S rK   rL   rM   s     r&   rP   zall_not_none.<locals>.<genexpr>   ra   r'   r\   rQ   s    r&   all_not_nonerf      rc   r'   intc                 4    t          d | D                       S )z;
    Returns the count of arguments that are not None.
    c              3     K   | ]}|d uV  	d S rK   rL   rN   xs     r&   rP   z!count_not_none.<locals>.<genexpr>   s&      ++q}++++++r'   )sumrQ   s    r&   count_not_nonerm      rY   r'   .valuesArrayLike | list | tuple | zipr7   NpDtype | None
np.ndarrayc                    d S rK   rL   rn   r7   s     r&   asarray_tuplesafert      s	     Cr'   r   r   c                    d S rK   rL   rs   s     r&   rt   rt          Cr'   c                   t          | t          t          f          s t          | d          st          |           } nt          | t                    r| j        S t          | t                    r$|t          j        t          fv rt          |           S 	 t          j                    5  t          j        dt          j                   t          j        | |          }d d d            n# 1 swxY w Y   n# t          $ r t          |           cY S w xY wt!          |j        j        t&                    rt          j        | t                    }|j        dk    rd | D             } t          |           }|S )N	__array__ignorer7      c                ,    g | ]}t          |          S rL   )tuplerj   s     r&   
<listcomp>z%asarray_tuplesafe.<locals>.<listcomp>   s    +++q%((+++r'   )r4   r=   r}   hasattrr   _valuesr5   r8   objectr   warningscatch_warningssimplefilterVisibleDeprecationWarningr9   r+   
issubclassr7   r?   strndim)rn   r7   results      r&   rt   rt      s   ve}-- 1M1M f	FH	%	% ~&$ ?Ebj&-A$A$A6v>>>
?$&& 	5 	5!(B,HIIIZe444F	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5  ? ? ?
 7v>>>>>? &,#S)) 2F&111{a++F+++8@@Ms6   C4 &6C(C4 (C,,C4 /C,0C4 4DDlabelsnp.ndarray | Iterablec                    t          | t          t          f          r| g} t          | t          t          j        f          s$	 t          |           } n# t          $ r | g} Y nw xY wt          | |          } | 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
    rz   )r4   r   r}   r=   r5   r6   	TypeErrorrt   )r   r7   s     r&   index_labels_to_arrayr     s     &3,'' ftRZ011 	&\\FF 	 	 	XFFF	 vU333FMs   A A"!A"c                H    | t          | t          t          f          s| gS | S rK   )r4   r}   r=   r-   s    r&   maybe_make_listr   "  s%    
z#t}==uJr'   r-   Iterable[T] | TCollection[T] | Tc                    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.
    )r4   r   r   Sizedr=   r   r
   r   s    r&   maybe_iterable_to_listr   (  sK     #s|$$ ZSY-G-G Cyy
z3

CJr'   c                b    t          | t                    o| j        du o| j        du o| j        du S )z
    We have a null slice.
    Nr4   slicestartstopstepr   s    r&   is_null_slicer   2  sE    
 	3 	I	H	 H	r'   c                p    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)r4   r   r   r   r   s    r&   is_empty_slicer   >  sG    
 	3 	"IT!	"HD 	" I!	r'   
list[bool]c                    d | D             S )zX
    Find non-trivial slices in "line": return a list of booleans with same length.
    c                X    g | ]'}t          |t                    ot          |           (S rL   )r4   r   r   )rN   ks     r&   r~   z"is_true_slices.<locals>.<listcomp>N  s2    HHHaJq%  9q)9)9%9HHHr'   rL   )r$   s    r&   is_true_slicesr   J  s     IH4HHHHr'   r$   c                j    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$   s     r&   is_full_slicer   R  sD    
 	3 	IN	H	 H	r'   c                    t          | d          rt          | d          S t          | t                    rt	          | j                  S t          |           rt          |           j        S d S )N__name__)	r   getattrr4   r   get_callable_namefunccallabler?   r   r   s    r&   r   r   ^  sj    sJ (sJ'''#w + ***}} "Cyy!!
 4r'   c                6    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-   kwargss      r&   apply_if_callabler   o  s2      -~c,,V,,,r'   c                6   t          j        |           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isclassr4   r   r   default_factoryr?   r   r   Mappingr   )intos    r&   standardize_mappingr     s    * ?4   dK(( 	>;(<===DzzdCK(( 53T33444{IJJJKr'   statenp.random.Generatorc                    d S rK   rL   r   s    r&   random_stater     rv   r'   Gint | ArrayLike | np.random.BitGenerator | np.random.RandomState | Nonenp.random.RandomStatec                    d S rK   rL   r   s    r&   r   r     s	     Cr'   RandomState | Nonec                x   t          |           s.t          |           st          | t          j        j                  rt          j                            |           S t          | t          j        j                  r| S t          | t          j        j                  r| S | t          j        S t          d          )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   r4   r5   randomBitGeneratorr   r   r+   r   s    r&   r   r     s    4 	5

 eRY344
" y$$U+++	E290	1	1 

	E29.	/	/ 
	y+
 
 	
r'   r   /Callable[..., T] | tuple[Callable[..., T], str]r   c                    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)r4   r}   r+   )r-   r   rR   r   targetmsgs         r&   piper     s    4 $ *fVLLLCS//!vtT$V$$$tC)$)))&)))r'   c                X      fd}t           t          j        t          f          r|n S )zv
    Returns a function that will map names/labels, dependent if mapper
    is a dict, Series or just a function.
    c                     | v r|          S | S rK   rL   )rk   mappers    r&   fzget_rename_function.<locals>.f  s    ;;!9Hr'   )r4   r   r   r   )r   r   s   ` r&   get_rename_functionr   	  s>         6CK#;<<H11&Hr'   "Hashable | Iterable | AnyArrayLikelist | AnyArrayLikec                    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.
    )
r4   r=   r5   r6   r   r   r   r   r   r   )rn   s    r&   convert_to_list_liker     sa     &4XyBSTUU 	FCL	)	) *VS2I2I F||8Or'   attrr   Generator[None, None, None]c              #     K   t          | |          }t          | ||           	 | V  t          | ||           dS # t          | ||           w xY w)zTemporarily 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)r-   r   value	old_values       r&   temp_setattrr   '  sg       T""ICu&			T9%%%%%T9%%%%s	   < Aindexr!   Nonec                    t          |           t          |          k    r0t          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>   r+   )datar   s     r&   require_length_matchr   ;  sg     4yyCJJD		  E

  
 
 	
 r'   rl   maxminr]   r<   meanprodstdvarmediancumprodcumsumrO   r	   
str | Nonec                6    t                               |           S )zH
    if we define an internal function for this argument, return it
    )_cython_tablegetrO   s    r&   get_cython_funcr   n  s     S!!!r'   c                8    t                               | |           S )zd
    if we define a builtin function for this argument, return it,
    otherwise return the arg
    )_builtin_tabler   r   s    r&   is_builtin_funcr   u  s    
 c3'''r'   namesSequence[Hashable | None]list[Hashable]c                4    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                &    g | ]\  }}|d| n|S )Nlevel_rL   )rN   ir*   s      r&   r~   z&fill_missing_names.<locals>.<listcomp>  s*    SSSwq$DLLQLLLdSSSr'   )	enumerate)r   s    r&   fill_missing_namesr   }  s!      TS)EBRBRSSSSr'   )r/   r   r0   r1   )r0   r1   )r0   rg   ).)rn   ro   r7   rp   r0   rq   )rn   r   r7   rp   r0   r   rK   )r   r   r7   rp   r0   rq   )r-   r   r0   r   )r0   r   )r$   rg   r0   r1   )r   r   r0   r   )r   r   r0   r   )r   r   )r   r   r0   r   )rn   r   r0   r   )r   r   r0   r   )r   r!   r0   r   )rO   r	   r0   r   )r   r   r0   r   )l__doc__
__future__r   builtinscollectionsr   r   
contextlib	functoolsr   r   typingr   r   r	   r
   r   r   r   r   r   r   r   numpyr5   pandas._libsr   pandas._typingr   r   r   r   r   pandas.core.dtypes.castr   pandas.core.dtypes.commonr   r   r   r   pandas.core.dtypes.genericr   r   r   pandas.core.dtypes.inferencer   pandas.core.dtypes.missingr    pandasr!   r#   r.   rC   rH   rS   rX   r^   rb   rf   rm   rt   r   r   r   r   r   r   r   r   r   r   r   r   r   r   contextmanagerr   r   rl   r   maximumreducer   minimumr   r]   r<   nansumr   nanmeanr   nanprodr   nanstdr   nanvarr   	nanmediannanmaxnanminr   
nancumprodr   	nancumsumr   r   r   r   rL   r'   r&   <module>r     sz   
 # " " " " "                                                                   L K K K K K                    
 = < < < < < + + + + + +   0  4 4 4 4n  ,4 4 4, , , ,, , , ,0 0 0 00 0 0 0, , , , 
DG    
 
    
    B <@    :     	 	 	 		 	 	 	I I I I	 	 	 	  "  "  @ 
   
 
   
5
 5
 5
 5
 5
p"* "* "* "*JI I I    & & & &&

 

 

 

" L"&L"*#L"*#L%L% L% FE	
 FE FE Iu GV J GV J FE Iu FE Iu  Ix!" L(#$ FEIuFEIuJ	M9IxL(3 :" " " "( ( (T T T T T Tr'   