
    A>i^F                       S r SSKJr  SSKrSSKJrJr  SSKJrJ	r	J
r
JrJrJr  SSKrSSKJr  SSKrSSKrSSKJrJrJrJrJrJr  SSKrSSKJr  SS	KJr  SS
K J!r!J"r"  SSK#J$r$J%r%J&r&J'r'J(r(  SSK)J*r*  SSK+J,r,  \(       a  SSK-J.r.J/r/J0r0J1r1J2r2J3r3  SSK4J5r5  S r6S r7SAS jr8S r9S r:SBS jr;SBS jr<SBS jr=SBS jr>SCS jr?\ SD     SES jj5       r@\SDSFS jj5       r@SGSFS jjr@ SG     SHS jjrAS rBSIS jrCSBS  jrDSBS! jrESJS" jrFSKS# jrGS$ rHS% rIS& rJ\SLS' j5       rK\    SMS( j5       rKSGSNS) jjrK\" S*5      rL\          SOS+ j5       rM\          SPS, j5       rM          SQS- jrMS. rN    SRS/ jrO\R                  SSSTS0 jj5       rQSUS1 jrR0 \R                  S2_\R                  S3_\R                  S4_\R                  S5_\R                  S6_\R                  S2_\R                  S2_\R                  S7_\R                  S7_\R                  S8_\R                  S8_\R                  S9_\R                  S9_\R                  S:_\R                  S:_\R                  S;_\R                  S;_\R                  S3\R                  S3\R                  S4\R                  S4\R                  S<\R                  S<\R                  S=\R                  S=0EriSVS> jrjSWS? jrkS@ rlg)Xzh
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              #  t   #    U  H,  n[        U5      (       a  [        U5       Sh  vN   M(  Uv   M.     g N7f)z
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     Q/var/www/html/land-tabula/venv/lib/python3.13/site-packages/pandas/core/common.pyr&   r&   D   s2     " w''w'''M	 's   $868c                    U S   R                   nU SS   H  n UR                   U:w  a  S n  U$ M     U$ ! [         a    S n   U$ f = f)Nr      )name
ValueError)objsr,   objs      r)   consensus_name_attrr0   \   si    7<<DABx	xx4 K    K  	DK	s   4AAc                n   [        U [        [        R                  [        [
        [        45      (       a  [        U [        5      (       d  U R                  [        R                  :X  aZ  [        R                  " U 5      n[        R                  " U5      (       d(  Sn[        R                  " USS9(       a  [        U5      egg[        U R                  5      (       a  g g[        U [        5      (       aB  [!        U 5      S:  a3  [#        U 5      [        La  [        U 5      n [        R$                  " U 5      $ g)as  
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)key	key_arrayna_msgs      r)   is_bool_indexerrA   i   s    8 	BJJ*;=ST  m,,99

"

3I$$Y//X$$Yt< %V,,399%% &  
C		s8a<Cy$3i##C((    c                |    [         R                  " U 5      (       a   U R                  5       (       a  [        S5      eU $ )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_indexerrG      s8     ||CS^^--)
 	

 JrB   c                     S U  5       $ )zD
Returns a generator consisting of the arguments that are not None.
c              3  .   #    U  H  oc  M  Uv   M     g 7fN .0args     r)   	<genexpr>not_none.<locals>.<genexpr>   s     34CCC4s   	rK   argss    r)   not_nonerS      s     4433rB   c                 &    [        S U  5       5      $ )z7
Returns a boolean indicating if any argument is None.
c              3  (   #    U  H  oS L v   M
     g 7frJ   rK   rL   s     r)   rO   any_none.<locals>.<genexpr>        +dsd{d   anyrQ   s    r)   any_noner[           +d+++rB   c                 &    [        S U  5       5      $ )z9
Returns a boolean indicating if all arguments are None.
c              3  (   #    U  H  oS L v   M
     g 7frJ   rK   rL   s     r)   rO   all_none.<locals>.<genexpr>   rW   rX   allrQ   s    r)   all_nonerb      r\   rB   c                 &    [        S U  5       5      $ )z;
Returns a boolean indicating if any argument is not None.
c              3  (   #    U  H  oS Lv   M
     g 7frJ   rK   rL   s     r)   rO   any_not_none.<locals>.<genexpr>        /$3$$rX   rY   rQ   s    r)   any_not_nonerg           /$///rB   c                 &    [        S U  5       5      $ )z=
Returns a boolean indicating if all arguments are not None.
c              3  (   #    U  H  oS Lv   M
     g 7frJ   rK   rL   s     r)   rO   all_not_none.<locals>.<genexpr>   rf   rX   r`   rQ   s    r)   all_not_nonerl      rh   rB   c                 &    [        S U  5       5      $ )z3
Returns the count of arguments that are not None.
c              3  (   #    U  H  oS Lv   M
     g 7frJ   rK   )rM   xs     r)   rO   !count_not_none.<locals>.<genexpr>   s     +d}drX   )sumrQ   s    r)   count_not_nonerr      r\   rB   c                    g rJ   rK   valuesr6   s     r)   asarray_tuplesaferv      s     rB   c                    g rJ   rK   rt   s     r)   rv   rv      s    SVrB   c                   [        U [        [        45      (       d  [        U S5      (       d  [        U 5      n OB[        U [        5      (       a  U R
                  $ [        U [        5      (       a  U R
                  $ [        U [        5      (       a%  U[        R                  [        4;   a  [        U 5      $  [        R                  " XS9n[        UR                  R                  [         5      (       a  [        R                  " U [        S9nUR"                  S:X  a&  U  Vs/ s H  n[        U5      PM     n n[        U 5      nU$ ! [         a    [        U 5      s $ f = fs  snf )N	__array__r6      )r3   r:   tuplehasattrr   _valuesr   r4   r7   objectr   r8   r-   
issubclassr6   r<   strndim)ru   r6   resultro   s       r)   rv   rv      s   ve}--1M1Mf	FH	%	%~~	FI	&	&~~&$Ebjj&-A$A6v>>?F0 &,,##S))F&1{{a$*+Fq%(F+8@M  ?
 7v>>? ,s   6E  EEEc                    [        U [        [        45      (       a  U /n [        U [        [        R
                  45      (       d   [        U 5      n [        XS9nU$ ! [         a    U /n  Nf = f)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   )r3   r   r|   r:   r4   r5   	TypeErrorrv   )labelsr6   rlabelss      r)   index_labels_to_arrayr     si     &3,''ftRZZ011	&\F  4GN  	XF	s   A A+*A+c                H    U b  [        U [        [        45      (       d  U /$ U $ rJ   )r3   r|   r:   r/   s    r)   maybe_make_listr   +  s#    
z#t}==uJrB   c                    [        U [        R                  5      (       a*  [        U [        R                  5      (       d  [	        U 5      $ [        [        U 5      n U $ )z:
If obj is Iterable but not list-like, consume into list.
)r3   r   r
   Sizedr:   r   r   r   s    r)   maybe_iterable_to_listr   1  s@     #s||$$ZSYY-G-GCy
z3
CJrB   c                    [        U [        5      =(       a8    U R                  SL =(       a#    U R                  SL =(       a    U R                  SL $ )z
We have a null slice.
Nr3   slicestartstopstepr   s    r)   is_null_slicer   ;  sH    
 	3 	II	HH	 HH	rB   c                    [        U [        5      =(       aC    U R                  SL=(       a.    U R                  SL=(       a    U R                  U R                  :H  $ )z6
We have an empty slice, e.g. no values are selected.
N)r3   r   r   r   r   s    r)   is_empty_slicer   G  sL    
 	3 	"IIT!	"HHD 	" II!	rB   c              #  p   #    U  H,  n[        U[        5      =(       a    [        U5      (       + v   M.     g7f)z3
Find non-trivial slices in "line": yields a bool.
N)r3   r   r   )r'   ks     r)   is_true_slicesr   S  s+      E";=+;';; s   46c                    [        U [        5      =(       a:    U R                  S:H  =(       a$    U R                  U:H  =(       a    U R                  SL $ )z
We have a full length slice.
r   Nr   )r/   r'   s     r)   is_full_slicer   \  sG    
 	3 	IIN	HH	 HH	rB   c                    [        U S5      (       a  U R                  $ [        U [        5      (       a  [	        U R
                  5      $ [        U 5      (       a  [        U 5      R                  $ g )N__name__)r}   r   r3   r   get_callable_namefunccallabler<   r   s    r)   r   r   h  sS    sJ||#w **}}Cy!!!
 rB   c                    [        U [        5      (       a  U R                  " U40 UD6$ [        U 5      (       a	  U " U40 UD6$ U $ )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
)r3   r   _eval_expressionr   )maybe_callabler/   kwargss      r)   apply_if_callabler   y  sH     .*--..s=f==	.	!	!c,V,,rB   c                4   [         R                  " U 5      (       d:  [        U [        5      (       a  [	        [        U R
                  5      $ [        U 5      n [        U [        R                  5      (       d  [        SU  35      eU [        :X  a  [        S5      eU $ )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     sy    * ??4  dK((;(<(<==DzdCKK((,TF344{IJJKrB   c                    g rJ   rK   states    r)   random_stater     s    EHrB   c                    g rJ   rK   r   s    r)   r   r     s      rB   c                   [        U 5      (       d9  [        U [        R                  [        R                  R
                  45      (       a  [        R                  R                  U 5      $ [        U [        R                  R                  5      (       a  U $ [        U [        R                  R                  5      (       a  U $ U c  [        R                  $ [        S5      e)a9  
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

zdrandom_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    ( %Jurzz299;Q;Q.RSSyy$$U++	E29900	1	1	E299..	/	/	yy+
 	
rB   _Tc                    g rJ   rK   r/   r   rR   r   s       r)   piper          	rB   c                    g rJ   rK   r   s       r)   r   r     r   rB   c                    [        U[        5      (       a%  Uu  pEXS;   a  U S3n[        U5      eXU'   U" U0 UD6$ U" U /UQ70 UD6$ )a#  
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   rR   r   func_targetmsgs          r)   r   r     sa    : $HKLCS/!vd%f%%C)$)&))rB   c                b   ^  U 4S jn[        T [        R                  [        45      (       a  U$ T $ )zj
Returns a function that will map names/labels, dependent if mapper
is a dict, Series or just a function.
c                   > U T;   a  TU    $ U $ rJ   rK   )ro   mappers    r)   fget_rename_function.<locals>.f  s    ;!9HrB   )r3   r   r   r   )r   r   s   ` r)   get_rename_functionr     s*     6CKK#;<<1H&HrB   c                    [        U [        [        R                  [        [
        [        45      (       a  U $ [        U [        R                  5      (       a   [        U [        5      (       d  [        U 5      $ U /$ )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   )ru   s    r)   convert_to_list_liker   &  sT     &4XyBSTUU	FCLL	)	)*VS2I2IF|8OrB   c              #     #    U(       a  [        X5      n[        XU5         U v   U(       a  [        XW5        gg! U(       a  [        XW5        f f = f7f)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)r/   attrvalue	condition	old_values        r)   temp_setattrr   5  sL     * C&	5!*	Cy) 9Cy) s   A; AAAc                |    [        U 5      [        U5      :w  a$  [        S[        U 5       S[        U5       S35      eg)z;
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   T  sI     4yCJD	{ E
|1
 	
 rB   rq   maxminra   rZ   meanprodstdvarmediancumprodcumsumc                ,    [         R                  U 5      $ )z@
if we define an internal function for this argument, return it
)_cython_tableget)rN   s    r)   get_cython_funcr   ~  s     S!!rB   c                ^    [        U 5       VVs/ s H  u  pUc  SU 3OUPM     snn$ s  snnf )z
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.
level_)	enumerate)namesir,   s      r)   fill_missing_namesr     s6     CLEBRSBRwqDLfQCLd2BRSSSs   )c                ~    [         R                  " S5      nUR                  R                  5        H	  nX L d  M	    g   g)aQ  
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_localsru   )r/   framevs      r)   is_local_in_caller_framer     s6    & MM!E^^""$8 % rB   )r>   r   returnbool)r   r   )r   int).)ru   zArrayLike | list | tuple | zipr6   NpDtype | Noner   
np.ndarray)ru   r
   r6   r   r   r   rJ   )r   znp.ndarray | Iterabler6   r   r   r   )r/   zIterable[T] | Tr   zCollection[T] | T)r'   zabc.Iterabler   zabc.Generator[bool, None, None])r'   r   r   r   )r   np.random.Generatorr   r   )r   zHint | np.ndarray | np.random.BitGenerator | np.random.RandomState | Noner   znp.random.RandomState)r   zRandomState | None)
r/   r   r   zCallable[Concatenate[_T, P], T]rR   zP.argsr   zP.kwargsr   r#   )
r/   r   r   ztuple[Callable[..., T], str]rR   r   r   r   r   r#   )
r/   r   r   z>Callable[Concatenate[_T, P], T] | tuple[Callable[..., T], str]rR   r   r   r   r   r#   )ru   z"Hashable | Iterable | AnyArrayLiker   zlist | AnyArrayLike)T)r   r   r   r   r   zGenerator[None])r   r$   r   None)rN   r   r   z
str | None)r   zSequence[Hashable | None]r   zlist[Hashable])m__doc__
__future__r   builtinscollectionsr   r   collections.abcr   r   r   r	   r
   r   
contextlib	functoolsr   r   r   typingr   r   r   r   r   r   numpyr4   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&   r0   rA   rG   rS   r[   rb   rg   rl   rr   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   contextmanagerr   r   rq   r   r   ra   rZ   nansumr   nanmeanr   nanprodr   nanstdr   nanvarr   	nanmediannanmaxnanminr   
nancumprodr   	nancumsumr   r   r   r   rK   rB   r)   <module>r     s   #      
    K  = &  0
5p,4,,00, 
DG*3A 
 
 V 
 V@ <@!*8:		<	"&@ 
 H 
 H 
 S   
 
 
F T] 
	
)  	
  
 
	
&  	
  
&*	&*
H&* &* 	&*
 &*RI. * *<

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"rB   