
    `VgM                       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$ 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l0m1Z1 erddl2m3Z3 d Z4d Z5d?dZ6d@dAdZ7d Z8dBdZ9dBdZ:dBdZ;dBdZ<dCdZ=e	 dD	 	 	 	 	 dEd       Z>edDdFd       Z>dGdFdZ>	 dG	 	 	 	 	 dHdZ?d Z@dIdZAdBd ZBdJd!ZCdKd"ZDd# ZEd$ ZFd% ZGedLd&       ZHe	 	 	 	 dMd'       ZHdGdNd(ZH	 	 	 	 dOd)ZId* ZJ	 	 	 	 dPd+ZKej                  dQd,       ZMdRd-ZNej                  ej                  ej                  ej                  j                  ej                  ej                  j                  iZUi ej                  d.ej                  d/ej                  d0ej                  d1ej                  d2ej                  d.ej                  d.ej                  d3ej                  d3ej                  d4ej                  d4ej                  d5ej                  d5ej                  d6ej                  d6ej                  d7ej                  d7ej                  d/ej                  d/ej                  d0ej                  d0ej                  d8ej                  d8ej                  d9ej                  d9iZidSd:Zjd; ZkdTd<ZldUd=Zm	 d@	 	 	 	 	 	 	 dVd>Zny)Wzh
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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              #  d   K   | D ]%  }t        |      rt        |      E d{    "| ' y7 w)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     S/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/pandas/core/common.pyr$   r$   =   s5     "  w'w'''M	's   0.0c                ~    | d   j                   }| dd  D ]  }	 |j                   |k7  rd } |S # t        $ r d }Y &w xY w)Nr      )name
ValueError)objsr*   objs      r'   consensus_name_attrr.   U   sX    7<<DABx 	xx4 K  	D	s   .<<c                h   t        | t        t        j                  t        f      s t        |       rt        | j                        r| j                  t        j                  k(  rjt        j                  |       }t        j                  |      s?d}t        j                  |      dk(  r$t        |      j                         rt        |      yyt!        | j                        ryyt        | t"              r?t%        |       dkD  r1t'        |       t"        urt#        |       } t        j(                  |       S y)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)key	key_arrayna_msgs      r'   is_bool_indexerrA   `   s    8 #	2::x89c7		B99

"

3I$$Y/X??9-:tI?R?R?T %V,,399%  
C	s8a<Cy$3i##C((    c                    t        j                  |       rA| j                         r1|r$t        j                  dt
        t                      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
    zIndexing 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   is_floatr   warningswarnFutureWarningr   int)val
warn_floats     r'   cast_scalar_indexerrM      sG     ||CS^^-MMU+-	 3xJrB   c                     d | D        S )zL
    Returns a generator consisting of the arguments that are not None.
    c              3  &   K   | ]	  }||  y wN .0args     r'   	<genexpr>znot_none.<locals>.<genexpr>   s     3C3?C3s   rQ   argss    r'   not_nonerX      s     4433rB   c                 &    t        d | D              S )z?
    Returns a boolean indicating if any argument is None.
    c              3  $   K   | ]  }|d u  
 y wrP   rQ   rR   s     r'   rU   zany_none.<locals>.<genexpr>        +ssd{+   r9   rV   s    r'   any_noner^           +d+++rB   c                 &    t        d | D              S )zA
    Returns a boolean indicating if all arguments are None.
    c              3  $   K   | ]  }|d u  
 y wrP   rQ   rR   s     r'   rU   zall_none.<locals>.<genexpr>   r[   r\   allrV   s    r'   all_nonerd      r_   rB   c                 &    t        d | D              S )zC
    Returns a boolean indicating if any argument is not None.
    c              3  $   K   | ]  }|d u 
 y wrP   rQ   rR   s     r'   rU   zany_not_none.<locals>.<genexpr>        /3s$/r\   r]   rV   s    r'   any_not_nonerh           /$///rB   c                 &    t        d | D              S )zE
    Returns a boolean indicating if all arguments are not None.
    c              3  $   K   | ]  }|d u 
 y wrP   rQ   rR   s     r'   rU   zall_not_none.<locals>.<genexpr>   rg   r\   rb   rV   s    r'   all_not_nonerl      ri   rB   c                 &    t        d | D              S )z;
    Returns the count of arguments that are not None.
    c              3  $   K   | ]  }|d u 
 y wrP   rQ   )rS   xs     r'   rU   z!count_not_none.<locals>.<genexpr>   s     +q}+r\   )sumrV   s    r'   count_not_nonerq      r_   rB   c                     y rP   rQ   valuesr4   s     r'   asarray_tuplesaferu      s     rB   c                     y rP   rQ   rs   s     r'   ru   ru          rB   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        t!        j"                  j$                  t&              rt        j                  | t              }|j(                  dk(  r#| D cg c]  }t        |       } }t        |       }|S # 1 sw Y   |xY w# t        $ r t        |       cY S w xY wc c}w )N	__array__ignorer4      )r1   r:   tuplehasattrr   _valuesr2   r5   objectr   rG   catch_warningssimplefilterVisibleDeprecationWarningr6   r+   
issubclassr4   r<   strndim)rt   r4   resultro   s       r'   ru   ru      s    ve}-1Mf	FH	%~~&$Ebjj&-A$A6v>>
?$$& 	5!!(B,H,HIZZe4F	5 &,,##S)F&1{{a$*+q%(++8@M'	5 	5  ?
 7v>>? ,s0   ?E <E
E )E0
EE E-,E-c                    t        | t        t        f      r| g} t        | t        t        j
                  f      s	 t        |       } t        | |      } | S # t        $ r | g} Y w xY w)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{   )r1   r   r}   r:   r2   r3   	TypeErrorru   )labelsr4   s     r'   index_labels_to_arrayr     se     &3,'ftRZZ01	&\F vU3FM  	XF	s   A A$#A$c                <    | t        | t        t        f      s| gS | S rP   )r1   r}   r:   r-   s    r'   maybe_make_listr   )  s     
z#t}=uJrB   c                    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.
    )r1   r   r   Sizedr:   r   r
   r   s    r'   maybe_iterable_to_listr   /  s:     #s||$ZSYY-GCy
z3
CJrB   c                    t        | t              xr. | j                  du xr | j                  du xr | j                  du S )z
    We have a null slice.
    Nr1   slicestartstopstepr   s    r'   is_null_slicer   9  sH    
 	3 	II	HH	 HH	rB   c                d    | D cg c]   }t        |t              xr t        |       " c}S c c}w )zX
    Find non-trivial slices in "line": return a list of booleans with same length.
    )r1   r   r   )r%   ks     r'   is_true_slicesr   E  s1     DHHaJq% 9q)9%99HHHs   %-c                    t        | t              xr0 | j                  dk(  xr | j                  |k(  xr | j                  du S )z&
    We have a full length slice.
    r   Nr   )r-   r%   s     r'   is_full_slicer   M  sG    
 	3 	IIN	HH	 HH	rB   c                    t        | d      rt        | d      S t        | t              rt	        | j
                        S t        |       rt        |       j                  S y )N__name__)	r~   getattrr1   r   get_callable_namefunccallabler<   r   r   s    r'   r   r   Y  sN    sJsJ''#w **}Cy!!!
 rB   c                .    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   j  s"     c,V,,rB   c                   t        j                  |       s5t        | 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isclassr1   r   r   default_factoryr<   r   r   Mappingr   )intos    r'   standardize_mappingr   {  sp    * ??4 dK(;(<(<==DzdCKK(,TF344		IJJKrB   c                     y rP   rQ   states    r'   random_stater     rw   rB   c                     y rP   rQ   r   s    r'   r   r     s     rB   c                   t        |       s/t        |       s$t        | t        j                  j
                        rt        j                  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

    zdrandom_state must be an integer, array-like, a BitGenerator, Generator, a numpy RandomState, or None)	r   r   r1   r2   randomBitGeneratorr   	Generatorr+   r   s    r'   r   r     s    4 	5eRYY334 yy$$U++	E29900	1	E299..	/	yy+
 	
rB   c                    t        |t              r&|\  }}||v r| d}t        |      | ||<    ||i |S  || g|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)r1   r}   r+   )r-   r   rW   r   targetmsgs         r'   piper     sd    4 $fVHKLCS/!vT$V$$C)$)&))rB   c                V      f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                    | v r|    S | S rP   rQ   )ro   mappers    r'   fzget_rename_function.<locals>.f
  s    ;!9HrB   )r1   r   r   r   )r   r   s   ` r'   get_rename_functionr     s'     6CKK#;<1H&HrB   c                    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.
    )
r1   r:   r2   r3   r   r   r   r   r   r   )rt   s    r'   convert_to_list_liker     sK     &4XyBSTU	FCLL	)*VS2IF|8OrB   c              #     K   t        | |      }t        | ||       	 |  t        | ||       y# t        | ||       w xY w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-   attrvalue	old_values       r'   temp_setattrr   "  sB      T"ICu&	T9%T9%s   A/ A>Ac                z    t        |       t        |      k7  r$t        dt        |        dt        |       d      y)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+   )dataindexs     r'   require_length_matchr   6  sI     4yCJD	{ E
|1
 	
 rB   rp   maxminrc   r9   meanprodstdvarmediancumprodcumsumc                ,    t         j                  |       S )zH
    if we define an internal function for this argument, return it
    )_cython_tablegetrT   s    r'   get_cython_funcr   i  s     S!!rB   c                .    t         j                  | |       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   p  s    
 c3''rB   c                X    t        |       D cg c]  \  }}|d| n| c}}S c c}}w )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.
    level_)	enumerate)namesir*   s      r'   fill_missing_namesr   x  s2      CLEBRSwq$DLfQCLd2SSSs   &c                B    | t         j                  u rd}|S | d}|S | }|S )a  Determine the Boolean value of numeric_only.

    See GH#46560 for details on the deprecation.

    Parameters
    ----------
    numeric_only : bool, None, or lib.no_default
        Value passed to the method.

    Returns
    -------
    Resolved value of numeric_only.
    TF)r   
no_default)numeric_onlyr   s     r'   resolve_numeric_onlyr     s@     s~~%  M 
	  M MrB   c                    |dv rd}nd}d| d| j                    d| d}|r	|d| d	z  }|d
| dz  }t        j                  |t        t	                      y)a  Emit FutureWarning message for deprecation of numeric_only.

    See GH#46560 for details on the deprecation.

    Parameters
    ----------
    cls : type
        pandas type that is generating the warning.
    name : str
        Name of the method that is generating the warning.
    deprecate_none : bool, default False
        Whether to also warn about the deprecation of specifying ``numeric_only=None``.
    )rc   r9   	bool_onlyr   zThe default value of z in .z? is deprecated. In a future version, it will default to False. zIn addition, specifying 'z=None' is deprecated. z2Select only valid columns or specify the value of z to silence this warning.rD   N)r   rG   rH   rI   r   )clsr*   deprecate_nonearg_namer   s        r'   deprecate_numeric_only_defaultr     s      ~!  zcll^1TF CF 	F  *8*4JKK
<XJ G 	C
 MM#}1A1CDrB   )r>   r   returnbool)F)rL   r   )r   r   )r   rJ   ).)rt   zArrayLike | list | tuple | zipr4   NpDtype | Noner   
np.ndarray)rt   r   r4   r   r   r   rP   )r   znp.ndarray | Iterabler4   r   r   r   )r-   zIterable[T] | Tr   zCollection[T] | T)r   z
list[bool])r%   rJ   r   r   )r   np.random.Generatorr   r   )r   zGint | ArrayLike | np.random.BitGenerator | np.random.RandomState | Noner   znp.random.RandomState)r   zRandomState | None)r   z/Callable[..., T] | tuple[Callable[..., T], str]r   r   )rt   z"Hashable | Iterable | AnyArrayLiker   zlist | AnyArrayLike)r   r   r   zIterator[None])r   r"   r   None)rT   r	   r   z
str | None)r   zSequence[Hashable | None]r   zlist[Hashable])r   zbool | None | lib.NoDefaultr   r   )r   r<   r*   r   r   r   r   r   )o__doc__
__future__r   builtinscollectionsr   r   
contextlib	functoolsr   r   typingr   r   r	   r
   r   r   r   r   r   r   rG   numpyr2   pandas._libsr   pandas._typingr   r   r   r   r   pandas.util._exceptionsr   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.   rA   rM   rX   r^   rd   rh   rl   rq   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   contextmanagerr   r   rp   r   maximumreducer   minimumr   rc   r9   nansumr   nanmeanr   nanprodr   nanstdr   nanvarr   	nanmediannanmaxnanminr   
nancumprodr   	nancumsumr   r   r   r   r   r   rQ   rB   r'   <module>r     s  
 #           5 K  
 = +04n64,,00, 
DG*3A 
 
 
D <@!*8:	I	""@ 
 
 
R 
5
p"*>"*"*JI. & &&

" LL"&&LL"**##LL"**##LL%LL% LL% FFE	
 FFE FFE IIu GGV JJ GGV JJ FFE IIu FFE IIu  IIx!" LL(#$ FFEIIuFFEIIuJJ	MM9IIxLL(3:"(T&8 27 E	 E E*. E	 ErB   