
    Mh                       S r SSKJr  SSKrSSKrSSKJr  SSKJrJ	r	J
r
  SSKrSSKrSSKJrJrJrJr  SSKJrJrJrJrJrJ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'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1  SSK2J3r3  SSK4J5r5J6r6J7r7J8r8  SSK9J:r:J;r;J<r<J=r=J>r>J?r?  SSK@JArAJBrB  SSKCJDrD  SSKEJFrGJHrHJIrI  SSKJJKrK  \(       a  SSKJLrLJMrMJNrN  SSKOJPrPJQrQJRrR  SSKSJTrTJUrU  S6S jrV        S7S jrWS8S jrX\R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  S.rgS9S jrhS:S jriS rjS;S jrkS<S=S jjrl\jrmSrnS>S  jro    S?           S@S! jjrp\" \" S"5      \" S#5      \" S$5      S%9   SA       SBS& jj5       rq     SC         SDS' jjrr     SC         SDS( jjrs S<       SES) jjrt  SF       SGS* jjru SH       SIS+ jjrv     SJ             SKS, jjrw   SL     SMS- jjrx  SN         SOS. jjry1 S/krzSPSQS0 jjr{    SR           SSS1 jjr|STS2 jr}SUS3 jr~      SVS4 jr  SW       SXS5 jjrg)Yzl
Generic data algorithms. This module is experimental at the moment and not
intended for public consumption
    )annotationsN)dedent)TYPE_CHECKINGLiteralcast)algos	hashtableiNaTlib)AnyArrayLike	ArrayLikeAxisIntDtypeObjTakeIndexernpt)doc)find_stack_level)'construct_1d_object_array_from_listlikenp_find_common_type)ensure_float64ensure_objectensure_platform_intis_array_likeis_bool_dtypeis_complex_dtypeis_dict_likeis_extension_array_dtypeis_float_dtype
is_integeris_integer_dtypeis_list_likeis_object_dtypeis_signed_integer_dtypeneeds_i8_conversion)concat_compat)BaseMaskedDtypeCategoricalDtypeExtensionDtypeNumpyEADtype)ABCDatetimeArrayABCExtensionArrayABCIndexABCMultiIndex	ABCSeriesABCTimedeltaArray)isnana_value_for_dtype)take_nd)arrayensure_wrapped_if_datetimelikeextract_array)validate_indices)ListLikeNumpySorterNumpyValueArrayLike)CategoricalIndexSeries)BaseMaskedArrayExtensionArrayc                :   [        U [        5      (       d
  [        U SS9n [        U R                  5      (       a  [        [        R                  " U 5      5      $ [        U R                  [        5      (       aH  [        SU 5      n U R                  (       d  [        U R                  5      $ [        R                  " U 5      $ [        U R                  [        5      (       a  [        SU 5      n U R                  $ [        U R                  5      (       ah  [        U [        R                   5      (       a%  [        R                  " U 5      R#                  S5      $ [        R                  " U 5      R%                  SSS9$ ['        U R                  5      (       a  [        R                  " U 5      $ [)        U R                  5      (       a;  U R                  R*                  S;   a  [-        U 5      $ [        R                  " U 5      $ [/        U R                  5      (       a  [        [        R                   U 5      $ [1        U R                  5      (       a-  U R#                  S	5      n[        [        R                   U5      nU$ [        R                  " U [2        S
9n [        U 5      $ )aD  
routine to ensure that our data is of the correct
input dtype for lower-level routines

This will coerce:
- ints -> int64
- uint -> uint64
- bool -> uint8
- datetimelike -> i8
- datetime64tz -> i8 (in local tz)
- categorical -> codes

Parameters
----------
values : np.ndarray or ExtensionArray

Returns
-------
np.ndarray
Textract_numpyr=   r:   uint8Fcopy)         i8dtype)
isinstancer-   r5   r"   rJ   r   npasarrayr&   r   _hasna_ensure_data_datar'   codesr   ndarrayviewastyper    r   itemsizer   r   r$   object)valuesnpvaluess     H/var/www/html/env/lib/python3.13/site-packages/pandas/core/algorithms.pyrO   rO   j   s   , fm,,vT:v||$$RZZ/00	FLL/	2	2'0}}  --zz&!!	FLL"2	3	3 mV,||	v||	$	$fbjj))::f%**733 ::f%,,W5,AA	&,,	'	'zz&!!		%	% <<  K/!&))zz&!!	&,,	'	'BJJ'' 
V\\	*	*;;t$

H- ZZf-F      c                    [        U [        5      (       a  U R                  U:X  a  U $ [        U[        R                  5      (       d!  UR	                  5       nUR                  XS9n U $ U R                  USS9n U $ )z
reverse of _ensure_data

Parameters
----------
values : np.ndarray or ExtensionArray
dtype : np.dtype or ExtensionDtype
original : AnyArrayLike

Returns
-------
ExtensionArray or np.ndarray
rI   FrC   )rK   r+   rJ   rL   construct_array_type_from_sequencerT   )rW   rJ   originalclss       rY   _reconstruct_datar`      sv      &+,,1FeRXX&& ((*##F#8
 M u51MrZ   c                v   [        U [        [        [        [        R
                  45      (       d  US:w  a%  [        R                  " U S3[        [        5       S9  [        R                  " U SS9nUS;   a-  [        U [        5      (       a  [        U 5      n [        U 5      n U $ [        R                  " U 5      n U $ )z-
ensure that we are arraylike if not already
isin-targetsz with argument that is not not a Series, Index, ExtensionArray, or np.ndarray is deprecated and will raise in a future version.
stacklevelFskipna)mixedstringmixed-integer)rK   r,   r.   r+   rL   rR   warningswarnFutureWarningr   r   infer_dtypetuplelistr   rM   )rW   	func_nameinferreds      rY   _ensure_arraylikerr      s     fx4ErzzRSS&MM+ " " +- ??6%8;;&%((f<VDF M ZZ'FMrZ   )
complex128	complex64float64float32uint64uint32uint16rB   int64int32int16int8rh   rV   c                F    [        U 5      n [        U 5      n[        U   nX 4$ )zi
Parameters
----------
values : np.ndarray

Returns
-------
htable : HashTable subclass
values : ndarray
)rO   _check_object_for_strings_hashtables)rW   ndtyper	   s      rY   _get_hashtable_algor     s+     &!F&v.FF#IrZ   c                v    U R                   R                  nUS:X  a  [        R                  " U SS9(       a  SnU$ )z
Check if we can use string hashtable instead of object hashtable.

Parameters
----------
values : ndarray

Returns
-------
str
rV   Fre   rh   )rJ   namer   is_string_array)rW   r   s     rY   r   r     s7     \\F ve4FMrZ   c                    [        U 5      $ )a	  
Return unique values based on a hash table.

Uniques are returned in order of appearance. This does NOT sort.

Significantly faster than numpy.unique for long enough sequences.
Includes NA values.

Parameters
----------
values : 1d array-like

Returns
-------
numpy.ndarray or ExtensionArray

    The return can be:

    * Index : when the input is an Index
    * Categorical : when the input is a Categorical dtype
    * ndarray : when the input is a Series/ndarray

    Return numpy.ndarray or ExtensionArray.

See Also
--------
Index.unique : Return unique values from an Index.
Series.unique : Return unique values of Series object.

Examples
--------
>>> pd.unique(pd.Series([2, 1, 3, 3]))
array([2, 1, 3])

>>> pd.unique(pd.Series([2] + [1] * 5))
array([2, 1])

>>> pd.unique(pd.Series([pd.Timestamp("20160101"), pd.Timestamp("20160101")]))
array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]')

>>> pd.unique(
...     pd.Series(
...         [
...             pd.Timestamp("20160101", tz="US/Eastern"),
...             pd.Timestamp("20160101", tz="US/Eastern"),
...         ]
...     )
... )
<DatetimeArray>
['2016-01-01 00:00:00-05:00']
Length: 1, dtype: datetime64[ns, US/Eastern]

>>> pd.unique(
...     pd.Index(
...         [
...             pd.Timestamp("20160101", tz="US/Eastern"),
...             pd.Timestamp("20160101", tz="US/Eastern"),
...         ]
...     )
... )
DatetimeIndex(['2016-01-01 00:00:00-05:00'],
        dtype='datetime64[ns, US/Eastern]',
        freq=None)

>>> pd.unique(np.array(list("baabc"), dtype="O"))
array(['b', 'a', 'c'], dtype=object)

An unordered Categorical will return categories in the
order of appearance.

>>> pd.unique(pd.Series(pd.Categorical(list("baabc"))))
['b', 'a', 'c']
Categories (3, object): ['a', 'b', 'c']

>>> pd.unique(pd.Series(pd.Categorical(list("baabc"), categories=list("abc"))))
['b', 'a', 'c']
Categories (3, object): ['a', 'b', 'c']

An ordered Categorical preserves the category ordering.

>>> pd.unique(
...     pd.Series(
...         pd.Categorical(list("baabc"), categories=list("abc"), ordered=True)
...     )
... )
['b', 'a', 'c']
Categories (3, object): ['a' < 'b' < 'c']

An array of tuples

>>> pd.unique(pd.Series([("a", "b"), ("b", "a"), ("a", "c"), ("b", "a")]).values)
array([('a', 'b'), ('b', 'a'), ('a', 'c')], dtype=object)
)unique_with_mask)rW   s    rY   uniquer   3  s    | F##rZ   c                    [        U 5      S:X  a  g[        U 5      n [        R                  " U R	                  5       R                  S5      5      S:g  R                  5       nU$ )a   
Return the number of unique values for integer array-likes.

Significantly faster than pandas.unique for long enough sequences.
No checks are done to ensure input is integral.

Parameters
----------
values : 1d array-like

Returns
-------
int : The number of unique values in ``values``
r   intp)lenrO   rL   bincountravelrT   sum)rW   results     rY   nunique_intsr     sO     6{a&!Fkk&,,.//78A=BBDFMrZ   c                   [        U SS9n [        U R                  [        5      (       a  U R	                  5       $ U n[        U 5      u  p0U" [        U 5      5      nUc)  UR	                  U 5      n[        XRR                  U5      nU$ UR	                  XS9u  pQ[        XRR                  U5      nUc   eXQR                  S5      4$ )z?See algorithms.unique for docs. Takes a mask for masked arrays.r   rp   maskbool)	rr   rK   rJ   r(   r   r   r   r`   rT   )rW   r   r^   r	   tableuniquess         rY   r   r     s    v:F&,,//}}H+F3Ic&k"E|,,v&#G^^XF V7#G^^XFF+++rZ   i@B c                f   [        U 5      (       d"  [        S[        U 5      R                   S35      e[        U5      (       d"  [        S[        U5      R                   S35      e[	        U[
        [        [        [        R                  45      (       dZ  [        U5      n[        USS9n[        U5      S:  a5  UR                  R                  S;   a  [        U 5      (       d  [!        U5      nO7[	        U["        5      (       a  [        R$                  " U5      nO['        USSS9n[        U S	S9n['        USS
9n[	        U[        R                  5      (       d  UR)                  U5      $ [+        UR                  5      (       a  [-        U5      R)                  U5      $ [+        UR                  5      (       a=  [/        UR                  5      (       d#  [        R0                  " UR2                  [4        S9$ [+        UR                  5      (       a  [)        X1R7                  [8        5      5      $ [	        UR                  [:        5      (       a4  [)        [        R<                  " U5      [        R<                  " U5      5      $ [        U5      [>        :  aI  [        U5      S::  a:  UR                  [8        :w  a&  [A        U5      RC                  5       (       a  S nOTS nOP[E        UR                  UR                  5      nUR7                  USS9nUR7                  USS9n[F        RH                  nU" X15      $ )z
Compute the isin boolean array.

Parameters
----------
comps : list-like
values : list-like

Returns
-------
ndarray[bool]
    Same length as `comps`.
zIonly list-like objects are allowed to be passed to isin(), you passed a ``rb   r   r   iufcbT)rA   extract_rangeisinr@   rI      c                    [         R                  " [         R                  " X5      R                  5       [         R                  " U 5      5      $ N)rL   
logical_orr   r   isnan)cvs     rY   fisin.<locals>.f  s,    }}RWWQ]%8%8%:BHHQKHHrZ   c                J    [         R                  " X5      R                  5       $ r   )rL   r   r   )abs     rY   <lambda>isin.<locals>.<lambda>  s    RWWQ]002rZ   FrC   )%r!   	TypeErrortype__name__rK   r,   r.   r+   rL   rR   ro   rr   r   rJ   kindr#   r   r-   r3   r5   r   r$   pd_arrayr"   zerosshaper   rT   rV   r(   rM   _MINIMUM_COMP_ARR_LENr0   anyr   htableismember)compsrW   orig_valuescomps_arrayr   commons         rY   r   r     s    ((,U(<(<'=Q@
 	
 ((,V(=(='>aA
 	

 fx4ErzzRSS6l";.I K!O!!W,+E22 =[IF	FM	*	*&!vTN#EV<K4@Kk2::..''	[..	/	/$))&11	V\\	*	*?;CTCT3U3Uxx))66	V\\	*	*Kv!677	FLL.	1	1BJJ{+RZZ-?@@ 	K00K2' <I 3A %V\\;3D3DEvE2!((e(<OO[!!rZ   c                   U nU R                   R                  S;   a  [        n[        U 5      u  p`U" U=(       d    [	        U 5      5      nUR                  U SUUUS9u  p[        XR                   U5      n[        U	5      n	X4$ )a  
Factorize a numpy array to codes and uniques.

This doesn't do any coercion of types or unboxing before factorization.

Parameters
----------
values : ndarray
use_na_sentinel : bool, default True
    If True, the sentinel -1 will be used for NaN values. If False,
    NaN values will be encoded as non-negative integers and will not drop the
    NaN from the uniques of the values.
size_hint : int, optional
    Passed through to the hashtable's 'get_labels' method
na_value : object, optional
    A value in `values` to consider missing. Note: only use this
    parameter when you know that you don't have any values pandas would
    consider missing in the array (NaN for float data, iNaT for
    datetimes, etc.).
mask : ndarray[bool], optional
    If not None, the mask is used as indicator for missing values
    (True = missing, False = valid) instead of `na_value` or
    condition "val != val".

Returns
-------
codes : ndarray[np.intp]
uniques : ndarray
mM)na_sentinelna_valuer   	ignore_na)rJ   r   r
   r   r   	factorizer`   r   )
rW   use_na_sentinel	size_hintr   r   r^   
hash_klassr   r   rQ   s
             rY   factorize_arrayr   $  s    H H||D 
 ,V4Jy/CK0E__! % NG  BG&E>rZ   z    values : sequence
        A 1-D sequence. Sequences that aren't pandas objects are
        coerced to ndarrays before factorization.
    zt    sort : bool, default False
        Sort `uniques` and shuffle `codes` to maintain the
        relationship.
    zG    size_hint : int, optional
        Hint to the hashtable sizer.
    )rW   sortr   c                   [        U [        [        45      (       a  U R                  XS9$ [	        U SS9n U n[        U [
        [        45      (       a!  U R                  b  U R                  US9u  pVXV4$ [        U [        R                  5      (       d  U R                  US9u  pVO[        R                  " U 5      n U(       d_  U R                  [        :X  aK  [        U 5      nUR                  5       (       a+  [        U R                  SS9n[        R                   " XxU 5      n [#        U UUS9u  pVU(       a  [%        U5      S	:  a  ['        UUUS
SS9u  pe[)        XdR                  U5      nXV4$ )a  
Encode the object as an enumerated type or categorical variable.

This method is useful for obtaining a numeric representation of an
array when all that matters is identifying distinct values. `factorize`
is available as both a top-level function :func:`pandas.factorize`,
and as a method :meth:`Series.factorize` and :meth:`Index.factorize`.

Parameters
----------
{values}{sort}
use_na_sentinel : bool, default True
    If True, the sentinel -1 will be used for NaN values. If False,
    NaN values will be encoded as non-negative integers and will not drop the
    NaN from the uniques of the values.

    .. versionadded:: 1.5.0
{size_hint}
Returns
-------
codes : ndarray
    An integer ndarray that's an indexer into `uniques`.
    ``uniques.take(codes)`` will have the same values as `values`.
uniques : ndarray, Index, or Categorical
    The unique valid values. When `values` is Categorical, `uniques`
    is a Categorical. When `values` is some other pandas object, an
    `Index` is returned. Otherwise, a 1-D ndarray is returned.

    .. note::

       Even if there's a missing value in `values`, `uniques` will
       *not* contain an entry for it.

See Also
--------
cut : Discretize continuous-valued array.
unique : Find the unique value in an array.

Notes
-----
Reference :ref:`the user guide <reshaping.factorize>` for more examples.

Examples
--------
These examples all show factorize as a top-level method like
``pd.factorize(values)``. The results are identical for methods like
:meth:`Series.factorize`.

>>> codes, uniques = pd.factorize(np.array(['b', 'b', 'a', 'c', 'b'], dtype="O"))
>>> codes
array([0, 0, 1, 2, 0])
>>> uniques
array(['b', 'a', 'c'], dtype=object)

With ``sort=True``, the `uniques` will be sorted, and `codes` will be
shuffled so that the relationship is the maintained.

>>> codes, uniques = pd.factorize(np.array(['b', 'b', 'a', 'c', 'b'], dtype="O"),
...                               sort=True)
>>> codes
array([1, 1, 0, 2, 1])
>>> uniques
array(['a', 'b', 'c'], dtype=object)

When ``use_na_sentinel=True`` (the default), missing values are indicated in
the `codes` with the sentinel value ``-1`` and missing values are not
included in `uniques`.

>>> codes, uniques = pd.factorize(np.array(['b', None, 'a', 'c', 'b'], dtype="O"))
>>> codes
array([ 0, -1,  1,  2,  0])
>>> uniques
array(['b', 'a', 'c'], dtype=object)

Thus far, we've only factorized lists (which are internally coerced to
NumPy arrays). When factorizing pandas objects, the type of `uniques`
will differ. For Categoricals, a `Categorical` is returned.

>>> cat = pd.Categorical(['a', 'a', 'c'], categories=['a', 'b', 'c'])
>>> codes, uniques = pd.factorize(cat)
>>> codes
array([0, 0, 1])
>>> uniques
['a', 'c']
Categories (3, object): ['a', 'b', 'c']

Notice that ``'b'`` is in ``uniques.categories``, despite not being
present in ``cat.values``.

For all other pandas objects, an Index of the appropriate type is
returned.

>>> cat = pd.Series(['a', 'a', 'c'])
>>> codes, uniques = pd.factorize(cat)
>>> codes
array([0, 0, 1])
>>> uniques
Index(['a', 'c'], dtype='object')

If NaN is in the values, and we want to include NaN in the uniques of the
values, it can be achieved by setting ``use_na_sentinel=False``.

>>> values = np.array([1, 2, 1, np.nan])
>>> codes, uniques = pd.factorize(values)  # default: use_na_sentinel=True
>>> codes
array([ 0,  1,  0, -1])
>>> uniques
array([1., 2.])

>>> codes, uniques = pd.factorize(values, use_na_sentinel=False)
>>> codes
array([0, 1, 0, 2])
>>> uniques
array([ 1.,  2., nan])
)r   r   r   r   )r   )r   F)compat)r   r   r   T)r   assume_uniqueverify)rK   r,   r.   r   rr   r*   r/   freqrL   rR   rM   rJ   rV   r0   r   r1   wherer   r   	safe_sortr`   )	rW   r   r   r   r^   rQ   r   	null_maskr   s	            rY   r   r   b  sQ   p &8Y/00TKKv=FH 	6,.?@AAKK#  ))t)4~

++))/)Jw F#6<<6#9
 VI}}-fll5I)v>(+
 Gq "+
  BG>rZ   c           	     b    [         R                  " S[        [        5       S9  [	        U UUUUUS9$ )a  
Compute a histogram of the counts of non-null values.

Parameters
----------
values : ndarray (1-d)
sort : bool, default True
    Sort by values
ascending : bool, default False
    Sort in ascending order
normalize: bool, default False
    If True then compute a relative histogram
bins : integer, optional
    Rather than count values, group them into half-open bins,
    convenience for pd.cut, only works with numeric data
dropna : bool, default True
    Don't include counts of NaN

Returns
-------
Series
zupandas.value_counts is deprecated and will be removed in a future version. Use pd.Series(obj).value_counts() instead.rc   )r   	ascending	normalizebinsdropna)rj   rk   rl   r   value_counts_internal)rW   r   r   r   r   r   s         rY   value_countsr   /  s@    < MM	E#% ! rZ   c                   SSK JnJn  [        U SS 5      nU(       a  SOSn	Ub  SSKJn
  [        X5      (       a  U R                  n  U
" XSS9nUR                  US
9nXl
        XR                  R                  5          nUR                  R                  S5      Ul        UR                  5       nU(       a1  UR                  S:H  R                  5       (       a  UR                   SS n["        R$                  " ['        U5      /5      nGO[)        U 5      (       aw  U" U SS9R                  R                  US
9nXl
        XR                  l
        UR                  n[        U["        R*                  5      (       d  ["        R,                  " U5      nGOt[        U [.        5      (       ag  [1        [3        U R4                  5      5      nU" X	S9R7                  XS9R9                  5       nU R:                  UR                  l        UR                  nO[=        U SS9n [?        X5      u  nnnUR@                  ["        RB                  :X  a  UR                  ["        RD                  5      nU" U5      nUR@                  [F        :X  a*  UR@                  [H        :X  a  UR                  [H        5      nOLUR@                  UR@                  :w  a2  UR@                  S:w  a"  [J        RL                  " S[N        [Q        5       S9  UUl
        U" UUU	SS9nU(       a  URS                  US9nU(       a  XRU                  5       -  nU$ ! [         a  n[        S	5      UeS nAff = f)Nr   )r;   r<   r   
proportioncount)cutT)include_lowestz+bins argument only works with numeric data.r   intervalFrC   )indexr   )levelr   r   r   zstring[pyarrow_numpy]zThe behavior of value_counts with object-dtype is deprecated. In a future version, this will *not* perform dtype inference on the resulting index. To retain the old behavior, use `result.index = result.index.infer_objects()`rc   )r   r   rD   )r   )+pandasr;   r<   getattrpandas.core.reshape.tiler   rK   _valuesr   r   r   r   notnarT   
sort_indexallilocrL   r3   r   r   rR   rM   r-   ro   rangenlevelsgroupbysizenamesrr   value_counts_arraylikerJ   float16rv   r   rV   rj   rk   rl   r   sort_valuesr   )rW   r   r   r   r   r   r;   r<   
index_namer   r   iierrr   countslevelskeys_idxs                      rY   r   r   ^  s   
 .J$<'D0f%%^^F	TV$7B
 /**,-||**:6""$ v~~*//11[[1%F 3r7)$ $F++F/77DDFDSFK *LL^^Ffbjj11F+..%/0FV/v5 
 "(FLL^^F 'vHF4VDOD&!zzRZZ'{{2::. +CyyD TZZ6%9jj(		TZZ'II!88D "/1 "CHF#DuEF##i#8**,&MS  	TIJPSS	Ts   L5 5
M?MMc                    U n[        U 5      n [        R                  " XUS9u  pEn[        UR                  5      (       a  U(       a  U[
        :g  nXB   XR   pT[        XCR                  U5      nXuU4$ )z
Parameters
----------
values : np.ndarray
dropna : bool
mask : np.ndarray[bool] or None, default None

Returns
-------
uniques : np.ndarray
counts : np.ndarray[np.int64]
r   )rO   r   value_countr$   rJ   r
   r`   )rW   r   r   r^   r   r   
na_counterres_keyss           rY   r   r     sm     H&!F%11&tLD*8>>** 4<D:v|& ~~x@HZ''rZ   c                B    [        U 5      n [        R                  " XUS9$ )a4  
Return boolean ndarray denoting duplicate values.

Parameters
----------
values : np.ndarray or ExtensionArray
    Array over which to check for duplicate values.
keep : {'first', 'last', False}, default 'first'
    - ``first`` : Mark duplicates as ``True`` except for the first
      occurrence.
    - ``last`` : Mark duplicates as ``True`` except for the last
      occurrence.
    - False : Mark all duplicates as ``True``.
mask : ndarray[bool], optional
    array indicating which elements to exclude from checking

Returns
-------
duplicated : ndarray[bool]
)keepr   )rO   r   
duplicated)rW   r   r   s      rY   r   r     s!    2 &!FVT::rZ   c                   [        U SS9n U n[        U R                  5      (       a&  [        U 5      n [	        SU 5      n U R                  US9$ [        U 5      n [        R                  " XUS9u  pEUb  XE4$  [        R                  " U5      n[        XCR                  U5      nU$ ! [         a*  n[        R                  " SU 3[        5       S9   SnANGSnAff = f)	z
Returns the mode(s) of an array.

Parameters
----------
values : array-like
    Array over which to check for duplicate values.
dropna : bool, default True
    Don't consider counts of NaN/NaT.

Returns
-------
np.ndarray or ExtensionArray
moder   r>   r   )r   r   NzUnable to sort modes: rc   )rr   r$   rJ   r4   r   _moderO   r   r   rL   r   r   rj   rk   r   r`   )rW   r   r   r^   npresultres_maskr   r   s           rY   r   r     s    " v8FH6<<((/7&/||6|**&!FVFH!!
778$ xBFM  
$SE*')	

s   6B$ $
C. CCc           
        [        U R                  5      n[        U 5      n U R                  S:X  a  [        R
                  " U UUUUUS9nU$ U R                  S:X  a  [        R                  " U UUUUUUS9nU$ [        S5      e)a  
Rank the values along a given axis.

Parameters
----------
values : np.ndarray or ExtensionArray
    Array whose values will be ranked. The number of dimensions in this
    array must not exceed 2.
axis : int, default 0
    Axis over which to perform rankings.
method : {'average', 'min', 'max', 'first', 'dense'}, default 'average'
    The method by which tiebreaks are broken during the ranking.
na_option : {'keep', 'top'}, default 'keep'
    The method by which NaNs are placed in the ranking.
    - ``keep``: rank each NaN value with a NaN ranking
    - ``top``: replace each NaN with either +/- inf so that they
               there are ranked at the top
ascending : bool, default True
    Whether or not the elements should be ranked in ascending order.
pct : bool, default False
    Whether or not to the display the returned rankings in integer form
    (e.g. 1, 2, 3) or in percentile form (e.g. 0.333..., 0.666..., 1).
   )is_datetimeliketies_methodr   	na_optionpctrE   )axisr  r  r   r  r  z&Array with ndim > 2 are not supported.)r$   rJ   rO   ndimr   rank_1drank_2dr   )rW   r  methodr  r   r  r  rankss           rY   rankr  +  s    > *&,,7O&!F{{a+
* L 
	+
 L @AArZ   c                   [        U [        R                  [        [        [
        45      (       d"  [        R                  " S[        [        5       S9  [        U 5      (       d  [        R                  " U 5      n [        U5      nU(       a&  [        XR                  U   5        [        XUSUS9nU$ U R!                  XS9nU$ )a  
Take elements from an array.

Parameters
----------
arr : array-like or scalar value
    Non array-likes (sequences/scalars without a dtype) are coerced
    to an ndarray.

    .. deprecated:: 2.1.0
        Passing an argument other than a numpy.ndarray, ExtensionArray,
        Index, or Series is deprecated.

indices : sequence of int or one-dimensional np.ndarray of int
    Indices to be taken.
axis : int, default 0
    The axis over which to select values.
allow_fill : bool, default False
    How to handle negative values in `indices`.

    * False: negative values in `indices` indicate positional indices
      from the right (the default). This is similar to :func:`numpy.take`.

    * True: negative values in `indices` indicate
      missing values. These values are set to `fill_value`. Any other
      negative values raise a ``ValueError``.

fill_value : any, optional
    Fill value to use for NA-indices when `allow_fill` is True.
    This may be ``None``, in which case the default NA value for
    the type (``self.dtype.na_value``) is used.

    For multi-dimensional `arr`, each *element* is filled with
    `fill_value`.

Returns
-------
ndarray or ExtensionArray
    Same type as the input.

Raises
------
IndexError
    When `indices` is out of bounds for the array.
ValueError
    When the indexer contains negative values other than ``-1``
    and `allow_fill` is True.

Notes
-----
When `allow_fill` is False, `indices` may be whatever dimensionality
is accepted by NumPy for `arr`.

When `allow_fill` is True, `indices` should be 1-D.

See Also
--------
numpy.take : Take elements from an array along an axis.

Examples
--------
>>> import pandas as pd

With the default ``allow_fill=False``, negative numbers indicate
positional indices from the right.

>>> pd.api.extensions.take(np.array([10, 20, 30]), [0, 0, -1])
array([10, 10, 30])

Setting ``allow_fill=True`` will place `fill_value` in those positions.

>>> pd.api.extensions.take(np.array([10, 20, 30]), [0, 0, -1], allow_fill=True)
array([10., 10., nan])

>>> pd.api.extensions.take(np.array([10, 20, 30]), [0, 0, -1], allow_fill=True,
...      fill_value=-10)
array([ 10,  10, -10])
zpd.api.extensions.take accepting non-standard inputs is deprecated and will raise in a future version. Pass either a numpy.ndarray, ExtensionArray, Index, or Series instead.rc   T)r  
allow_fill
fill_value)r  )rK   rL   rR   r+   r,   r.   rj   rk   rl   r   r   rM   r   r6   r   r2   take)arrindicesr  r  r  r   s         rY   r  r  k  s    j cBJJ(98YOPP8 ')	
 jjo!'*G))D/2t
 M '-MrZ   c                "   Ub  [        U5      n[        U [        R                  5      (       GaG  U R                  R
                  S;   Ga,  [        U5      (       d  [        U5      (       Ga  [        R                  " U R                  R                  5      n[        U5      (       a  [        R                  " U/5      O[        R                  " U5      nXTR                  :  R                  5       (       a.  XTR                  :*  R                  5       (       a  U R                  nOUR                  n[        U5      (       a   [        [        UR                  U5      5      nO$[!        [        ["        U5      US9nO[%        U 5      n U R'                  XUS9$ )ao  
Find indices where elements should be inserted to maintain order.

Find the indices into a sorted array `arr` (a) such that, if the
corresponding elements in `value` were inserted before the indices,
the order of `arr` would be preserved.

Assuming that `arr` is sorted:

======  ================================
`side`  returned index `i` satisfies
======  ================================
left    ``arr[i-1] < value <= self[i]``
right   ``arr[i-1] <= value < self[i]``
======  ================================

Parameters
----------
arr: np.ndarray, ExtensionArray, Series
    Input array. If `sorter` is None, then it must be sorted in
    ascending order, otherwise `sorter` must be an array of indices
    that sort it.
value : array-like or scalar
    Values to insert into `arr`.
side : {'left', 'right'}, optional
    If 'left', the index of the first suitable location found is given.
    If 'right', return the last such index.  If there is no suitable
    index, return either 0 or N (where N is the length of `self`).
sorter : 1-D array-like, optional
    Optional array of integer indices that sort array a into ascending
    order. They are typically the result of argsort.

Returns
-------
array of ints or int
    If value is array-like, array of insertion points.
    If value is scalar, a single integer.

See Also
--------
numpy.searchsorted : Similar method from NumPy.
iurI   )sidesorter)r   rK   rL   rR   rJ   r   r   r    iinfor   r3   minr   maxr   intr   r   r4   searchsorted)r  valuer  r  r  	value_arrrJ   s          rY   r  r    s    ` $V, 	3

##IINNd""25"9"9 ()3E):):BHHeW%	"''))yII/E.J.J.L.L IIEOOEeejj/0ET)U35AE -S1 EV<<rZ   >   r}   r|   r{   rz   rv   ru   c                   [        U5      n[        R                  nU R                  n[	        U5      nU(       a  [
        R                  nO[
        R                  n[        U[        5      (       a  U R                  5       n U R                  n[        U [        R                  5      (       d  [        U SUR                   S35      (       aA  US:w  a$  [        S[        U 5      R                   SU 35      eU" X R!                  U5      5      $ [#        [        U 5      R                   S35      eSnU R                  R$                  S;   a*  [        R&                  nU R)                  S5      n [*        nS	nOcU(       a  [        R,                  nOKUR$                  S
;   a;  U R                  R.                  S;   a  [        R0                  nO[        R2                  nU R4                  nUS:X  a  U R7                  SS5      n [        R                  " U5      n[        R8                  " U R:                  US9n	[=        S5      /S-  n
US:  a  [=        SU5      O[=        US5      X'   X9[?        U
5      '   U R                  R.                  [@        ;   a  [B        RD                  " X	XUS9  O[=        S5      /S-  nUS:  a  [=        US5      O[=        SU5      X'   [?        U5      n[=        S5      /S-  nUS:  a  [=        SU* 5      O[=        U* S5      X'   [?        U5      nU" X   X   5      X'   U(       a  U	R)                  S5      n	US:X  a	  U	SS2S4   n	U	$ )a  
difference of n between self,
analogous to s-s.shift(n)

Parameters
----------
arr : ndarray or ExtensionArray
n : int
    number of periods
axis : {0, 1}
    axis to shift on
stacklevel : int, default 3
    The stacklevel for the lost dtype warning.

Returns
-------
shifted
__r   zcannot diff z	 on axis=zK has no 'diff' method. Convert to a suitable dtype prior to calling 'diff'.Fr   rH   Tr  )r}   r|   r  r   rI   NrE   )datetimelikeztimedelta64[ns])#r  rL   nanrJ   r   operatorxorsubrK   r)   to_numpyrR   hasattrr   
ValueErrorr   shiftr   r   rz   rS   r
   object_r   rv   ru   r	  reshapeemptyr   slicern   _diff_specialr   diff_2d)r  nr  narJ   is_boolopis_timedelta	orig_ndimout_arr
na_indexer_res_indexerres_indexer_lag_indexerlag_indexers                  rY   diffr=  ;  s   ( 	AA	BIIEE"G\\\\%&&lln		c2::&&3"R[[M,--qy <S	0B0B/C9TF!STTc99Q<((9%%& 'G G 
 L
yy~~hhtn	

	t	
 99>>..JJEJJEIA~kk"a  HHUOEhhsyy.G+"J)*auT1~U1d^J!#E*
yy~~& 	cA,G d}q(/0AvU1d^5q>L)d}q(01AU4!_5!T?L)!#"2C4DE,,01A~!Q$-NrZ   c                   [        U [        R                  [        [        45      (       d  [        S5      eSn[        U R                  [        5      (       d%  [        R                  " U SS9S:X  a  [        U 5      nO" U R                  5       nU R                  U5      nUc  U$ [%        U5      (       d  [        S5      e['        [        R(                  " U5      5      nU(       d,  [+        [-        U 5      5      [+        U 5      :X  d  [/        S5      eUcI  [1        U 5      u  ppU" [+        U 5      5      nUR3                  U 5        ['        UR5                  U5      5      nU(       aG  UR                  5       n	U(       a#  U[+        U 5      * :  U[+        U 5      :  -  n
SX'   OSn
[7        XS	S
9nO[        R8                  " [+        U5      [:        S9nUR=                  U[        R>                  " [+        U5      5      5        UR                  USS9nU(       a,  US	:H  n
U(       a   X[+        U 5      * :  -  U[+        U 5      :  -  n
U(       a  W
b  [        R@                  " XS	5        U['        U5      4$ ! [
        [        R                  4 aF    U R                  (       a&  [        U S   [         5      (       a  [#        U 5      n GN[        U 5      n GN-f = f)a  
Sort ``values`` and reorder corresponding ``codes``.

``values`` should be unique if ``codes`` is not None.
Safe for use with mixed types (int, str), orders ints before strs.

Parameters
----------
values : list-like
    Sequence; must be unique if ``codes`` is not None.
codes : np.ndarray[intp] or None, default None
    Indices to ``values``. All out of bound indices are treated as
    "not found" and will be masked with ``-1``.
use_na_sentinel : bool, default True
    If True, the sentinel -1 will be used for NaN values. If False,
    NaN values will be encoded as non-negative integers and will not drop the
    NaN from the uniques of the values.
assume_unique : bool, default False
    When True, ``values`` are assumed to be unique, which can speed up
    the calculation. Ignored when ``codes`` is None.
verify : bool, default True
    Check if codes are out of bound for the values and put out of bound
    codes equal to ``-1``. If ``verify=False``, it is assumed there
    are no out of bound codes. Ignored when ``codes`` is None.

Returns
-------
ordered : AnyArrayLike
    Sorted ``values``
new_codes : ndarray
    Reordered ``codes``; returned when ``codes`` is not None.

Raises
------
TypeError
    * If ``values`` is not list-like or if ``codes`` is neither None
    nor list-like
    * If ``values`` cannot be sorted
ValueError
    * If ``codes`` is not None and ``values`` contain duplicates.
zbOnly np.ndarray, ExtensionArray, and Index objects are allowed to be passed to safe_sort as valuesNFre   ri   r   zMOnly list-like objects or None are allowed to be passed to safe_sort as codesz,values should be unique if codes is not Noner   r  rI   wrap)r   )!rK   rL   rR   r+   r,   r   rJ   r(   r   rm   _sort_mixedargsortr  decimalInvalidOperationr   rn   _sort_tuplesr!   r   rM   r   r   r)  r   map_locationslookupr2   r-  r  putarangeputmask)rW   rQ   r   r   r   r  orderedr   torder2r   	new_codesreverse_indexers                rY   r   r     s[   ` frzz+<hGHH/
 	

 F v||^44OOF51_Df%	.^^%Fkk&)G }.
 	
  

5 12EVF^!4F!CGHH~
 18
s6{#	$QXXg%67!S[L(Uc&k-ABDEKDFb9	((3v;c:FBIIc&k$:; $((V(<	B;DF|34V8LM4+


9B''	222{ 7334 
	. {{z&)U;; 'v.%f-
	.s   =!I, ,AK=KKc           	     Z   [         R                  " U  Vs/ s H  n[        U[        5      PM     sn[        S9n[         R                  " U  Vs/ s H  n[        U5      PM     sn[        S9nU) U) -  n[         R                  " X   5      n[         R                  " X   5      nUR                  5       S   R                  U5      nUR                  5       S   R                  U5      nUR                  5       S   n	[         R                  " XU	/5      n
U R                  U
5      $ s  snf s  snf )z3order ints before strings before nulls in 1d arraysrI   r   )
rL   r3   rK   strr   r0   rB  nonzeror  concatenate)rW   xstr_posnull_posnum_posstr_argsortnum_argsortstr_locsnum_locs	null_locslocss              rY   rA  rA  .  s    hhF;Fq
1c*F;4HGxx&1&Qa&1>Hh("G**V_-K**V_-K #((5H #((5H  "1%I>>8y9:D;;t <1s   D#D(c                F    SSK Jn  SSKJn  U" U S5      u  p4U" USS9nX   $ )z
Convert array of tuples (1d) to array of arrays (2d).
We need to keep the columns separately as they contain different types and
nans (can't use `np.sort` as it may fail when str and nan are mixed in a
column as types cannot be compared).
r   )	to_arrays)lexsort_indexerNT)orders)"pandas.core.internals.constructionr_  pandas.core.sortingr`  )rW   r_  r`  arraysr   indexers         rY   rE  rE  =  s,     =3&$'IFfT2G?rZ   c                &   SSK Jn  [        R                  " 5          [        R                  " SS[
        S9  [        U SS9n[        USS9nSSS5        WR                  WSS	9u  p4[        R                  " UR                  UR                  5      nU" XSR                  S
SS9n[        U [        5      (       a5  [        U[        5      (       a   U R                  U5      R                  5       nOd[        U [         5      (       a  U R"                  n [        U[         5      (       a  UR"                  n[%        X/5      n[        U5      n['        U5      nUR)                  U5      R                  n[        R*                  " Xh5      $ ! , (       d  f       GN== f)a  
Extracts the union from lvals and rvals with respect to duplicates and nans in
both arrays.

Parameters
----------
lvals: np.ndarray or ExtensionArray
    left values which is ordered in front.
rvals: np.ndarray or ExtensionArray
    right values ordered after lvals.

Returns
-------
np.ndarray or ExtensionArray
    Containing the unsorted union of both arrays.

Notes
-----
Caller is responsible for ensuring lvals.dtype == rvals.dtype.
r   r<   ignorez<The behavior of value_counts with object-dtype is deprecated)categoryFr   Nr?  r  )r   rJ   rD   )r   r<   rj   catch_warningsfilterwarningsrl   r   alignrL   maximumrW   r   rK   r-   appendr   r,   r   r%   r4   reindexrepeat)	lvalsrvalsr<   l_countr_countfinal_countunique_valscombinedrepeatss	            rY   union_with_duplicatesry  L  s8   . 		 	 	" 	J"	

 (e<'e< 
# }}W};G**W^^W^^<KMMUSK%''Jum,L,Lll5)002eX&&MMEeX&&MME !%0X&4[A!!+.55G99[**7 
#	"s   /F
Fc                  ^	 US;  a  SU S3n[        U5      e[        U5      (       ab  [        U[        5      (       a  [	        US5      (       a	  Um	U	4S jnO3SSKJn  [        U5      S:X  a  U" U[        R                  S9nOU" U5      n[        U[        5      (       aU  US	:X  a  XR                  R                  5          nUR                  R                  U 5      n[        UR                  U5      nU$ [        U 5      (       d  U R!                  5       $ U R#                  [$        S
S9nUc  [&        R(                  " XUS9$ [&        R*                  " X[-        U5      R/                  [        R0                  5      US9$ )af  
Map values using an input mapping or function.

Parameters
----------
mapper : function, dict, or Series
    Mapping correspondence.
na_action : {None, 'ignore'}, default None
    If 'ignore', propagate NA values, without passing them to the
    mapping correspondence.
convert : bool, default True
    Try to find better dtype for elementwise function results. If
    False, leave as dtype=object.

Returns
-------
Union[ndarray, Index, ExtensionArray]
    The output of the mapping function applied to the array.
    If the function returns a tuple with more than one element
    a MultiIndex will be returned.
)Nrh  z+na_action must either be 'ignore' or None, z was passed__missing__c                   > T[        U [        5      (       a-  [        R                  " U 5      (       a  [        R                     $ U    $ r   )rK   floatrL   r   r#  )rT  dict_with_defaults    rY   r   map_array.<locals>.<lambda>  s2    0$Q..288A;; DE rZ   r   rg  rI   rh  FrC   )convert)r   r  )r)  r   rK   dictr(  r   r<   r   rL   ru   r.   r   r   get_indexerr2   r   rD   rT   rV   r   	map_infermap_infer_maskr0   rS   rB   )
r  mapper	na_actionr  msgr<   re  
new_valuesrW   r~  s
            @rY   	map_arrayr    sH   6 ((;I;kRo
 Ffd##(F(F !'F &6{abjj9&)$$ LL..01F ,,**3/V^^W5
s88xxz ZZUZ+F}}VW==!!f!2!2288!<g
 	
rZ   )rW   r   return
np.ndarray)rW   r   rJ   r   r^   r   r  r   )rp   rQ  r  r   )rW   r  )rW   r  r  rQ  )rW   r   r  r  r   )r   npt.NDArray[np.bool_] | None)r   r7   rW   r7   r  npt.NDArray[np.bool_])TNNN)rW   r  r   r   r   
int | Noner   rV   r   r  r  z'tuple[npt.NDArray[np.intp], np.ndarray])FTN)r   r   r   r   r   r  r  z%tuple[np.ndarray, np.ndarray | Index])TFFNT)
r   r   r   r   r   r   r   r   r  r<   )rW   r  r   r   r   r  r  z,tuple[ArrayLike, npt.NDArray[np.int64], int])firstN)rW   r   r   zLiteral['first', 'last', False]r   r  r  r  )TN)rW   r   r   r   r   r  r  r   )r   averager   TF)rW   r   r  r   r  rQ  r  rQ  r   r   r  r   r  znpt.NDArray[np.float64])r   FN)r  r   r  r   r  r   )leftN)
r  r   r  z$NumpyValueArrayLike | ExtensionArrayr  zLiteral['left', 'right']r  zNumpySorter | Noner  znpt.NDArray[np.intp] | np.intp)r   )r1  r  r  r   )NTFT)rW   zIndex | ArrayLikerQ   znpt.NDArray[np.intp] | Noner   r   r   r   r   r   r  z.AnyArrayLike | tuple[AnyArrayLike, np.ndarray])r  r   )rW   r  r  r  )rq  ArrayLike | Indexrr  r  r  r  )NT)r  r   r  zLiteral['ignore'] | Noner  r   r  z#np.ndarray | ExtensionArray | Index)__doc__
__future__r   rC  r$  textwrapr   typingr   r   r   rj   numpyrL   pandas._libsr   r	   r   r
   r   pandas._typingr   r   r   r   r   r   pandas.util._decoratorsr   pandas.util._exceptionsr   pandas.core.dtypes.castr   r   pandas.core.dtypes.commonr   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   pandas.core.dtypes.concatr%   pandas.core.dtypes.dtypesr&   r'   r(   r)   pandas.core.dtypes.genericr*   r+   r,   r-   r.   r/   pandas.core.dtypes.missingr0   r1   pandas.core.array_algos.taker2   pandas.core.constructionr3   r   r4   r5   pandas.core.indexersr6   r7   r8   r9   r   r:   r;   r<   pandas.core.arraysr=   r>   rO   r`   rr   Complex128HashTableComplex64HashTableFloat64HashTableFloat32HashTableUInt64HashTableUInt32HashTableUInt16HashTableUInt8HashTableInt64HashTableInt32HashTableInt16HashTableInt8HashTableStringHashTablePyObjectHashTabler   r   r   r   r   r   unique1dr   r   r   r   r   r   r   r   r   r  r  r  r/  r=  r   rA  rE  ry  r   rZ   rY   <module>r     s   #    
     ( 4    " 4  
 1 
 2  
K!\&2>B8 ,,**&&&&$$$$$$""""""""  $$&&$$6^$B.,0  " X"z ! )-;;; ; 	;
 '; -;| 	 
	
 	0   	t
t t 	t
 +t-,tr 	,
, , 	, , ,b 	a
a a 	a a aL LP(( $(,H(1(B -4)-;;
); '; 	;< RV))#)2N))\ 88
8 8 	8
 8 
8 8F mm m 	mp &,!%	Q=	Q=/Q= #Q= 	Q=
 $Q=p Jgf *. 33&3 3 	3
 3 43D4+4+%64+4+t +/	P
	P
 (P
 	P

 )P
rZ   