
    bMh)D                       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rddl*m+Z+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1 d Z2d Z3dmdZ4d Z5d Z6dndZ7dndZ8dndZ9dndZ:dodZ;e	 dpdqd%            Z<edpdrd(            Z<dsdrd)Z<	 dsdtd,Z=d- Z>dud1Z?dnd2Z@dnd3ZAdvd5ZBdwd7ZCd8 ZDd9 ZEd: ZFedxd=            ZGedyd@            ZGdsdzdBZGd{dFZHdG ZId|dJZJejK        	 d}d~dP            ZLddTZMejN        ejN        ejO        ejP        jQ        ejR        ejS        jQ        iZTejN        dUejO        dVejR        dWiZUi ejN        dXejO        dYejR        dZejV        d[ejW        d\ejN        dXejX        dXejY        d]ejZ        d]ej[        d^ej\        d^ej]        d_ej^        d_ej_        d`ej`        d`eja        daejb        daejO        dYejc        dYejR        dZejd        dZeje        dbejf        dbejg        dcejh        dciZiddgZjdh Zkddl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              #  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     R/var/www/html/test/jupyter/venv/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-   V   se    7<DABBx  	x4 	 	 	DDD	Ks   )88keyr   returnboolc                J   t          | t          t          j        t          t
          f          rt          | t                    s| j        t          j        k    rSt          j	        |           }t          j        |          s)d}t          j        |d          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 valuesT)skipnaFr   )
isinstancer   npndarrayr   r   r   dtypeobject_asarrayr   is_bool_arrayr*   r   listlentypeis_bool_list)r.   	key_arrayna_msgs      r%   is_bool_indexerr@   a   s   8 iX/@A  )m,,) 9
""
3I$Y// X$Yt<<< - %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_indexerrE      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&   rI   argss    r%   not_nonerP      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 rH   rI   rJ   s     r%   rM   zany_none.<locals>.<genexpr>   &      ++ssd{++++++r&   anyrN   s    r%   any_nonerV      !     ++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 rH   rI   rJ   s     r%   rM   zall_none.<locals>.<genexpr>   rS   r&   allrN   s    r%   all_noner\      rW   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 rH   rI   rJ   s     r%   rM   zany_not_none.<locals>.<genexpr>   &      //3s$//////r&   rT   rN   s    r%   any_not_noner`      !     //$//////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 rH   rI   rJ   s     r%   rM   zall_not_none.<locals>.<genexpr>   r_   r&   rZ   rN   s    r%   all_not_nonerd      ra   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 rH   rI   rK   xs     r%   rM   z!count_not_none.<locals>.<genexpr>   s&      ++q}++++++r&   )sumrN   s    r%   count_not_nonerk      rW   r&   .valuesArrayLike | list | tuple | zipr6   NpDtype | None
np.ndarrayc                    d S rH   rI   rl   r6   s     r%   asarray_tuplesaferr      s	     Cr&   r	   r   c                    d S rH   rI   rq   s     r%   rr   rr          Cr&   c                0   t          | t          t          f          s t          | d          st          |           } n8t          | t                    r| j        S t          | t                    r| j        S t          | t                    r$|t          j        t          fv rt          |           S 	 t          j                    5  t          s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r6      c                ,    g | ]}t          |          S rI   )tuplerh   s     r%   
<listcomp>z%asarray_tuplesafe.<locals>.<listcomp>  s    +++q%((+++r&   )r3   r:   r{   hasattrr   _valuesr   r4   r7   objectr   warningscatch_warningsr   simplefilterVisibleDeprecationWarningr8   r*   
issubclassr6   r<   strndim)rl   r6   results      r%   rr   rr      s   ve}-- 1M1M f	FH	%	% ~	FI	&	& ~&$ ?Ebj&-A$A$A6v>>>?$&& 	5 	5% N%h0LMMM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   /D =D?D DD DD D32D3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
    rx   )r3   r   r{   r:   r4   r5   	TypeErrorrr   )r   r6   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 rH   )r3   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.
    )r3   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r3   slicestartstopstepr   s    r%   is_null_slicer   7  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)r3   r   r   r   r   s    r%   is_empty_slicer   C  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 rI   )r3   r   r   )rK   ks     r%   r|   z"is_true_slices.<locals>.<listcomp>S  s2    HHHaJq%  9q)9)9%9HHHr&   rI   )r#   s    r%   is_true_slicesr   O  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   W  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}   getattrr3   r   get_callable_namefunccallabler<   r   r   s    r%   r   r   c  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   t  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isclassr3   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 rH   rI   r   s    r%   random_stater     rt   r&   Hint | np.ndarray | np.random.BitGenerator | np.random.RandomState | Nonenp.random.RandomStatec                    d S rH   rI   r   s    r%   r   r     s	     Cr&   RandomState | Nonec                r   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 | 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   r3   r4   r5   randomBitGeneratorr   r   r*   r   s    r%   r   r     s    ( % 
Jurz29;Q.RSS 
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)r3   r{   r*   )r,   r   rO   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 rH   rI   )ri   mappers    r%   fzget_rename_function.<locals>.f  s    ;;!9Hr&   )r3   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.
    )
r3   r:   r4   r5   r   r   r   r   r	   r   )rl   s    r%   convert_to_list_liker     sa     &4XyBSTUU 	FCL	)	) *VS2I2I F||8Or&   Tattrr   	conditionGenerator[None, None, None]c              #     K   |r!t          | |          }t          | ||           	 | V  |rt          | ||           dS dS # |rt          | ||           w w xY 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_values        r%   temp_setattrr     s      .  "C&&	T5!!!*			 	*Cy)))))	* 	*9 	*Cy))))	*s   A 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   8  sg     4yyCJJD		  E

  
 
 	
 r&   znp.sumznp.maximum.reduceznp.minimum.reducerj   maxminr[   rU   meanprodstdvarmediancumprodcumsumrL   r   
str | Nonec                6    t                               |           S )zH
    if we define an internal function for this argument, return it
    )_cython_tablegetrL   s    r%   get_cython_funcr   r  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   y  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_rI   )rK   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   r/   r0   )r/   r0   )r/   re   ).)rl   rm   r6   rn   r/   ro   )rl   r	   r6   rn   r/   r   rH   )r   r   r6   rn   r/   ro   )r,   r   r/   r   )r/   r   )r#   re   r/   r0   )r   r   r/   r   )r   r   r/   r   )r   r   )r   r   r/   r   )rl   r   r/   r   )T)r   r   r   r0   r/   r   )r   r    r/   r   )rL   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   r   numpyr4   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@   rE   rP   rV   r\   r`   rd   rk   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   contextmanagerr   r   rj   r   maximumreducer   minimumr   _builtin_table_aliasr[   rU   nansumr   nanmeanr   nanprodr   nanstdr   nanvarr   	nanmediannanmaxnanminr   
nancumprodr   	nancumsumr   r   r   r   rI   r&   r%   <module>r     s   
 # " " " " "                                                         2 2 2 2 2 2 K K K K K K                   = < < < < < 	                0  4 4 4 4n  ,4 4 4, , , ,, , , ,0 0 0 00 0 0 0, , , , 
DG    
 
    
         H <@    :     	 	 	 		 	 	 	I I I I	 	 	 	  "  "  @ 
   
 
   
 
  
  
  
  
F"* "* "* "*JI I I    -1* * * * *@

 

 

 

" L"&L"*#L"*# 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&   