Ë
    ¤eh�×  ã                  óR  — d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	m
Z
 ddlZddlZddlmZmZmZmZ ddlmZ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! ddl"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8 ddl9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z? ddl@mAZAmBZB ddlCmDZD ddlEmFZGmHZHmIZI ddlJmKZK erddlmLZLmMZMmNZN ddlOmPZPmQZQmRZR ddlSmTZTmUZU d6d„ZV	 	 	 	 	 	 	 	 d7d„ZWd8d„ZXej²                  ej´                  ej¶                  ej¸                  ejº                  ej¼                  ej¾                  ejÀ                  ejÂ                  ejÄ                  ejÆ                  ejÈ                  ejÊ                  ejÌ                  dœZgd9d„Zhd:d„Zid„ Zjd;d„Zkd<d=d„ZlejZmdZnd>d „Zo	 	 	 	 d?	 	 	 	 	 	 	 	 	 	 	 d@d!„Zp e ed"«       ed#«       ed$«      ¬%«      	 	 	 dA	 	 	 	 	 	 	 dBd&„«       Zq	 	 	 	 	 dC	 	 	 	 	 	 	 	 	 dDd'„Zr	 	 	 	 	 dC	 	 	 	 	 	 	 	 	 dDd(„Zs	 d<	 	 	 	 	 	 	 dEd)„Zt	 	 dF	 	 	 	 	 	 	 dGd*„Zu	 dH	 	 	 	 	 	 	 dId+„Zv	 	 	 	 	 dJ	 	 	 	 	 	 	 	 	 	 	 	 	 dKd,„Zw	 	 	 dL	 	 	 	 	 dMd-„Zx	 	 dN	 	 	 	 	 	 	 	 	 dOd.„Zyh d/£ZzdPdQd0„Z{	 	 	 	 dR	 	 	 	 	 	 	 	 	 	 	 dSd1„Z|dTd2„Z}dUd3„Z~	 	 	 	 	 	 dVd4„Z	 	 dW	 	 	 	 	 	 	 dXd5„Z€y)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                óÌ  — t        | t        «      st        | d¬«      } t        | j                  «      rt        t        j                  | «      «      S t        | j                  t        «      rBt        d| «      } | j                  st        | j                  «      S t        j                  | «      S t        | j                  t        «      rt        d| «      } | j                  S t        | j                  «      rdt        | t        j                   «      r$t        j                  | «      j#                  d«      S t        j                  | «      j%                  dd¬«      S t'        | j                  «      rt        j                  | «      S t)        | j                  «      r8| j                  j*                  dv rt-        | «      S t        j                  | «      S t/        | j                  «      rt        t        j                   | «      S t1        | j                  «      r-| j#                  d	«      }t        t        j                   |«      }|S t        j                  | t2        ¬
«      } t        | «      S )a„  
    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     úT/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/pandas/core/algorithms.pyrO   rO   j   s¸  € ô, �fœmÔ,ä˜v°TÔ:ˆä�v—|‘|Ô$ÜœRŸZ™Z¨Ó/Ó0Ð0ä	�F—L‘L¤/Ô	2äÐ'¨Ó0ˆØ�}Š}ô   §¡Ó-Ð-Ü�z‰z˜&Ó!Ð!ä	�F—L‘LÔ"2Ô	3ô �m VÓ,ˆØ�|‰|Ðä	�v—|‘|Ô	$Ü�fœbŸj™jÔ)ä—:‘:˜fÓ%×*Ñ*¨7Ó3Ð3ô —:‘:˜fÓ%×,Ñ,¨W¸5Ð,ÓAÐAä	˜&Ÿ,™,Ô	'Ü�z‰z˜&Ó!Ð!ä	˜Ÿ™Ô	%ð �<‰<× Ñ  KÑ/ä! &Ó)Ð)Ü�z‰z˜&Ó!Ð!ä	˜&Ÿ,™,Ô	'Ü”B—J‘J Ó'Ð'ô 
˜VŸ\™\Ô	*Ø—;‘;˜tÓ$ˆÜœŸ
™
 HÓ-ˆØˆô �Z‰Z˜¤fÔ-€FÜ˜Ó Ð ó    c                óì   — t        | t        «      r| j                  |k(  r| S t        |t        j                  «      s%|j	                  «       }|j                  | |¬«      } | S | j                  |d¬«      } | S )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`   ¸   sr   € ô  �&Ô+Ô,°·±ÀÒ1Fàˆä�eœRŸX™XÔ&ð ×(Ñ(Ó*ˆà×#Ñ# F°%Ð#Ó8ˆð
 €Mð —‘˜u¨5�Ó1ˆà€MrZ   c                ób  — t        | t        t        t        t        j
                  f«      s„|dk7  r't        j                  |› d�t        t        «       ¬«       t        j                  | d¬«      }|dv r(t        | t        «      rt        | «      } t        | «      } | S t	        j                  | «      } | S )z5
    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ž   € ô �fœx¬Ô4EÄrÇzÁzÐRÔSà˜Ò&ä�M‰MØ�+ð "ð "ô Ü+Ó-õô —?‘? 6°%Ô8ˆØÐ;Ñ;ä˜&¤%Ô(Ü˜f›�Ü<¸VÓDˆFð €Mô —Z‘Z Ó'ˆFØ€MrZ   )Ú
complex128Ú	complex64Úfloat64Úfloat32Úuint64Úuint32Úuint16rB   Úint64Úint32Úint16Úint8rh   rV   c                óH   — t        | «      } t        | «      }t        |   }|| fS )z‰
    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Ø�fÐÐrZ   c                ón   — | j                   j                  }|dk(  rt        j                  | d¬«      rd}|S )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Ø�Òô ×Ñ˜v¨eÕ4ØˆFØ€MrZ   c                ó   — t        | «      S )a3
  
    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                óÀ   — t        | «      dk(  ryt        | «      } t        j                  | j	                  «       j                  d«      «      dk7  j                  «       }|S )aH  
    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ä�k‰k˜&Ÿ,™,›.×/Ñ/°Ó7Ó8¸AÑ=×BÑBÓD€FØ€MrZ   c                ó’  — t        | d¬«      } t        | j                  t        «      r| j	                  «       S | }t        | «      \  }}  |t        | «      «      }|€*|j	                  | «      }t        ||j                  |«      }|S |j	                  | |¬«      \  }}t        ||j                  |«      }|€J ‚||j                  d«      fS )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ˆvá”c˜&“kÓ"€EØ€|Ø—,‘,˜vÓ&ˆÜ# G¨X¯^©^¸XÓFˆØˆð Ÿ™ V°$˜Ó7‰ˆ�Ü# G¨X¯^©^¸XÓFˆØÐÐÐØ˜Ÿ™ FÓ+Ð+Ð+rZ   i@B c                ó  — t        | «      s"t        dt        | «      j                  › d�«      ‚t        |«      s"t        dt        |«      j                  › d�«      ‚t	        |t
        t        t        t        j                  f«      sUt        |«      }t        |d¬«      }t        |«      dkD  rc|j                  j                  dv rKt        | «      s@t!        |«      }n4t	        |t"        «      rt        j$                  |«      }nt'        |dd¬«      }t        | d	¬«      }t'        |d¬
«      }t	        |t        j                  «      s|j)                  |«      S t+        |j                  «      rt-        |«      j)                  |«      S t+        |j                  «      r:t/        |j                  «      s%t        j0                  |j2                  t4        ¬«      S t+        |j                  «      rt)        ||j7                  t8        «      «      S t	        |j                  t:        «      r2t)        t        j<                  |«      t        j<                  |«      «      S t        |«      t>        kD  rBt        |«      dk  r4|j                  t8        k7  r!tA        |«      jC                  «       rd„ }nZd„ }nVtE        |j                  |j                  «      }|j7                  |d¬«      }|j7                  |d¬«      }tF        jH                  } |||«      S )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                ó˜   — t        j                  t        j                  | |«      j                  «       t        j                  | «      «      S ©N)rL   Ú
logical_orrœ   r�   Úisnan)ÚcÚvs     rY   Úfzisin.<locals>.f  s.   € Ü—}‘}¤R§W¡W¨Q°£]×%8Ñ%8Ó%:¼B¿H¹HÀQ»KÓHÐHrZ   c                óJ   — t        j                  | |«      j                  «       S rŸ   )rL   rœ   r�   )ÚaÚbs     rY   ú<lambda>zisin.<locals>.<lambda>  s   € œRŸW™W Q¨›]×0Ñ0Ó2€ rZ   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œ   É  sj  € ô ˜ÔÜð(Ü(,¨U«×(<Ñ(<Ð'=¸Qð@ó
ð 	
ô ˜ÔÜð(Ü(,¨V«×(=Ñ(=Ð'>¸aðAó
ð 	
ô
 �fœx¬Ô4EÄrÇzÁzÐRÔSÜ˜6“lˆÜ" ;¸.ÔIˆô �‹K˜!ŠOØ—‘×!Ñ! WÑ,Ü+¨EÔ2ô =¸[ÓI‰Fä	�FœMÔ	*ä—‘˜&Ó!‰ä˜v°TÈÔNˆä# E°VÔ<€KÜ ¸4Ô@€KÜ�k¤2§:¡:Ô.à×Ñ Ó'Ð'ä	˜[×.Ñ.Ô	/ä˜Ó$×)Ñ)¨&Ó1Ð1Ü	˜VŸ\™\Ô	*´?À;×CTÑCTÔ3Uä�x‰x˜×)Ñ)´Ô6Ð6ä	˜VŸ\™\Ô	*Ü�K §¡¬vÓ!6Ó7Ð7ä	�F—L‘L¤.Ô	1Ü”B—J‘J˜{Ó+¬R¯Z©Z¸Ó-?Ó@Ð@ô 	ˆKÓÔ0Ò0Ü�‹K˜2ÒØ×Ñ¤Ò'ô �‹<×ÑÔóIñ 3‰Aô % V§\¡\°;×3DÑ3DÓEˆØ—‘˜v¨E�Ó2ˆØ!×(Ñ(¨°eÐ(Ó<ˆÜ�O‰Oˆáˆ[˜&Ó!Ð!rZ   c                ó  — | }| j                   j                  dv rt        }t        | «      \  }}  ||xs t	        | «      «      }|j                  | d|||¬«      \  }}	t        ||j                   |«      }t        |	«      }	|	|fS )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Ó0€EØ—_‘_ØØØØØ!ð %ó �N€GˆUô   ¨¯©¸ÓB€Gä Ó&€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                óÌ  — t        | t        t        f«      r| j                  ||¬«      S t	        | d¬«      } | }t        | t
        t        f«      r%| j                  �| j                  |¬«      \  }}||fS t        | t        j                  «      s| j                  |¬«      \  }}n„t        j                  | «      } |s\| j                  t        k(  rIt        | «      }|j                  «       r.t        | j                  d¬«      }t        j                   ||| «      } t#        | ||¬«      \  }}|r!t%        |«      d	kD  rt'        |||d
d¬«      \  }}t)        ||j                  |«      }||fS )aN  
    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  sV  € ôp �&œ8¤YÐ/Ô0Ø×Ñ T¸?ÐÓKÐKä˜v°Ô=€FØ€Hô 	�6Ô,Ô.?Ð@ÔAØ�K‰KÐ#ð  ×)Ñ)¨tÐ)Ó4‰ˆˆwØ�gˆ~Ðä˜¤§
¡
Ô+à×)Ñ)¸/Ð)ÓJ‰ˆ‰wô —‘˜FÓ#ˆá 6§<¡<´6Ò#9ô
 ˜V›ˆIØ�}‰}ŒÜ-¨f¯l©lÀ5ÔI�äŸ™ )¨X°vÓ>�ä(ØØ+Øô
‰ˆˆwñ ”�G“˜qÒ Ü"ØØØ+ØØô
‰ˆ�ô   ¨¯©¸ÓB€Gà�'ˆ>ÐrZ   c                ól   — t        j                  dt        t        «       ¬«       t	        | |||||¬«      S )aK  
    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@   € ô< ‡M�Mð	EäÜ#Ó%õô !ØØØØØØôð rZ   c                óŠ  — ddl m}m} t        | dd «      }|rdnd}	|�ßddlm}
 t        | |«      r| j                  } 	  |
| |d¬«      }|j                  |¬
«      }|	|_
        ||j                  j                  «          }|j                  j                  d«      |_        |j                  «       }|r,|j                  dk(  j                  «       r|j                   dd }t#        j$                  t'        |«      g«      }�n t)        | «      rz || d¬«      j                  j                  |¬
«      }|	|_
        ||j                  _
        |j                  }t        |t"        j*                  «      �s’t#        j,                  |«      }�n{t        | t.        «      rot1        t3        | j4                  «      «      } || |	¬«      j7                  ||¬«      j9                  «       }| j:                  |j                  _        |j                  }nüt=        | d¬«      } t?        | |«      \  }}}|j@                  t"        jB                  k(  r|j                  t"        jD                  «      } ||«      }|j@                  tF        k(  r)|j@                  tH        k(  r|j                  tH        «      }nL|j@                  |j@                  k7  r3|j@                  dk7  r$tK        jL                  dtN        tQ        «       ¬«       ||_
         ||||	d¬«      }|r|jS                  |¬«      }|r||jU                  «       z  }|S # t        $ r}t        d	«      |‚d }~ww xY w)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]zàThe 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Ô%Ø—^‘^ˆFð	TÙ�V˜T°$Ô7ˆBð
 —‘¨�Ó/ˆØˆŒØ˜Ÿ™×*Ñ*Ó,Ñ-ˆØ—|‘|×*Ñ*¨:Ó6ˆŒØ×"Ñ"Ó$ˆñ �v—~‘~¨Ñ*×/Ñ/Ô1Ø—[‘[  1Ð%ˆFô —‘œ3˜r›7˜)Ó$Šô $ FÔ+á˜F¨Ô/×7Ñ7×DÑDÈFÐDÓSˆFØˆFŒKØ *ˆF�L‰LÔØ—^‘^ˆFÜ˜f¤b§j¡jÕ1äŸ™ FÓ+’ä˜¤Ô.äœ% §¡Ó/Ó0ˆFá˜V¨$Ô/ß‘˜v¨f�Ó5ß‘“ð ð
 "(§¡ˆF�L‰LÔØ—^‘^‰Fô ' v¸ÔHˆFÜ4°V¸VÓD‰OˆD�&˜!Ø�z‰zœRŸZ™ZÒ'Ø—{‘{¤2§:¡:Ó.�ñ ˜“+ˆCØ�y‰yœDÒ  T§Z¡Z´6Ò%9Ø—j‘j¤Ó(‘à—	‘	˜TŸZ™ZÒ'Ø—I‘IÐ!8Ò8ä—‘ðDô "Ü/Ó1õð "ˆCŒHá˜F¨#°D¸uÔEˆFáØ×#Ñ#¨iÐ#Ó8ˆáØ˜&Ÿ*™*›,Ñ&ˆà€MøôS ò 	TÜÐIÓJÐPSÐSûð	Tús   ½L( Ì(	MÌ1L=Ì=Mc                óà   — | }t        | «      } t        j                  | ||¬«      \  }}}t        |j                  «      r|r|t
        k7  }||   ||   }}t        ||j                  |«      }|||fS )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é   Ã  sx   € ð €HÜ˜&Ó!€Fä%×1Ñ1°&¸&ÀtÔLÑ€Dˆ&�*ä˜8Ÿ>™>Ô*ñ Øœ4‘<ˆDØ ™: v¨d¡|�&ˆDä   x§~¡~°xÓ@€HØ�V˜ZÐ'Ð'rZ   c                óH   — t        | «      } t        j                  | ||¬«      S )ax  
    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Ü×Ñ˜V¨$°TÔ:Ð:rZ   c                óÂ  — t        | d¬«      } | }t        | j                  «      r)t        | «      } t	        d| «      } | j                  |¬«      S t        | «      } t        j                  | ||¬«      \  }}|�||fS 	 t        j                  |«      }t        ||j                  |«      }|S # t        $ r,}t        j                  d|› �t        «       ¬«       Y d}~ŒId}~ww xY w)	a  
    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°Ô8€FØ€Hä˜6Ÿ<™<Ô(ä/°Ó7ˆÜÐ&¨Ó/ˆØ�|‰| 6ˆ|Ó*Ð*ä˜&Ó!€FäŸ™ V°FÀÔFÑ€HˆhØÐØ˜Ð!Ð!ð
Ü—7‘7˜8Ó$ˆô ˜x¨¯©¸ÓB€FØ€Møô ò 
Ü�‰Ø$ S EÐ*Ü'Ó)÷	
ò 	
ûð
ús   Á;B) Â)	CÂ2"CÃCc           	     ó
  — t        | j                  «      }t        | «      } | j                  dk(  rt	        j
                  | |||||¬«      }|S | j                  dk(  rt	        j                  | ||||||¬«      }|S t        d«      ‚)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•   € ô> *¨&¯,©,Ó7€OÜ˜&Ó!€Fà‡{�{�aÒÜ—‘ØØ+ØØØØô
ˆð* €Lð 
�‰˜Ò	Ü—‘ØØØ+ØØØØô
ˆð €Lô Ð@ÓAÐArZ   c                óx  — t        | t        j                  t        t        t
        f«      s$t        j                  dt        t        «       ¬«       t        | «      st        j                  | «      } t        |«      }|r+t        || j                  |   «       t        | ||d|¬«      }|S | j!                  ||¬«      }|S )ak	  
    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])
    z­pd.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 �cœBŸJ™JÔ(9¼8ÄYÐOÔPä�‰ð8ô Ü'Ó)õ	
ô ˜ÔÜ�j‰j˜‹oˆä! 'Ó*€Gáä˜ #§)¡)¨D¡/Ô2ÜØ�˜t°Àô
ˆð €Mð —‘˜'¨�Ó-ˆØ€MrZ   c                óà  — |�t        |«      }t        | t        j                  «      �r(| j                  j
                  dv �rt        |«      st        |«      rùt        j                  | j                  j                  «      }t        |«      rt        j                  |g«      nt        j                  |«      }||j                  k\  j                  «       r*||j                  k  j                  «       r| j                  }n|j                  }t        |«      r t        t        |j                  |«      «      }n't!        t        t"        |«      |¬«      }nt%        | «      } | j'                  |||¬«      S )aû  
    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œŸ
™
Õ#Ø�I‰I�N‰N˜dÒ"Ü˜ÔÔ"2°5Ô"9ô —‘˜Ÿ™Ÿ™Ó(ˆÜ)3°EÔ):”B—H‘H˜e˜WÔ%ÄÇÁÈÃˆ	Ø˜Ÿ™Ñ"×'Ñ'Ô)¨y¸E¿I¹IÑ/E×.JÑ.JÔ.Lð —I‘I‰Eà—O‘OˆEä�eÔäœ˜eŸj™j¨Ó/Ó0‰EäœT¤)¨UÓ3¸5ÔA‰Eô -¨SÓ1ˆð ×Ñ˜E¨°VÐÓ<Ð<rZ   >   r}   r|   r{   rz   rv   ru   c                ó\  — t        |«      }t        j                  }| j                  }t	        |«      }|rt
        j                  }nt
        j                  }t        |t        «      r| j                  «       } | j                  }t        | t        j                  «      s|t        | d|j                  › d�«      rA|dk7  r$t        dt        | «      j                  › d|› �«      ‚ || | j!                  |«      «      S t#        t        | «      j                  › d�«      ‚d}| j                  j$                  dv r*t        j&                  }| j)                  d«      } t*        }d	}nZ|rt        j,                  }nG|j$                  d
v r9| j                  j.                  dv rt        j0                  }nt        j2                  }| j4                  }|dk(  r| j7                  dd«      } t        j                  |«      }t        j8                  | j:                  |¬«      }	t=        d«      gdz  }
|dk\  rt=        d|«      nt=        |d«      |
|<   ||	t?        |
«      <   | j                  j.                  t@        v rtC        jD                  | |	|||¬«       nˆt=        d«      gdz  }|dk\  rt=        |d«      nt=        d|«      ||<   t?        |«      }t=        d«      gdz  }|dkD  rt=        d| «      nt=        | d«      ||<   t?        |«      } || |   | |   «      |	|<   |r|	j)                  d«      }	|dk(  r	|	dd…df   }	|	S )aQ  
    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Ø�I‰I€Eä˜EÓ"€GÙÜ�\‰\‰ä�\‰\ˆä�%œÔ&à�l‰l‹nˆØ—	‘	ˆä�cœ2Ÿ:™:Ô&ä�3˜"˜RŸ[™[˜M¨Ð,Ô-Ø�qŠyÜ  <´°S³	×0BÑ0BÐ/CÀ9ÈTÈFÐ!SÓTÐTÙ�c˜3Ÿ9™9 Q›<Ó(Ð(äÜ˜“9×%Ñ%Ð&ð 'Gð Góð ð
 €LØ
‡y�y‡~�~˜ÑÜ—‘ˆØ�h‰h�t‹nˆÜˆØ‰á	ä—
‘
‰à	�‰�tÑ	ð
 �9‰9�>‰>Ð.Ñ.Ü—J‘J‰Eä—J‘JˆEà—‘€IØ�A‚~à�k‰k˜"˜aÓ ˆô �H‰H�U‹O€EÜ�h‰h�s—y‘y¨Ô.€Gä˜“+� Ñ"€JØ)*¨aª”u˜T 1”~´U¸1¸d³^€JˆtÑØ!#€GŒE�*ÓÑà
‡y�y‡~�~œÑ&ô 	�‰�c˜7 A t¸,ÖGô ˜d›�} qÑ(ˆØ/0°AªvœU 1 dœ^¼5ÀÀq»>ˆ�TÑÜ˜LÓ)ˆä˜d›�} qÑ(ˆØ01°A²œU 4¨!¨œ_¼5À!ÀÀT»?ˆ�TÑÜ˜LÓ)ˆá! # kÑ"2°C¸Ñ4DÓEˆ�ÑáØ—,‘,Ð0Ó1ˆà�A‚~Øš!˜Q˜$‘-ˆØ€NrZ   c                ó8  — t        | t        j                  t        t        f«      st        d«      ‚d}t        | j                  t        «      s&t        j                  | d¬«      dk(  rt        | «      }n"	 | j                  «       }| j                  |«      }|€|S t%        |«      st        d«      ‚t'        t        j(                  |«      «      }|s+t+        t-        | «      «      t+        | «      k(  st/        d«      ‚|€Jt1        | «      \  }}  |t+        | «      «      }|j3                  | «       t'        |j5                  |«      «      }|rG|j                  «       }	|r$|t+        | «       k  |t+        | «      k\  z  }
d||
<   nd}
t7        |	|d	¬
«      }n�t        j8                  t+        |«      t:        ¬«      }|j=                  |t        j>                  t+        |«      «      «       |j                  |d¬«      }|r(|d	k(  }
|r!|
|t+        | «       k  z  |t+        | «      k\  z  }
|r
�t        j@                  ||
d	«       |t'        |«      fS # t
        t        j                  f$ r: | j                  rt        | d   t         «      rt#        | «      }nt        | «      }Y �Œw xY w)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Ê   ¬  sZ  € ô` �fœrŸz™zÔ+<¼hÐGÔHÜð/ó
ð 	
ð
 €Fô �v—|‘|¤^Ô4Ü�O‰O˜F¨5Ô1°_ÒDä˜fÓ%‰ð	.Ø—^‘^Ó%ˆFØ—k‘k &Ó)ˆGð €}Øˆä˜ÔÜð.ó
ð 	
ô  ¤§
¡
¨5Ó 1Ó2€Eá¤¤V¨F£^Ó!4¼¸F»Ò!CÜÐGÓHÐHà€~ô
 1°Ó8Ñˆ
�FÙ”s˜6“{Ó#ˆØ	�‰˜ÔÜ$ Q§X¡X¨gÓ%6Ó7ˆáà—‘Ó!ˆÙØœS ›[˜LÑ(¨U´c¸&³kÑ-AÑBˆDØˆE�$ŠKàˆDÜ˜F E°bÔ9‰	äŸ(™(¤3 v£;´cÔ:ˆØ×Ñ˜F¤B§I¡I¬c°&«kÓ$:Ô;ð $×(Ñ(¨°VÐ(Ó<ˆ	áØ˜B‘;ˆDÙØ˜u¬¨F« |Ñ3Ñ4¸ÄÀVÃÑ8LÑM�á˜4Ð+Ü
�
‰
�9˜d BÔ'àÔ'¨	Ó2Ð2Ð2øô{ œ7×3Ñ3Ð4ò 
	.ð �{Š{œz¨&°©)´UÔ;ô ' vÓ.‘ä% fÓ-�úð
	.ús   Á4!I ÉAJÊJc           	     óV  — t        j                  | D �cg c]  }t        |t        «      ‘Œ c}t        ¬«      }t        j                  | D �cg c]  }t        |«      ‘Œ c}t        ¬«      }| | z  }t        j                  | |   «      }t        j                  | |   «      }|j                  «       d   j                  |«      }|j                  «       d   j                  |«      }|j                  «       d   }	t        j                  |||	g«      }
| j                  |
«      S c c}w c c}w )z3order ints before strings before nulls in 1d arraysrI   r   )
rL   r3   rK   Ústrr•   r0   r@  Únonzeror  Úconcatenate)rW   ÚxÚstr_posÚnull_posÚnum_posÚstr_argsortÚnum_argsortÚstr_locsÚnum_locsÚ	null_locsÚlocss              rY   r?  r?  .  sì   € ä�h‰h°FÖ;¨qœ
 1¤cÕ*Ò;Ä4ÔH€GÜ�x‰x¨&Ö1 Qœ˜a�Ò1¼Ô>€HØˆh˜(˜Ñ"€GÜ—*‘*˜V G™_Ó-€KÜ—*‘*˜V G™_Ó-€Kà�‰Ó  Ñ#×(Ñ(¨Ó5€HØ�‰Ó  Ñ#×(Ñ(¨Ó5€HØ× Ñ Ó" 1Ñ%€IÜ�>‰>˜8 X¨yÐ9Ó:€DØ�;‰;�tÓÐùò <ùÚ1s   ”D!ÁD&c                óP   — ddl m} ddlm}  || d«      \  }} ||d¬«      }| |   S )a  
    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   rC  rC  =  s0   € õ =Ý3á˜& $Ó'�I€FˆAÙ˜f¨TÔ2€GØ�'‰?ÐrZ   c                ó  — ddl m} t        j                  «       5  t        j                  ddt
        ¬«       t        | d¬«      }t        |d¬«      }ddd«       j                  d¬	«      \  }}t        j                  |j                  |j                  «      } |||j                  d
d¬«      }t        | t        «      r0t        |t        «      r | j                  |«      j                  «       }n[t        | t         «      r| j"                  } t        |t         «      r|j"                  }t%        | |g«      }t        |«      }t'        |«      }|j)                  |«      j                  }t        j*                  ||«      S # 1 sw Y   �Œ,xY w)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_duplicatesrw  L  s;  € õ. ä	×	 Ñ	 Ó	"ñ 	=ô 	×ÑØØJÜ"õ	
ô
 (¨°eÔ<ˆÜ'¨°eÔ<ˆ÷	=ð —}‘} W¸�}Ó;Ñ€GˆWÜ—*‘*˜WŸ^™^¨W¯^©^Ó<€KÙ˜¨G¯M©MÀÈUÔS€KÜ�%œÔ'¬J°u¼mÔ,LØ—l‘l 5Ó)×0Ñ0Ó2‰ä�eœXÔ&Ø—M‘MˆEÜ�eœXÔ&Ø—M‘MˆEô ! %¨ Ó0ˆÜ˜XÓ&ˆÜ4°[ÓAˆØ×!Ñ! +Ó.×5Ñ5€GÜ�9‰9�[ 'Ó*Ð*÷7	=ñ 	=ús   ›7E<Å<Fc                óÖ  ‡	— |dvrd|› d�}t        |«      ‚t        |«      rYt        |t        «      rt	        |d«      r|Š	ˆ	fd„}n5ddlm} t        |«      dk(  r ||t        j                  ¬«      }n ||«      }t        |t        «      rU|d	k(  r||j                  j                  «          }|j                  j                  | «      }t        |j                  |«      }|S t        | «      s| j!                  «       S | j#                  t$        d
¬«      }|€t'        j(                  |||¬«      S t'        j*                  ||t-        |«      j/                  t        j0                  «      |¬«      S )a®  
    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.
    )Nrf  z+na_action must either be 'ignore' or None, z was passedÚ__missing__c                ó|   •— ‰t        | t        «      r't        j                  | «      rt        j                     S |    S rŸ   )rK   ÚfloatrL   r¡   r!  )rR  Údict_with_defaults    €rY   r¨   zmap_array.<locals>.<lambda>ª  s1   ø€ Ð0Ü$ Q¬Ô.´2·8±8¸A´;”—‘ñ € ØDEñ € rZ   r   re  rI   rf  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<   rc  Ú
new_valuesrW   r|  s
            @rY   Ú	map_arrayr†  ƒ  s@  ø€ ð6 Ð(Ñ(Ø;¸I¸;ÀkÐRˆÜ˜‹oÐô
 �FÔÜ�fœdÔ#¬°¸Ô(Fð !'Ðó‰Fõ &ä�6‹{˜aÒÙ ¬b¯j©jÔ9‘á ›�ä�&œ)Ô$Ø˜Ò Ø˜FŸL™L×.Ñ.Ó0Ñ1ˆFð —,‘,×*Ñ*¨3Ó/ˆÜ˜VŸ^™^¨WÓ5ˆ
àÐäˆsŒ8Ø�x‰x‹zÐð �Z‰Zœ UˆZÓ+€FØÐÜ�}‰}˜V V°WÔ=Ð=ä×!Ñ!Ø�F¤ f£×!2Ñ!2´2·8±8Ó!<Àgô
ð 	
rZ   )rW   r   Úreturnú
np.ndarray)rW   r   rJ   r   r^   r   r‡  r   )rp   rO  r‡  r   )rW   rˆ  )rW   rˆ  r‡  rO  )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
  rO  r  rO  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   )r/  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ˆ  )ro  úArrayLike | Indexrp  r�  r‡  r�  )NT)r  r   rƒ  zLiteral['ignore'] | Noner}  r•   r‡  z#np.ndarray | ExtensionArray | Index)�Ú__doc__Ú
__future__r   rA  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Ê   r?  rC  rw  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ó3óDóð4+Øð4+Ø%6ð4+àó4+ðt +/Øð	P
Ø	ðP
ð (ðP
ð ð	P
ð
 )ôP
rZ   