§
    
�’jÝ  ã                  ó\  — d Z ddlmZ ddlZddlZddlmZmZmZm	Z	m
Z
 ddlZddlZddlmZmZmZmZ ddlmZ ddlmZ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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z< ddl=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZD ddlEmFZFmGZG ddlHmIZI ddlJmKZLmMZMmNZN ddlOmPZP er/ddlmQZQmRZRmSZS ddlTmUZUmVZVmWZW ddlXmYZYmZZZ  edeVeUz  eZz  ¬¦  «        Z[dd„Z\d€d"„Z]d�d%„Z^ej_        ej`        eja        ejb        ejc        ejd        eje        ejf        ejg        ejh        eji        ejj        ejk        ejl        d&œZmd‚d(„Zndƒd)„Zoe
d„d*„¦   «         Zpe
d…d,„¦   «         Zp ed-¦  «        d.„ ¦   «         Zpd†d0„Zqd‡dˆd3„ZrepZsd4Ztd‰d8„Zu	 	 	 	 dŠd‹dA„Zv ed-¦  «        	 	 	 dŒd�dE„¦   «         Zw	 	 	 	 	 dŽd�dJ„Zx	 d‡d�dL„Zy	 	 d‘d’dP„Zz	 d“d”dR„Z{	 	 	 	 	 	 d•d–dZ„Z| ed[¦  «        	 	 	 d—d˜d_„¦   «         Z}	 	 d™dšdi„Z~h dj£Zd›dœdm„Z€	 	 	 	 d�dždt„Z�dŸdu„Z‚d dv„Zƒd¡dz„Z„	 d‡d¢d~„Z…dS )£zl
Generic data algorithms. This module is experimental at the moment and not
intended for public consumption
é    )ÚannotationsN)ÚTYPE_CHECKINGÚLiteralÚTypeVarÚcastÚoverload)ÚalgosÚ	hashtableÚiNaTÚlib©ÚNA)ÚAnyArrayLikeÚ	ArrayLikeÚ
ArrayLikeTÚAxisIntÚDtypeObjÚTakeIndexerÚnpt)Ú
set_module)Úfind_stack_level)Ú'construct_1d_object_array_from_listlikeÚnp_find_common_type)Úensure_float64Úensure_objectÚensure_platform_intÚis_bool_dtypeÚis_complex_dtypeÚis_dict_likeÚis_dtype_equalÚis_extension_array_dtypeÚis_floatÚ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ÚABCNumpyExtensionArrayÚ	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ÚExtensionArrayÚT)ÚboundÚvaluesr   Úreturnú
np.ndarrayc                óÜ  — t          | t          ¦  «        st          | d¬¦  «        } t          | j        ¦  «        r!t          t          j        | ¦  «        ¦  «        S t          | j        t          ¦  «        r?t          d| ¦  «        } | j
        st          | j        ¦  «        S t          j        | ¦  «        S t          | j        t          ¦  «        rt          d| ¦  «        } | j        S t          | j        ¦  «        rjt          | t          j        ¦  «        r't          j        | ¦  «                             d¦  «        S t          j        | ¦  «                             dd¬¦  «        S t'          | j        ¦  «        rt          j        | ¦  «        S t)          | j        ¦  «        r1| j        j        dv rt-          | ¦  «        S t          j        | ¦  «        S t/          | j        ¦  «        rt          t          j        | ¦  «        S t1          | j        ¦  «        r1|                      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_numpyrC   r@   Úuint8F©Úcopy)é   é   é   Úi8©Údtype)Ú
isinstancer2   r;   r'   rU   r   ÚnpÚasarrayr+   r   Ú_hasnaÚ_ensure_dataÚ_datar,   Úcodesr   ÚndarrayÚviewÚastyper%   r#   Úitemsizer   r   r)   Úobject)rG   Únpvaluess     úDC:\Projects\DSCons\.venv\Lib\site-packages\pandas\core\algorithms.pyrZ   rZ   r   s!  € õ, �f�mÑ,Ô,ð ;å˜v°TÐ:Ñ:Ô:ˆå�v”|Ñ$Ô$ð -Ý�RœZ¨Ñ/Ô/Ñ0Ô0Ð0å	�F”L¥/Ñ	2Ô	2ð *åÐ'¨Ñ0Ô0ˆØŒ}ð 	.õ   ¤Ñ-Ô-Ð-ÝŒz˜&Ñ!Ô!Ð!å	�F”LÕ"2Ñ	3Ô	3ð !õ �m VÑ,Ô,ˆØŒ|Ðå	�v”|Ñ	$Ô	$ð Ý�f�bœjÑ)Ô)ð 	Bå”:˜fÑ%Ô%×*Ò*¨7Ñ3Ô3Ð3õ ”:˜fÑ%Ô%×,Ò,¨W¸5Ð,ÑAÔAÐAå	˜&œ,Ñ	'Ô	'ð ÝŒz˜&Ñ!Ô!Ð!å	˜œÑ	%Ô	%ð ð Œ<Ô  KÐ/Ð/å! &Ñ)Ô)Ð)ÝŒz˜&Ñ!Ô!Ð!å	˜&œ,Ñ	'Ô	'ð Ý•B”J Ñ'Ô'Ð'õ 
˜Vœ\Ñ	*Ô	*ð Ø—;’;˜tÑ$Ô$ˆÝ�œ
 HÑ-Ô-ˆØˆõ ŒZ˜¥fÐ-Ñ-Ô-€FÝ˜Ñ Ô Ð ó    r   rU   r   Úoriginalr   c                óþ   — t          | t          ¦  «        r| j        |k    r| S t          |t          j        ¦  «        s+|                     ¦   «         }|                     | |¬¦  «        S |                      |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
    rT   FrN   )rV   r0   rU   rW   Úconstruct_array_typeÚ_from_sequencer_   )rG   rU   re   Úclss       rc   Ú_reconstruct_datarj   À   s‚   € õ  �&Õ+Ñ,Ô,ð °´ÀÒ1FÐ1Fàˆå�e�RœXÑ&Ô&ð 7ð ×(Ò(Ñ*Ô*ˆð
 ×!Ò! &°Ð!Ñ6Ô6Ð6ð
 �=Š=˜ Uˆ=Ñ+Ô+Ð+rd   Ú	func_nameÚstrc                óŠ  — t          | t          t          t          t          j        t          f¦  «        s�|dk    r't          |› dt          | ¦  «        j	        › d�¦  «        ‚t          j        | d¬¦  «        }|dv r4t          | t          ¦  «        rt          | ¦  «        } t          | ¦  «        } nt	          j        | ¦  «        } | S )z5
    ensure that we are arraylike if not already
    úisin-targetszQ requires a Series, Index, ExtensionArray, np.ndarray or NumpyExtensionArray got ú.F©Úskipna)ÚmixedÚstringúmixed-integer)rV   r1   r4   r0   rW   r]   r3   Ú	TypeErrorÚtypeÚ__name__r   Úinfer_dtypeÚtupleÚlistr   rX   )rG   rk   Úinferreds      rc   Ú_ensure_arrayliker|   ä   sÔ   € õ ØÝ	•9Õ/µ´Õ=SÐTñô ð (ð
 ˜Ò&Ð&åØð 0ð 0å˜F‘|”|Ô,ð0ð 0ð 0ñô ð õ ”? 6°%Ð8Ñ8Ô8ˆØÐ;Ð;Ð;å˜&¥%Ñ(Ô(ð &Ý˜f™œ�Ý<¸VÑDÔDˆFˆFå”Z Ñ'Ô'ˆFØ€Mrd   )Ú
complex128Ú	complex64Úfloat64Úfloat32Úuint64Úuint32Úuint16rM   Úint64Úint32Úint16Úint8rs   ra   ú)tuple[type[htable.HashTable], np.ndarray]c                ó`   — t          | ¦  «        } t          | ¦  «        }t          |         }|| fS )z‰
    Parameters
    ----------
    values : np.ndarray

    Returns
    -------
    htable : HashTable subclass
    values : ndarray
    )rZ   Ú_check_object_for_stringsÚ_hashtables)rG   Úndtyper
   s      rc   Ú_get_hashtable_algor�     s3   € õ ˜&Ñ!Ô!€Få& vÑ.Ô.€FÝ˜FÔ#€IØ�fÐÐrd   c                óZ   — | 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
    ra   Frp   rs   )rU   Únamer   Úis_string_array)rG   rŒ   s     rc   rŠ   rŠ   &  s=   € ð Œ\Ô€FØ�ÒÐõ Ô˜v¨eÐ4Ñ4Ô4ð 	ØˆFØ€Mrd   c                ó   — d S ©N© ©rG   s    rc   Úuniquer•   A  s   € Ø˜Crd   únp.ndarray | Seriesc                ó   — d S r’   r“   r”   s    rc   r•   r•   C  s   € Ø7:°srd   Úpandasc                ó    — t          | ¦  «        S )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
        The input array-like object containing values from which to extract
        unique values.

    Returns
    -------
    numpy.ndarray, ExtensionArray or NumpyExtensionArray

        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, ExtensionArray or NumpyExtensionArray.

    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.000000'], dtype='datetime64[us]')

    >>> pd.unique(
    ...     pd.Series(
    ...         [
    ...             pd.Timestamp("20160101", tz="US/Eastern"),
    ...             pd.Timestamp("20160101", tz="US/Eastern"),
    ...         ],
    ...         dtype="M8[ns, 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"),
    ...         ],
    ...         dtype="M8[ns, 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, str): ['a', 'b', 'c']

    >>> pd.unique(pd.Series(pd.Categorical(list("baabc"), categories=list("abc"))))
    ['b', 'a', 'c']
    Categories (3, str): ['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, str): ['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)

    A NumpyExtensionArray of complex

    >>> pd.unique(pd.array([1 + 1j, 2, 3]))
    <NumpyExtensionArray>
    [(1+1j), (2+0j), (3+0j)]
    Length: 3, dtype: complex128
    )Úunique_with_maskr”   s    rc   r•   r•   G  s   € õT ˜FÑ#Ô#Ð#rd   Úintc                óì   — t          | ¦  «        dk    rdS t          | ¦  «        } t          j        |                      ¦   «                              d¦  «        ¦  «        dk                         ¦   «         }|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)ÚlenrZ   rW   ÚbincountÚravelr_   Úsum)rG   Úresults     rc   Únunique_intsr£   ´  sb   € õ ˆ6�{„{�aÒÐØˆqÝ˜&Ñ!Ô!€FåŒk˜&Ÿ,š,™.œ.×/Ò/°Ñ7Ô7Ñ8Ô8¸AÒ=×BÒBÑDÔD€FØ€Mrd   Úmaskúnpt.NDArray[np.bool_] | Nonec                ó  — t          | d¬¦  «        } t          | j        t          ¦  «        r|                      ¦   «         S t          | t
          ¦  «        r|                      ¦   «         S | }t          | ¦  «        \  }}  |t          | ¦  «        ¦  «        }|€-|                     | ¦  «        }t          ||j        |¦  «        }|S |                     | |¬¦  «        \  }}t          ||j        |¦  «        }|€J ‚|| 	                    d¦  «        fS )z?See algorithms.unique for docs. Takes a mask for masked arrays.r•   ©rk   N©r¤   Úbool)
r|   rV   rU   r-   r•   r1   r�   rž   rj   r_   )rG   r¤   re   r
   ÚtableÚuniquess         rc   rš   rš   Ë  s  € å˜v°Ð:Ñ:Ô:€Få�&”,¥Ñ/Ô/ð à�}Š}‰ŒÐå�&�(Ñ#Ô#ð à�}Š}‰ŒÐà€HÝ+¨FÑ3Ô3Ñ€IˆvàˆI•c˜&‘k”kÑ"Ô"€EØ€|Ø—,’,˜vÑ&Ô&ˆÝ# G¨X¬^¸XÑFÔFˆØˆð Ÿš V°$˜Ñ7Ô7‰ˆ�Ý# G¨X¬^¸XÑFÔFˆØÐÐÐØ˜Ÿš FÑ+Ô+Ð+Ð+rd   i@B Úcompsr=   únpt.NDArray[np.bool_]c                óð  — t          | ¦  «        s%t          dt          | ¦  «        j        › d�¦  «        ‚t          |¦  «        s%t          dt          |¦  «        j        › d�¦  «        ‚t	          |t
          t          t          t          j	        f¦  «        spt          |¦  «        }t          |d¬¦  «        }t          |¦  «        dk    r<|j        j        dv r.t          | ¦  «        st!          || ¦  «        st#          |¦  «        }n<t	          |t$          ¦  «        rt          j        |¦  «        }nt)          |dd¬¦  «        }t          | d	¬¦  «        }t)          |d¬
¦  «        }t	          |t          j	        ¦  «        s|                     |¦  «        S t-          |j        ¦  «        r"t/          |¦  «                             |¦  «        S t-          |j        ¦  «        r4t1          |j        ¦  «        s t          j        |j        t6          ¬¦  «        S t-          |j        ¦  «        r(t+          ||                     t:          ¦  «        ¦  «        S t	          |j        t<          ¦  «        r4t+          t          j        |¦  «        t          j        |¦  «        ¦  «        S t          |¦  «        t@          k    ret          |¦  «        dk    rR|j        t:          k    rBtC          d„ |D ¦   «         ¦  «        s)tE          |¦  «         !                    ¦   «         rd„ }nXd„ }nTtG          |j        |j        ¦  «        }|                     |d¬¦  «        }|                     |d¬¦  «        }tH          j%        } |||¦  «        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 `ú`rn   r§   r   ÚiufcbT)rL   Úextract_rangeÚisinrK   rT   é   c              3  ó(   K  — | ]}|t           u V — Œd S r’   r   )Ú.0Úvs     rc   ú	<genexpr>zisin.<locals>.<genexpr>9  s&   è è € Ð,Ð, �A��GÐ,Ð,Ð,Ð,Ð,Ð,rd   c                óš   — t          j        t          j        | |¦  «                             ¦   «         t          j        | ¦  «        ¦  «        S r’   )rW   Ú
logical_orr²   r    Úisnan)Úcr¶   s     rc   Úfzisin.<locals>.f?  s2   € Ý”}¥R¤W¨Q°¡]¤]×%8Ò%8Ñ%:Ô%:½B¼HÀQ¹K¼KÑHÔHÐHrd   c                óP   — t          j        | |¦  «                             ¦   «         S r’   )rW   r²   r    )ÚaÚbs     rc   ú<lambda>zisin.<locals>.<lambda>C  s   € �RœW Q¨™]œ]×0Ò0Ñ2Ô2€ rd   FrN   )&r&   ru   rv   rw   rV   r1   r4   r0   rW   r]   rz   r|   rž   rU   Úkindr(   r    r   r2   r9   r;   r²   r)   Úpd_arrayr'   ÚzerosÚshaper©   r_   ra   r-   rX   Ú_MINIMUM_COMP_ARR_LENÚanyr6   r   ÚhtableÚismember)r¬   rG   Úorig_valuesÚcomps_arrayr¼   Úcommons         rc   r²   r²   í  sn  € õ ˜ÑÔð 
Ýð@Ý(,¨U©¬Ô(<ð@ð @ð @ñ
ô 
ð 	
õ ˜ÑÔð 
ÝðAÝ(,¨V©¬Ô(=ðAð Að Añ
ô 
ð 	
õ
 �f�x­Õ4EÅrÄzÐRÑSÔSð OÝ˜6‘l”lˆÝ" ;¸.ÐIÑIÔIˆõ �‰KŒK˜!ŠOˆOØ”Ô! WÐ,Ð,Ý+¨EÑ2Ô2ð -å" 6¨5Ñ1Ô1ð -õ =¸[ÑIÔIˆFøå	�F�MÑ	*Ô	*ð Oå”˜&Ñ!Ô!ˆˆå˜v°TÈÐNÑNÔNˆå# E°VÐ<Ñ<Ô<€KÝ ¸4Ð@Ñ@Ô@€KÝ�k¥2¤:Ñ.Ô.ð Aà×Ò Ñ'Ô'Ð'å	˜[Ô.Ñ	/Ô	/ð Aå˜Ñ$Ô$×)Ò)¨&Ñ1Ô1Ð1Ý	˜Vœ\Ñ	*Ô	*ð Aµ?À;ÔCTÑ3UÔ3Uð AåŒx˜Ô)µÐ6Ñ6Ô6Ð6å	˜Vœ\Ñ	*Ô	*ð AÝ�K §¢­vÑ!6Ô!6Ñ7Ô7Ð7å	�F”L¥.Ñ	1Ô	1ð AÝ•B”J˜{Ñ+Ô+­R¬Z¸Ñ-?Ô-?Ñ@Ô@Ð@õ 	ˆKÑÔÕ0Ò0Ð0Ý�‰KŒK˜2ÒÐØÔ¥Ò'Ð'ÝÐ,Ð, VÐ,Ñ,Ô,Ñ,Ô,ð (õ
 �‰<Œ<×ÒÑÔð 	3ðIð Ið Ið Ið 3Ð2ˆAˆAõ % V¤\°;Ô3DÑEÔEˆØ—’˜v¨E�Ñ2Ô2ˆØ!×(Ò(¨°eÐ(Ñ<Ô<ˆÝŒOˆàˆ1ˆ[˜&Ñ!Ô!Ð!rd   TÚuse_na_sentinelr©   Ú	size_hintú
int | NoneÚna_valuera   ú'tuple[npt.NDArray[np.intp], np.ndarray]c                ó  — | }| j         j        dv rt          }t          | ¦  «        \  }}  ||pt	          | ¦  «        ¦  «        }|                     | 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_sentinelrÏ   r¤   Ú	ignore_na)rU   rÁ   r   r�   rž   Ú	factorizerj   r   )
rG   rÌ   rÍ   rÏ   r¤   re   Ú
hash_klassrª   r«   r\   s
             rc   Úfactorize_arrayrØ   N  s¤   € ðH €HØ„|Ô˜DÐ Ð õ
 ˆå,¨VÑ4Ô4Ñ€J�àˆJ�yÐ/¥C¨¡K¤KÑ0Ô0€EØ—_’_ØØØØØ!ð %ñ ô �N€GˆUõ   ¨¬¸ÑBÔB€Gå Ñ&Ô&€EØ�'ˆ>Ðrd   FÚsortú%tuple[np.ndarray, np.ndarray | Index]c                ó  — t          | t          t          f¦  «        r|                      ||¬¦  «        S t	          | d¬¦  «        } | }t          | t
          t          f¦  «        r$| j        �|                      |¬¦  «        \  }}||fS t          | t          j	        ¦  «        s|                      |¬¦  «        \  }}nŠt          j
        | ¦  «        } |s_| j        t          k    rOt          | ¦  «        }|                     ¦   «         r,t          | j        d¬¦  «        }t          j        ||| ¦  «        } t#          | ||¬	¦  «        \  }}|r*t%          |¦  «        d
k    rt'          |||dd¬¦  «        \  }}t)          ||j        |¦  «        }||fS )a1  
    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 : sequence
        A 1-D sequence. Sequences that aren't pandas objects are
        coerced to ndarrays before factorization.
    sort : bool, default False
        Sort `uniques` and shuffle `codes` to maintain the
        relationship.
    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
        Hint to the hashtable sizer.

    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, str): ['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='str')

    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§   N)rÙ   )rÌ   F)Úcompat)rÌ   rÍ   r   T)rÌ   Úassume_uniqueÚverify)rV   r1   r4   rÖ   r|   r/   r5   ÚfreqrW   r]   rX   rU   ra   r6   rÆ   r7   ÚwhererØ   rž   Ú	safe_sortrj   )	rG   rÙ   rÌ   rÍ   re   r\   r«   Ú	null_maskrÏ   s	            rc   rÖ   rÖ   Œ  s°  € õP �&�8¥YÐ/Ñ0Ô0ð LØ×Ò T¸?ÐÑKÔKÐKå˜v°Ð=Ñ=Ô=€FØ€Hõ 	�6Õ,Õ.?Ð@ÑAÔAð
àŒKÐ#ð  ×)Ò)¨tÐ)Ñ4Ô4‰ˆˆwØ�gˆ~Ðå˜¥¤
Ñ+Ô+ð 
à×)Ò)¸/Ð)ÑJÔJ‰ˆˆwˆwõ ”˜FÑ#Ô#ˆàð 		? 6¤<µ6Ò#9Ð#9õ
 ˜V™œˆIØ�}Š}‰Œð ?Ý-¨f¬lÀ5ÐIÑIÔI�åœ )¨X°vÑ>Ô>�å(ØØ+Øð
ñ 
ô 
‰ˆˆwð ð 
•�G‘”˜qÒ Ð Ý"ØØØ+ØØð
ñ 
ô 
‰ˆ�õ   ¨¬¸ÑBÔB€Gà�'ˆ>Ðrd   Ú	ascendingÚ	normalizeÚdropnarB   c                ó¾  — ddl m}m}m}m}	 t          | dd ¦  «        }
|rdnd}|�ýddlm} t          | |¦  «        r| j	        } 	  || |d¬¦  «        }n"# t          $ r}t          d	¦  «        |‚d }~ww xY w|                     |¬
¦  «        }||_        ||j                             ¦   «                  }|j                             d¦  «        |_        |                     ¦   «         }|r,|j	        dk                         ¦   «         r|j        dd…         }t'          |¦  «        }�n€d }t)          | ¦  «        r; || d¬¦  «        j	                             |¬
¦  «        }||_        |
|j        _        �n4t          | t*          ¦  «        rgt-          t/          | j        ¦  «        ¦  «        } || |¬¦  «                             ||¬¦  «                             ¦   «         }| j        |j        _        n¸t9          | d¬¦  «        } t;          | |¦  «        \  }}}|j        t>          j         k    r|                     t>          j!        ¦  «        } |||j        |
d¬¦  «        }|s:t          | ||	f¦  «        r(| "                    | ¦  «        r| j#        �| j#        |_$         ||||d¬¦  «        }|r| %                    |d¬¦  «        }|r|�||z  }n|| &                    ¦   «         z  }|S )Nr   )ÚDatetimeIndexrA   rB   ÚTimedeltaIndexr�   Ú
proportionÚcount)ÚcutT)Úinclude_lowestz+bins argument only works with numeric data.©rå   ÚintervalFrN   )Úindexr�   )Úlevelrå   Úvalue_countsr§   )rU   r�   rO   )rï   r�   rO   Ústable)rã   rÁ   )'r˜   rç   rA   rB   rè   ÚgetattrÚpandas.core.reshape.tilerë   rV   Ú_valuesru   rñ   r�   rï   Únotnar_   Ú
sort_indexÚallÚilocrž   r!   r2   rz   ÚrangeÚnlevelsÚgroupbyÚsizeÚnamesr|   Úvalue_counts_arraylikerU   rW   Úfloat16r€   ÚequalsÚinferred_freqrß   Úsort_valuesr¡   )rG   rÙ   rã   rä   Úbinsrå   rç   rA   rB   rè   Ú
index_namer�   rë   ÚiiÚerrr¢   Únormalize_denominatorÚlevelsÚkeysÚcountsÚ_Úidxs                         rc   Úvalue_counts_internalr  I  se  € ðð ð ð ð ð ð ð ð ð ð ð õ ˜ ¨Ñ.Ô.€JØ$Ð1ˆ<ˆ<¨'€DàÐØ0Ð0Ð0Ð0Ð0Ð0å�f˜fÑ%Ô%ð 	$Ø”^ˆFð	TØ��V˜T°$Ð7Ñ7Ô7ˆBˆBøÝð 	Tð 	Tð 	TÝÐIÑJÔJÐPSÐSøøøøð	Tøøøð —’¨�Ñ/Ô/ˆØˆŒØ˜œ×*Ò*Ñ,Ô,Ô-ˆØ”|×*Ò*¨:Ñ6Ô6ˆŒØ×"Ò"Ñ$Ô$ˆð ð 	&�v”~¨Ò*×/Ò/Ñ1Ô1ð 	&Ø”[  1 Ô%ˆFõ !$ B¡¤ÐÑð !%ÐÝ# FÑ+Ô+ð #	Fà�V˜F¨Ð/Ñ/Ô/Ô7×DÒDÈFÐDÑSÔSˆFØˆFŒKØ *ˆFŒLÔÑå˜¥Ñ.Ô.ð 	Få�% ¤Ñ/Ô/Ñ0Ô0ˆFà�˜V¨$Ð/Ñ/Ô/ß’˜v¨f�Ñ5Ô5ß’‘”ð ð
 "(¤ˆFŒLÔÐõ ' v¸ÐHÑHÔHˆFÝ4°V¸VÑDÔD‰OˆD�&˜!ØŒz�RœZÒ'Ð'Ø—{’{¥2¤:Ñ.Ô.�ð �%˜ D¤J°ZÀeÐLÑLÔLˆCð ð0å˜v¨°~Ð'FÑGÔGð0ð —J’J˜vÑ&Ô&ð0ð Ô(Ð4ð "Ô/�”à�V˜F¨#°D¸uÐEÑEÔEˆFàð HØ×#Ò#¨i¸hÐ#ÑGÔGˆàð +Ø Ð,ØÐ3Ñ3ˆFˆFà˜fŸjšj™lœlÑ*ˆFà€Ms   ÁA Á
A2ÁA-Á-A2ú,tuple[ArrayLike, npt.NDArray[np.int64], int]c                óò   — | }t          | ¦  «        } t          j        | ||¬¦  «        \  }}}t          |j        ¦  «        r|r|t
          k    }||         ||         }}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¨   )rZ   rÇ   Úvalue_countr)   rU   r   rj   )rG   rå   r¤   re   r
  r  Ú
na_counterÚres_keyss           rc   rÿ   rÿ   ¨  sŠ   € ð €HÝ˜&Ñ!Ô!€Få%Ô1°&¸&ÀtÐLÑLÔLÑ€Dˆ&�*å˜8œ>Ñ*Ô*ð 4ð ð 	4Ø�4’<ˆDØ œ: v¨d¤|�&ˆDå   x¤~°xÑ@Ô@€HØ�V˜ZÐ'Ð'rd   ÚfirstÚkeepúLiteral['first', 'last', False]c                óN   — 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]
    )r  r¤   )rZ   rÇ   Ú
duplicated)rG   r  r¤   s      rc   r  r  Ç  s)   € õ2 ˜&Ñ!Ô!€FÝÔ˜V¨$°TÐ:Ñ:Ô:Ð:rd   ú9tuple[np.ndarray, npt.NDArray[np.bool_]] | ExtensionArrayc                ó2  — t          | d¬¦  «        } | }t          | j        ¦  «        r5t          | ¦  «        } t	          d| ¦  «        } |                      |¬¦  «        S t          | ¦  «        } t          j        | ||¬¦  «        \  }}|€&t          j
        |j        t          j        ¬¦  «        }n||fS 	 t          |¦  «        }n<# t          $ r/}t          j        d|› �t#          ¦   «         ¬	¦  «         Y d}~nd}~ww xY wt%          ||j        |¦  «        }||fS )
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
    -------
    Union[Tuple[np.ndarray, npt.NDArray[np.bool_]], ExtensionArray]
    Úmoder§   rD   rí   )rå   r¤   NrT   zUnable to sort modes: )Ú
stacklevel)r|   r)   rU   r:   r   Ú_moderZ   rÇ   r  rW   rÃ   rÄ   Úbool_rá   ru   ÚwarningsÚwarnr   rj   )rG   rå   r¤   re   ÚnpresultÚres_maskr  r¢   s           rc   r  r  ä  sJ  € õ" ˜v°Ð8Ñ8Ô8€FØ€Hå˜6œ<Ñ(Ô(ð +å/°Ñ7Ô7ˆÝÐ&¨Ñ/Ô/ˆØ�|Š| 6ˆ|Ñ*Ô*Ð*å˜&Ñ!Ô!€Fåœ V°FÀÐFÑFÔFÑ€HˆhØÐÝ”8˜HœNµ"´(Ð;Ñ;Ô;ˆˆà˜Ð!Ð!ð
Ý˜XÑ&Ô&ˆˆøÝð 
ð 
ð 
ÝŒØ* SÐ*Ð*Ý'Ñ)Ô)ð	
ñ 	
ô 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
øøøøð
øøøõ ˜x¨¬¸ÑBÔB€FØ�8ÐÐs   Â3C Ã
C<Ã%C7Ã7C<ÚaverageÚaxisr   ÚmethodÚ	na_optionÚpctúnpt.NDArray[np.float64]c           	     ó  — t          | j        ¦  «        }t          | ¦  «        } | j        dk    rt	          j        | ||||||¬¦  «        }n:| j        dk    r |�J ‚t	          j        | ||||||¬¦  «        }nt          d¦  «        ‚|S )ab  
    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).
    mask : bool ndarray, optional
        Boolean array indicating which elements to exclude from ranking.
    é   )Úis_datetimelikeÚties_methodrã   r&  r'  r¤   rP   N)r$  r+  r,  rã   r&  r'  z&Array with ndim > 2 are not supported.)r)   rU   rZ   Úndimr	   Úrank_1dÚrank_2dru   )	rG   r$  r%  r&  rã   r'  r¤   r+  Úrankss	            rc   Úrankr1    s¶   € õD *¨&¬,Ñ7Ô7€OÝ˜&Ñ!Ô!€Fà„{�aÒÐÝ”ØØ+ØØØØØð
ñ 
ô 
ˆˆð 
Œ˜Ò	Ð	Øˆ|ˆ|ˆ|Ý”ØØØ+ØØØØð
ñ 
ô 
ˆˆõ Ð@ÑAÔAÐAà€Lrd   zpandas.api.extensionsÚindicesr   Ú
allow_fillc                óf  — t          | t          j        t          t          t
          t          f¦  «        s%t          dt          | ¦  «        j	        › d�¦  «        ‚t          |¦  «        }|r0t          || j        |         ¦  «         t          | ||d|¬¦  «        }n|                      ||¬¦  «        }|S )a§  
    Take elements from an array.

    Parameters
    ----------
    arr : numpy.ndarray, ExtensionArray, Index, or Series
        Input array.
    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])
    zkpd.api.extensions.take requires a numpy.ndarray, ExtensionArray, Index, Series, or NumpyExtensionArray got ro   T)r$  r3  Ú
fill_value)r$  )rV   rW   r]   r0   r1   r4   r3   ru   rv   rw   r   r<   rÄ   r8   Útake)Úarrr2  r$  r3  r5  r¢   s         rc   r6  r6  W  sÔ   € õb ØÝ	ŒÕ&­µ)Õ=SÐTñô ð 
õ
 ðOÝ9=¸c¹¼Ô9KðOð Oð Oñ
ô 
ð 	
õ
 " 'Ñ*Ô*€Gàð .å˜ #¤)¨D¤/Ñ2Ô2Ð2õ ØØØØØ!ð
ñ 
ô 
ˆˆð —’˜'¨�Ñ-Ô-ˆØ€Mrd   Úleftr7  Úvalueú$NumpyValueArrayLike | ExtensionArrayÚsideúLiteral['left', 'right']ÚsorterúNumpySorter | Noneúnpt.NDArray[np.intp] | np.intpc                óú  — |�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                         ¦   «         r%||j        k                         ¦   «         r| j        }n|j        }t          |¦  «        r)t          t          | 	                    |¦  «        ¦  «        }n4t!          t          t"          |¦  «        |¬¦  «        }nt%          | ¦  «        } |                      |||¬¦  «        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.
    NÚiurT   )r;  r=  )r   rV   rW   r]   rU   rÁ   r$   r%   Úiinforv   r9   Úminrø   Úmaxr   r›   rÂ   r   r:   Úsearchsorted)r7  r9  r;  r=  rB  Ú	value_arrrU   s          rc   rE  rE  Í  s\  € ð` ÐÝ$ VÑ,Ô,ˆõ 	�3�œ
Ñ#Ô#ñ2àŒIŒN˜dÐ"Ñ"Ý˜ÑÔð #Ý"2°5Ñ"9Ô"9ð #õ ”˜œœÑ(Ô(ˆÝ)3°EÑ):Ô):ÐO•B”H˜e˜WÑ%Ô%Ð%ÅÄÈÁÄˆ	Ø˜œÒ"×'Ò'Ñ)Ô)ð 	$¨y¸E¼IÒ/E×.JÒ.JÑ.LÔ.Lð 	$ð ”IˆEˆEà”OˆEå�eÑÔð 	Bå�˜eŸjšj¨Ñ/Ô/Ñ0Ô0ˆEˆEå�T¥)¨UÑ3Ô3¸5ÐAÑAÔAˆEˆEõ -¨SÑ1Ô1ˆð ×Ò˜E¨°VÐÑ<Ô<Ð<rd   >   r‡   r†   r…   r„   r€   r   Únú&int | float | np.integer | np.floatingc                ó0  — t          j        |¦  «        sAt          |¦  «        r|                     ¦   «         st          d¦  «        ‚t	          |¦  «        }t
          j        }| j        }t          |¦  «        }|rt          j
        }nt          j        }t          |t          ¦  «        r|                      ¦   «         } | j        }t          | t
          j        ¦  «        s‰t!          | d|j        › d�¦  «        rL|dk    r't          dt%          | ¦  «        j        › d|› �¦  «        ‚ || |                      |¦  «        ¦  «        S t)          t%          | ¦  «        j        › d�¦  «        ‚d}| j        j        dv r+t
          j        }|                      d	¦  «        } t0          }d
}n?|rt
          j        }n0|j        dv r'| j        j        dv rt
          j        }nt
          j        }| j        }|dk    r|                      dd¦  «        } t          j        |¦  «        }t          j        | j         |¬¦  «        }	tC          d¦  «        gdz  }
|dk    rtC          d|¦  «        ntC          |d¦  «        |
|<   ||	tE          |
¦  «        <   | j        j        tF          v r'tI          j%        | |	t	          |¦  «        ||¬¦  «         n³tC          d¦  «        gdz  }|dk    rtC          |d¦  «        ntC          d|¦  «        ||<   tE          |¦  «        }tC          d¦  «        gdz  }|dk    rtC          d| ¦  «        ntC          | d¦  «        ||<   tE          |¦  «        } || |         | |         ¦  «        |	|<   |r|	                     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
    zperiods must be an integerÚ__r   zcannot diff z	 on axis=zK has no 'diff' method. Convert to a suitable dtype prior to calling 'diff'.FrÒ   rS   TrA  )r‡   r†   r*  rÓ   rT   NrP   )Údatetimelikeztimedelta64[ns])&r   r$   r"   Ú
ValueErrorr›   rW   ÚnanrU   r   ÚoperatorÚxorÚsubrV   r.   Úto_numpyr]   Úhasattrrw   rv   Úshiftru   rÁ   r„   r^   r   Úobject_r�   r€   r   r-  ÚreshapeÚemptyrÄ   Úslicery   Ú_diff_specialr	   Údiff_2d)r7  rG  r$  ÚnarU   Úis_boolÚopÚis_timedeltaÚ	orig_ndimÚout_arrÚ
na_indexerÚ_res_indexerÚres_indexerÚ_lag_indexerÚlag_indexers                  rc   Údiffre  (  s  € õ, Œ>˜!ÑÔð Ý˜‘”ð 	; §¢¡¤ð 	;ÝÐ9Ñ:Ô:Ð:Ý�‰FŒFˆÝ	Œ€BØŒI€Eå˜EÑ"Ô"€GØð ÝŒ\ˆˆåŒ\ˆå�%�Ñ&Ô&ð à�lŠl‰nŒnˆØ”	ˆå�c�2œ:Ñ&Ô&ð 
å�3Ð,˜Rœ[Ð,Ð,Ð,Ñ-Ô-ð 	Ø�qŠyˆyÝ Ð!Sµ°S±	´	Ô0BÐ!SÐ!SÈTÐ!SÐ!SÑTÔTÐTØ�2�c˜3Ÿ9š9 Q™<œ<Ñ(Ô(Ð(åÝ˜‘9”9Ô%ð Gð Gð Gñô ð ð
 €LØ
„y„~˜ÐÐÝ”ˆØ�hŠh�t‰nŒnˆÝˆØˆˆà	ð å”
ˆˆà	Œ�tÐ	Ð	ð
 Œ9Œ>Ð.Ð.Ð.Ý”JˆEˆEå”JˆEà”€IØ�A‚~€~à�kŠk˜"˜aÑ Ô ˆõ ŒH�U‰OŒO€EÝŒh�s”y¨Ð.Ñ.Ô.€Gå˜‘+”+� Ñ"€JØ)*¨aª¨•u˜T 1‘~”~�~µU¸1¸d±^´^€JˆtÑØ!#€G�E�*ÑÔÑà
„y„~�Ð&Ð&õ 	Œ�c˜7¥C¨¡F¤F¨D¸|ÐLÑLÔLÐLÐLõ ˜d™œ�} qÑ(ˆØ/0°Aªv¨v�U 1 d™^œ^˜^½5ÀÀq¹>¼>ˆ�TÑÝ˜LÑ)Ô)ˆå˜d™œ�} qÑ(ˆØ01°A²°�U 4¨!¨™_œ_˜_½5À!ÀÀT¹?¼?ˆ�TÑÝ˜LÑ)Ô)ˆà!˜r # kÔ"2°C¸Ô4DÑEÔEˆ�Ñàð 2Ø—,’,Ð0Ñ1Ô1ˆà�A‚~€~Ø˜!˜!˜!˜Q˜$”-ˆØ€Nrd   úIndex | ArrayLiker\   únpt.NDArray[np.intp] | NonerÝ   rÞ   ú.AnyArrayLike | tuple[AnyArrayLike, np.ndarray]c                óŒ  — t          | t          j        t          t          f¦  «        st          d¦  «        ‚d}t          | j        t          ¦  «        s*t          j	        | d¬¦  «        dk    rt          | ¦  «        }nˆ	 |                      ¦   «         }|                      |¦  «        }n]# t
          t          j        f$ rD | j        r+t          | d         t           ¦  «        rt#          | ¦  «        }nt          | ¦  «        }Y nw xY w|€|S t%          |¦  «        st          d¦  «        ‚t'          t          j        |¦  «        ¦  «        }|s<t+          t-          | ¦  «        ¦  «        t+          | ¦  «        k    st/          d¦  «        ‚|€at1          | ¦  «        \  }}  |t+          | ¦  «        ¦  «        }|                     | ¦  «         t'          |                     |¦  «        ¦  «        }|rV|                     ¦   «         }	|r-|t+          | ¦  «         k     |t+          | ¦  «        k    z  }
d	||
<   t7          |	|d	¬
¦  «        }ntt          j        t+          |¦  «        t:          ¬¦  «        }|                     |t          j        t+          |¦  «        ¦  «        ¦  «         |                     |d¬¦  «        }|t'          |¦  «        fS )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 valuesNFrp   rt   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Ó   ©r5  rT   Úwrap)r  ) rV   rW   r]   r0   r1   ru   rU   r-   r   rx   Ú_sort_mixedÚargsortr6  ÚdecimalÚInvalidOperationrý   ry   Ú_sort_tuplesr&   r   rX   rž   r•   rL  r�   Úmap_locationsÚlookupr8   rV  r›   ÚputÚarange)rG   r\   rÌ   rÝ   rÞ   r=  Úorderedr×   ÚtÚorder2r¤   Ú	new_codesÚreverse_indexers                rc   rá   rá   ž  s´  € õ` �f�rœzÕ+<½hÐGÑHÔHð 
Ýð/ñ
ô 
ð 	
ð
 €Fõ �v”|¥^Ñ4Ô4ð.åŒO˜F¨5Ð1Ñ1Ô1°_ÒDÐDå˜fÑ%Ô%ˆˆð	.Ø—^’^Ñ%Ô%ˆFØ—k’k &Ñ)Ô)ˆGˆGøÝ�7Ô3Ð4ð 
	.ð 
	.ð 
	.ð Œ{ð .�z¨&°¬)µUÑ;Ô;ð .õ ' vÑ.Ô.��å% fÑ-Ô-�øøð
	.øøøð €}Øˆå˜ÑÔð 
Ýð.ñ
ô 
ð 	
õ  ¥¤
¨5Ñ 1Ô 1Ñ2Ô2€Eàð I¥¥V¨F¡^¤^Ñ!4Ô!4½¸F¹¼Ò!CÐ!CÝÐGÑHÔHÐHà€~õ
 1°Ñ8Ô8Ñˆ
�FØˆJ•s˜6‘{”{Ñ#Ô#ˆØ	�Š˜ÑÔÐõ % Q§X¢X¨gÑ%6Ô%6Ñ7Ô7ˆàð =à—’Ñ!Ô!ˆØð 	Ø�S ™[œ[˜LÒ(¨Uµc¸&±k´kÒ-AÑBˆDØˆE�$‰KÝ˜F E°bÐ9Ñ9Ô9ˆ	ˆ	åœ(¥3 v¡;¤;µcÐ:Ñ:Ô:ˆØ×Ò˜F¥B¤I­c°&©k¬kÑ$:Ô$:Ñ;Ô;Ð;ð $×(Ò(¨°VÐ(Ñ<Ô<ˆ	àÕ'¨	Ñ2Ô2Ð2Ð2s   Á>)B( Â(ADÄDc                óL  — t          j        d„ | D ¦   «         t          ¬¦  «        }t          j        d„ | D ¦   «         t          ¬¦  «        }| | z  }t          j        | |         ¦  «        }t          j        | |         ¦  «        }|                     ¦   «         d                              |¦  «        }|                     ¦   «         d                              |¦  «        }|                     ¦   «         d         }t          j        |||g¦  «        }	|                      |	¦  «        S )z3order ints before strings before nulls in 1d arraysc                ó8   — g | ]}t          |t          ¦  «        ‘ŒS r“   )rV   rl   ©rµ   Úxs     rc   ú
<listcomp>z_sort_mixed.<locals>.<listcomp>  s"   € Ð;Ð;Ð;¨q�
 1¥cÑ*Ô*Ð;Ð;Ð;rd   rT   c                ó,   — g | ]}t          |¦  «        ‘ŒS r“   )r6   r|  s     rc   r~  z_sort_mixed.<locals>.<listcomp>  s   € Ð1Ð1Ð1 Q�˜a™œÐ1Ð1Ð1rd   r   )rW   r9   r©   rm  Únonzeror6  Úconcatenate)
rG   Ústr_posÚnull_posÚnum_posÚstr_argsortÚnum_argsortÚstr_locsÚnum_locsÚ	null_locsÚlocss
             rc   rl  rl    sþ   € åŒhÐ;Ð;°FÐ;Ñ;Ô;Å4ÐHÑHÔH€GÝŒxÐ1Ð1¨&Ð1Ñ1Ô1½Ð>Ñ>Ô>€HØˆh˜(˜Ñ"€GÝ”*˜V Gœ_Ñ-Ô-€KÝ”*˜V Gœ_Ñ-Ô-€Kà�ŠÑ Ô  Ô#×(Ò(¨Ñ5Ô5€HØ�ŠÑ Ô  Ô#×(Ò(¨Ñ5Ô5€HØ× Ò Ñ"Ô" 1Ô%€IÝŒ>˜8 X¨yÐ9Ñ:Ô:€DØ�;Š;�tÑÔÐrd   c                ób   — 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�  )rG   rŒ  r�  Úarraysr  Úindexers         rc   rp  rp  '  s[   € ð =Ð<Ð<Ð<Ð<Ð<Ø3Ð3Ð3Ð3Ð3Ð3à�	˜& $Ñ'Ô'�I€FˆAØˆo˜f¨TÐ2Ñ2Ô2€GØ�'Œ?Ðrd   ÚlvalsúArrayLike | IndexÚrvalsc                ó¼  — ddl m} t          | d¬¦  «        }t          |d¬¦  «        }|                     |d¬¦  «        \  }}t	          j        |j        |j        ¦  «        } |||j        dd¬¦  «        }t          | t          ¦  «        r=t          |t          ¦  «        r(|  
                    |¦  «                             ¦   «         }ngt          | t          ¦  «        r| j        } t          |t          ¦  «        r|j        }t          | |g¦  «        }t          |¦  «        }t          |¦  «        }|                     |¦  «        j        }t	          j        ||¦  «        S )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   ©rB   Frí   rj  r›   )rï   rU   rO   )r˜   rB   r  ÚalignrW   ÚmaximumrG   rï   rV   r2   Úappendr•   r1   rõ   r*   r:   ÚreindexÚrepeat)	r“  r•  rB   Úl_countÚr_countÚfinal_countÚunique_valsÚcombinedÚrepeatss	            rc   Úunion_with_duplicatesr£  6  sN  € ð. ÐÐÐÐÐå# E°%Ð8Ñ8Ô8€GÝ# E°%Ð8Ñ8Ô8€GØ—}’} W¸�}Ñ;Ô;Ñ€GˆWÝ”*˜Wœ^¨W¬^Ñ<Ô<€KØ�&˜¨G¬MÀÈUÐSÑSÔS€KÝ�%�Ñ'Ô'ð B­J°u½mÑ,LÔ,Lð BØ—l’l 5Ñ)Ô)×0Ò0Ñ2Ô2ˆˆå�e�XÑ&Ô&ð 	"Ø”MˆEÝ�e�XÑ&Ô&ð 	"Ø”MˆEõ ! %¨ Ñ0Ô0ˆÝ˜XÑ&Ô&ˆÝ4°[ÑAÔAˆØ×!Ò! +Ñ.Ô.Ô5€GÝŒ9�[ 'Ñ*Ô*Ð*rd   Ú	na_actionúLiteral['ignore'] | Noneú#np.ndarray | ExtensionArray | Indexc                óÚ  ‡	— ddl m} |dvrd|› d�}t          |¦  «        ‚t          |¦  «        r»t	          |t
          ¦  «        rt          |d¦  «        r|Š	ˆ	fd„}nŽddl m} t          |¦  «        dk    r ||t          j
        ¬	¦  «        }n]t	          |t
          ¦  «        r= ||                     ¦   «          ||                     ¦   «         d
¬¦  «        ¬¦  «        }n ||¦  «        }t	          |t          ¦  «        rV|dk    r||j                             ¦   «                  }|j                             | ¦  «        }t#          |j        |¦  «        }|S t          | ¦  «        s|                      ¦   «         S |                      t*          d
¬¦  «        }|€t-          j        ||¦  «        S t-          j        ||t3          |¦  «                             t          j        ¦  «        ¬¦  «        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.

    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.
    r   )rA   )NÚignorez+na_action must either be 'ignore' or None, z was passedÚ__missing__c                ó~   •— ‰t          | t          ¦  «        r t          j        | ¦  «        rt          j        n|          S r’   )rV   ÚfloatrW   rº   rM  )r}  Údict_with_defaults    €rc   rÀ   zmap_array.<locals>.<lambda>Š  s2   ø€ Ð0Ý$ Q­Ñ.Ô.ÐEµ2´8¸A±;´;ÐE•”�ÀAô € rd   r—  rT   F)Útupleize_cols)rï   r¨  rN   Nr¨   )r˜   rA   rL  r   rV   ÚdictrR  rB   rž   rW   r   rG   r
  r4   rï   rö   Úget_indexerr8   rõ   rO   r_   ra   r   Ú	map_inferÚmap_infer_maskr6   r^   rM   )
r7  Úmapperr¤  rA   ÚmsgrB   r’  Ú
new_valuesrG   r¬  s
            @rc   Ú	map_arrayrµ  e  s
  ø€ ð. ÐÐÐÐÐàÐ(Ð(Ð(ØR¸IÐRÐRÐRˆÝ˜‰oŒoÐõ
 �FÑÔð (Ý�f�dÑ#Ô#ð 	(­°¸Ñ(FÔ(Fð 	(ð !'Ððð ð ð ˆFˆFð &Ð%Ð%Ð%Ð%Ð%å�6‰{Œ{˜aÒÐØ˜ ­b¬jÐ9Ñ9Ô9��Ý˜F¥DÑ)Ô)ð (Ø˜Ø—M’M‘O”O¨5¨5°·²±´ÈeÐ+TÑ+TÔ+Tðñ ô ��ð  ˜ ™œ�å�&�)Ñ$Ô$ð 	Ø˜Ò Ð Ø˜FœL×.Ò.Ñ0Ô0Ô1ˆFð ”,×*Ò*¨3Ñ/Ô/ˆÝ˜Vœ^¨WÑ5Ô5ˆ
àÐåˆs‰8Œ8ð Ø�xŠx‰zŒzÐð �ZŠZ� UˆZÑ+Ô+€FØÐÝŒ}˜V VÑ,Ô,Ð,åÔ! &¨&µt¸F±|´|×7HÒ7HÍÌÑ7RÔ7RÐSÑSÔSÐSrd   )rG   r   rH   rI   )rG   r   rU   r   re   r   rH   r   )rk   rl   rH   r   )rG   rI   rH   rˆ   )rG   rI   rH   rl   )rG   rE   rH   rE   )rG   r–   rH   rI   )rG   r   rH   r›   r’   )r¤   r¥   )r¬   r=   rG   r=   rH   r­   )TNNN)rG   rI   rÌ   r©   rÍ   rÎ   rÏ   ra   r¤   r¥   rH   rÐ   )FTN)rÙ   r©   rÌ   r©   rÍ   rÎ   rH   rÚ   )TFFNT)
rÙ   r©   rã   r©   rä   r©   rå   r©   rH   rB   )rG   rI   rå   r©   r¤   r¥   rH   r  )r  N)rG   r   r  r  r¤   r¥   rH   r­   )TN)rG   r   rå   r©   r¤   r¥   rH   r  )r   r#  r  TFN)rG   r   r$  r   r%  rl   r&  rl   rã   r©   r'  r©   r¤   r¥   rH   r(  )r   FN)r2  r   r$  r   r3  r©   )r8  N)
r7  r   r9  r:  r;  r<  r=  r>  rH   r?  )r   )rG  rH  r$  r   )NTFT)rG   rf  r\   rg  rÌ   r©   rÝ   r©   rÞ   r©   rH   rh  )rH   r   )rG   rI   rH   rI   )r“  r”  r•  r”  rH   r”  )r7  r   r¤  r¥  rH   r¦  )†Ú__doc__Ú
__future__r   rn  rN  Útypingr   r   r   r   r   r  ÚnumpyrW   Úpandas._libsr	   r
   rÇ   r   r   Úpandas._libs.missingr   Úpandas._typingr   r   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(   r)   Úpandas.core.dtypes.concatr*   Úpandas.core.dtypes.dtypesr+   r,   r-   r.   Úpandas.core.dtypes.genericr/   r0   r1   r2   r3   r4   r5   Úpandas.core.dtypes.missingr6   r7   Úpandas.core.array_algos.taker8   Úpandas.core.constructionr9   rÂ   r:   r;   Úpandas.core.indexersr<   r=   r>   r?   r˜   r@   rA   rB   Úpandas.core.arraysrC   rD   rE   rZ   rj   r|   Ú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  r1  r6  rE  rX  re  rá   rl  rp  r£  rµ  r“   rd   rc   ú<module>rØ     sø  ððð ð
 #Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€ðð ð ð ð ð ð ð ð ð ð ð ð ð ð €€€à Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð ð ð $Ð #Ð #Ð #Ð #Ð #ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð /Ð .Ð .Ð .Ð .Ð .Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4ðð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð$ 4Ð 3Ð 3Ð 3Ð 3Ð 3ðð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð
 1Ð 0Ð 0Ð 0Ð 0Ð 0ðð ð ð ð ð ð ð ð ð ð
 2Ð 1Ð 1Ð 1Ð 1Ð 1àð Aðð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð
ð ð ð ð ð ð ð ð
 	ˆ�˜5 ;Ñ.°Ñ?Ð@Ñ@Ô@€AðK!ð K!ð K!ð K!ð\!,ð !,ð !,ð !,ðHð ð ð ð: Ô,ØÔ*ØÔ&ØÔ&ØÔ$ØÔ$ØÔ$ØÔ"ØÔ"ØÔ"ØÔ"ØÔ ØÔ$ØÔ&ðð €ð$ð ð ð ð(ð ð ð ð6 
Ø Ð Ð ñ 
„Ø Ø	Ø :Ð :Ð :ñ 
„Ø :ð €ˆHÑÔði$ð i$ñ Ôði$ðXð ð ð ð.,ð ,ð ,ð ,ð ,ð8 €ð "Ð ð^"ð ^"ð ^"ð ^"ðF !Ø ØØ)-ð;ð ;ð ;ð ;ð ;ð| €ˆHÑÔð Ø Ø ð	yð yð yð yñ Ôðyð| ØØØ	Øð[ð [ð [ð [ð [ð@ LPð(ð (ð (ð (ð (ðB -4Ø)-ð;ð ;ð ;ð ;ð ;ð< RVð+ð +ð +ð +ð +ð` ØØØØØ)-ð=ð =ð =ð =ð =ðJ €Ð#Ñ$Ô$ð ØØðmð mð mð mñ %Ô$ðmðp &,Ø!%ð	Q=ð Q=ð Q=ð Q=ð Q=ðp JÐIÐI€ðlð lð lð lð lðp *.Ø ØØðw3ð w3ð w3ð w3ð w3ðtð ð ð ðð ð ð ð,+ð ,+ð ,+ð ,+ðd +/ðPTð PTð PTð PTð PTð PTð PTrd   