
    Pi^F                    Z   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mZ ddlZddlmZ ddlZddlZddlmZmZmZmZmZmZ ddl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'm(Z( ddl)m*Z* ddl+m,Z, erddl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5 d Z6d Z7dtdZ8d Z9d Z:dudZ;dudZ<dudZ=dudZ>dvdZ?e	 dwdxd%            Z@edwdyd(            Z@dzdyd)Z@	 dzd{d,ZAd- ZBd|d1ZCdud2ZDdud3ZEd}d7ZFd~d8ZGd9 ZHd: ZId; ZJedd>            ZKeddA            ZKdzddCZK edD          ZLeddL            ZMeddN            ZMddPZMdQ ZNddTZOejP        dddZ            ZQdd^ZRi ejS        d_ejT        d`ejU        daejV        dbejW        dcejS        d_ejX        d_ejY        ddejZ        ddej[        deej\        deej]        dfej^        dfej_        dgej`        dgeja        dhejb        dhejT        d`ejc        d`ejU        daejd        daeje        diejf        diejg        djejh        djiZiddnZjddrZkds ZldS )zh
Misc tools for implementing data structures

Note: pandas.core.common is *not* part of the public API.
    )annotationsN)abcdefaultdict)Callable
Collection	GeneratorHashableIterableSequence)partial)TYPE_CHECKINGAnyConcatenateTypeVarcastoverload)lib)'construct_1d_object_array_from_listlike)is_bool_dtype
is_integer)ABCExtensionArrayABCIndexABCMultiIndexABCNumpyExtensionArray	ABCSeries)iterable_not_string)
Expression)AnyArrayLike	ArrayLikeNpDtypeP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     f/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/core/common.pyr&   r&   D   s_      "   w'' 	w''''''''''MMMM	     c                    | d         j         }| dd          D ]%}	 |j         |k    rd } n# t          $ r d }Y  nw xY w|S )Nr      )name
ValueError)objsr-   objs      r)   consensus_name_attrr1   \   su    7<DABBx  	x4    	 	 	DEE	 Ks   +;;keyr   returnboolc                V   t          | t          t          j        t          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   r   dtypeobject_asarrayr   is_bool_arrayr.   r   listlentypeis_bool_list)r2   	key_arrayna_msgs      r)   is_bool_indexerrD   i   s   8 	BJ*;=ST  ) 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_indexerrI      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*   rM   argss    r)   not_nonerT      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 rL   rM   rN   s     r)   rQ   zany_none.<locals>.<genexpr>   &      ++ssd{++++++r*   anyrR   s    r)   any_nonerZ      !     ++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 rL   rM   rN   s     r)   rQ   zall_none.<locals>.<genexpr>   rW   r*   allrR   s    r)   all_noner`      r[   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 rL   rM   rN   s     r)   rQ   zany_not_none.<locals>.<genexpr>   &      //3s$//////r*   rX   rR   s    r)   any_not_nonerd      !     //$//////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 rL   rM   rN   s     r)   rQ   zall_not_none.<locals>.<genexpr>   rc   r*   r^   rR   s    r)   all_not_nonerh      re   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 rL   rM   rO   xs     r)   rQ   z!count_not_none.<locals>.<genexpr>   s&      ++q}++++++r*   )sumrR   s    r)   count_not_nonero      r[   r*   .valuesArrayLike | list | tuple | zipr:   NpDtype | None
np.ndarrayc                    d S rL   rM   rp   r:   s     r)   asarray_tuplesaferv      s	     Cr*   r
   r   c                    d S rL   rM   ru   s     r)   rv   rv      s    SVSVr*   c                   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        | |          }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__r:      c                ,    g | ]}t          |          S rM   )tuplerl   s     r)   
<listcomp>z%asarray_tuplesafe.<locals>.<listcomp>  s    +++q%((+++r*   )r7   r>   r}   hasattrr   _valuesr   r8   r;   objectr   r<   r.   
issubclassr:   r@   strndim)rp   r:   results      r)   rv   rv      sF   ve}-- 1M1M f	FH	%	% ~	FI	&	& ~&$ ?Ebj&-A$A$A6v>>>?F%000 ? ? ?
 7v>>>>>? &,#S)) 2F&111{a++F+++8@@Ms   /C C"!C"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   )r7   r   r}   r>   r8   r9   	TypeErrorrv   )r   r:   rlabelss      r)   index_labels_to_arrayr     s     &3,'' ftRZ011 	&\\FF 	 	 	XFFF	  e444GNs   A A"!A"c                H    | t          | t          t          f          s| gS | S rL   )r7   r}   r>   r0   s    r)   maybe_make_listr   +  s%    
z#t}==uJr*   r0   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.
    )r7   r   r
   Sizedr>   r   r   r   s    r)   maybe_iterable_to_listr   1  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r7   slicestartstopstepr   s    r)   is_null_slicer   ;  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)r7   r   r   r   r   s    r)   is_empty_slicer   G  sG    
 	3 	"IT!	"HD 	" I!	r*   r'   abc.Iterableabc.Generator[bool, None, None]c              #  b   K   | D ])}t          |t                    ot          |           V  *dS )z;
    Find non-trivial slices in "line": yields a bool.
    N)r7   r   r   )r'   ks     r)   is_true_slicesr   S  sJ        < <E"";=+;+;';;;;;< <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   )r0   r'   s     r)   is_full_slicer   \  sD    
 	3 	IN	H	 H	r*   c                    t          | d          r| j        S t          | t                    rt	          | j                  S t          |           rt          |           j        S d S )N__name__)r   r   r7   r   get_callable_namefunccallabler@   r   s    r)   r   r   h  sb    sJ |#w + ***}} "Cyy!!
 4r*   c                |    t          | t                    r | j        |fi |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
    )r7   r   _eval_expressionr   )maybe_callabler0   kwargss      r)   apply_if_callabler   y  s_     .*-- -.~.s==f===	.	!	! -~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isclassr7   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 rL   rM   r   s    r)   random_stater     s    EHSr*   Hint | np.ndarray | np.random.BitGenerator | np.random.RandomState | Nonenp.random.RandomStatec                    d S rL   rM   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   r7   r8   r9   randomBitGeneratorr"   r   r.   r   s    r)   r   r     s    ( % 
Jurz29;Q.RSS 
y$$U+++	E290	1	1 

	E29.	/	/ 
	y+
 
 	
r*   _Tr   Callable[Concatenate[_T, P], T]rS   P.argsr   P.kwargsr#   c                    d S rL   rM   r0   r   rS   r   s       r)   piper     	     	r*   tuple[Callable[..., T], str]c                    d S rL   rM   r   s       r)   r   r     r   r*   >Callable[Concatenate[_T, P], T] | tuple[Callable[..., T], str]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)r7   r}   r.   )r0   r   rS   r   func_targetmsgs          r)   r   r     s    : $ 	*vVLLLCS//!vud%f%%%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 rL   rM   )rm   mappers    r)   fzget_rename_function.<locals>.f  s    ;;!9Hr*   )r7   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.
    )
r7   r>   r8   r9   r   r   r   r   r
   r   )rp   s    r)   convert_to_list_liker   &  sa     &4XyBSTUU 	FCL	)	) *VS2I2I F||8Or*   Tattrr   	conditionGenerator[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)getattrsetattr)r0   r   valuer   	old_values        r)   temp_setattrr   5  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   T  sg     4yyCJJD		  E

  
 
 	
 r*   rn   maxminr_   rY   meanprodstdvarmediancumprodcumsumrP   r   
str | Nonec                6    t                               |           S )zH
    if we define an internal function for this argument, return it
    )_cython_tableget)rP   s    r)   get_cython_funcr   ~  s     S!!!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

    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_rM   )rO   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*   c                t    t          j        d          }|j                                        D ]	}|| u r dS 
dS )a  
    Helper function used in detecting chained assignment.

    If the pandas object (DataFrame/Series) is a local variable
    in the caller's frame, it should not be a case of chained
    assignment or method call.

    For example:

    def test():
        df = pd.DataFrame(...)
        df["a"] = 1  # not chained assignment

    Inside ``df.__setitem__``, we call this function to check whether `df`
    (`self`) is a local variable in `test` frame (the frame calling setitem). If
    so, we know it is not a case of chained assignment (even when the refcount
    of `df` is below the threshold due to optimization of local variables).
    r{   TF)sys	_getframef_localsrp   )r0   framevs      r)   is_local_in_caller_framer    sJ    & M!E^""$$  8844 5r*   )r2   r   r3   r4   )r3   r4   )r3   ri   ).)rp   rq   r:   rr   r3   rs   )rp   r
   r:   rr   r3   r   rL   )r   r   r:   rr   r3   rs   )r0   r   r3   r   )r'   r   r3   r   )r'   ri   r3   r4   )r   r   r3   r   )r   r   r3   r   )r   r   )
r0   r   r   r   rS   r   r   r   r3   r#   )
r0   r   r   r   rS   r   r   r   r3   r#   )
r0   r   r   r   rS   r   r   r   r3   r#   )rp   r   r3   r   )T)r   r   r   r4   r3   r   )r   r$   r3   r   )rP   r   r3   r   )r   r   r3   r   )m__doc__
__future__r   builtinscollectionsr   r   collections.abcr   r   r   r	   r
   r   
contextlib	functoolsr   r   r   typingr   r   r   r   r   r   numpyr8   pandas._libsr   pandas.core.dtypes.castr   pandas.core.dtypes.commonr   r   pandas.core.dtypes.genericr   r   r   r   r   pandas.core.dtypes.inferencer   pandas.core.colr   pandas._typingr   r   r    r!   r"   r#   pandasr$   r&   r1   rD   rI   rT   rZ   r`   rd   rh   ro   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   contextmanagerr   r   rn   r   r   r_   rY   nansumr   nanmeanr   nanprodr   nanstdr   nanvarr   	nanmediannanmaxnanminr   
nancumprodr   	nancumsumr   r   r   r  rM   r*   r)   <module>r"     s    # " " " " "                                   



                          K K K K K K                     = < < < < < & & & & & & 
                  0
 
 
5 5 5 5p  ,4 4 4, , , ,, , , ,0 0 0 00 0 0 0, , , , 
DG    
 
 V V V V 
 V    @ <@    :     	 	 	 		 	 	 	< < < <	 	 	 	  "  &  @ 
 H H H 
 H 
      
 
 
  
  
  
  
F WT]] 
   
 
   
&* &* &* &*RI I I    * * * * *<

 

 

 

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"    r*   