
    d]                    <   U d Z ddlmZ ddlZddlmZmZmZmZm	Z	m
Z
mZmZmZmZ ddlZddl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# ddl$m%Z%m&Z& ddl'm(Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZAmBZB erddlmCZCmDZDmEZEmFZF ddlGmHZHmIZImJZJ i ZKdeLd<   dddddZM edd          ZN G d de;          ZO G d  d!          ZP G d" d#ee                   ZQ G d$ de=          ZRdS )%z.
Base and utility classes for pandas objects.
    )annotationsN)
TYPE_CHECKINGAnyGenericHashableIteratorLiteralTypeVarcastfinaloverload)using_copy_on_write)lib)AxisAxisIntDtypeObj
IndexLabelNDFrameTShapenpt)PYPY)functionAbstractMethodError)cache_readonlydoc)can_hold_element)is_categorical_dtypeis_dict_likeis_extension_array_dtypeis_object_dtype	is_scalar)ABCDataFrameABCIndex	ABCSeries)isnaremove_na_arraylike)
algorithmsnanopsops)DirNamesMixin)OpsMixin)ExtensionArray)ensure_wrapped_if_datetimelikeextract_array)DropKeepNumpySorterNumpyValueArrayLikeScalarLike_co)CategoricalIndexSerieszdict[str, str]_shared_docsIndexOpsMixin )klassinplaceunique
duplicated_T)boundc                  X     e Zd ZU dZded<   ed             ZddZdddZd fdZ	 xZ
S )PandasObjectz/
    Baseclass for various pandas objects.
    zdict[str, Any]_cachec                     t          |           S )zJ
        Class constructor (for this class it's just `__class__`.
        )typeselfs    L/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/pandas/core/base.py_constructorzPandasObject._constructorl   s    
 Dzz    returnstrc                6    t                               |           S )zI
        Return a string representation for a particular object.
        )object__repr__rE   s    rG   rN   zPandasObject.__repr__s   s    
 t$$$rI   Nkey
str | NoneNonec                    t          | d          sdS || j                                         dS | j                            |d           dS )zV
        Reset cached properties. If ``key`` is passed, only clears that key.
        rB   N)hasattrrB   clearpop)rF   rO   s     rG   _reset_cachezPandasObject._reset_cachez   sV     tX&& 	F;KKOOC&&&&&rI   intc                    t          | dd          }|r> |d          }t          t          |          r|n|                                          S t	                                                      S )zx
        Generates the total memory usage for an object that returns
        either a value or Series of values
        memory_usageNTdeep)getattrrW   r"   sumsuper
__sizeof__)rF   rY   mem	__class__s      rG   r_   zPandasObject.__sizeof__   sm    
 t^T:: 	=,D)))Cinn;ss#''))<<< ww!!###rI   )rJ   rK   N)rO   rP   rJ   rQ   rJ   rW   )__name__
__module____qualname____doc____annotations__propertyrH   rN   rV   r_   __classcell__)ra   s   @rG   rA   rA   d   s          
   X% % % %	' 	' 	' 	' 	'$ $ $ $ $ $ $ $ $ $rI   rA   c                  "    e Zd ZdZd	dZd
dZdS )NoNewAttributesMixina  
    Mixin which prevents adding new attributes.

    Prevents additional attributes via xxx.attribute = "something" after a
    call to `self.__freeze()`. Mainly used to prevent the user from using
    wrong attributes on an accessor (`Series.cat/.str/.dt`).

    If you really want to add a new attribute at a later time, you need to use
    `object.__setattr__(self, key, value)`.
    rJ   rQ   c                >    t                               | dd           dS )z9
        Prevents setting additional attributes.
        __frozenTN)rM   __setattr__rE   s    rG   _freezezNoNewAttributesMixin._freeze   s"     	4T22222rI   rO   rK   c                    t          | dd          r@|dk    s:|t          |           j        v s$t          | |d           t          d| d          t                              | ||           d S )Nrn   FrB   z"You cannot add any new attribute '')r\   rD   __dict__AttributeErrorrM   ro   )rF   rO   values      rG   ro   z NoNewAttributesMixin.__setattr__   s     4U++ 	N8OOd4jj)))tS$''3 !Lc!L!L!LMMM4e,,,,,rI   N)rJ   rQ   )rO   rK   rJ   rQ   )rd   re   rf   rg   rp   ro    rI   rG   rl   rl      sF        	 	3 3 3 3- - - - - -rI   rl   c                      e Zd ZU dZded<   dZded<   ded<   d	d
gZ ee          Ze	e
d                         Zed             Ze	edd                        Ze	ed                         Zd ZdddZd ZeZdS )SelectionMixinz
    mixin implementing the selection & aggregation interface on a group-like
    object sub-classes need to define: obj, exclusions
    r   objNzIndexLabel | None
_selectionzfrozenset[Hashable]
exclusionsrB   __setstate__c                    t          | j        t          t          t          t
          t          j        f          s| j        gS | j        S rb   )
isinstancerz   listtupler%   r$   npndarrayrE   s    rG   _selection_listzSelectionMixin._selection_list   s?     OdE9h
K
 
 	% O$$rI   c                v    | j         t          | j        t                    r| j        S | j        | j                  S rb   )rz   r~   ry   r%   rE   s    rG   _selected_objzSelectionMixin._selected_obj   s1    ?"j9&E&E"8O8DO,,rI   rJ   rW   c                    | j         j        S rb   )r   ndimrE   s    rG   r   zSelectionMixin.ndim   s     !&&rI   c                   t          | j        t                    r| j        S | j        | j                            | j                  S t          | j                  dk    r"| j                            | j        dd          S | j        S )Nr      T)axis
only_slice)	r~   ry   r%   rz   _getitem_nocopyr   lenr{   
_drop_axisrE   s    rG   _obj_with_exclusionsz#SelectionMixin._obj_with_exclusions   s}     dh	** 	8O?&8++D,@AAAt!##
 8&&tQ4&PPP8OrI   c                   | j         t          d| j          d          t          |t          t          t
          t          t          j        f          rt          | j
        j                            |                    t          t          |                    k    r`t          t          |                              | j
        j                            }t          dt!          |          dd                    |                     t          |          d          S || j
        vrt          d|           | j
        |         j        }|                     ||          S )	Nz
Column(s) z already selectedzColumns not found: r      )r   zColumn not found: )rz   
IndexErrorr~   r   r   r%   r$   r   r   r   ry   columnsintersectionset
differenceKeyErrorrK   _gotitemr   )rF   rO   bad_keysr   s       rG   __getitem__zSelectionMixin.__getitem__   s)   ?&L$/LLLMMMcD%HbjIJJ 
	148#005566#c#hh--GGC 3 3DH4D E EFFJS]]1R45HJJKKK==c=333 $(""9C99:::8C=%D==4=000rI   r   c                     t          |           )a  
        sub-classes to define
        return a sliced object

        Parameters
        ----------
        key : str / list of selections
        ndim : {1, 2}
            requested ndim of result
        subset : object, default None
            subset to act on
        r   )rF   rO   r   subsets       rG   r   zSelectionMixin._gotitem   s     "$'''rI   c                     t          |           rb   r   )rF   funcargskwargss       rG   	aggregatezSelectionMixin.aggregate  s    !$'''rI   rc   rb   )r   rW   )rd   re   rf   rg   rh   rz   _internal_namesr   _internal_names_setr   ri   r   r   r   r   r   r   r   r   aggrv   rI   rG   rx   rx      s'         
 MMM$(J((((####0O#o..
  X U - - ^- ' ' ' ^ U'   ^ U 1 1 1 ( ( ( ( (( ( ( CCCrI   rx   c            	          e Zd ZU dZdZ edg          Zded<   edod            Z	edpd
            Z
edqd            Z eed          Zedrd            ZdsdZedtd            Zed             Zedsd            Zedsd            Zedud            Zeddej        fdvd$            Zeedwd%                        Zdxdyd*Z ed+d,d-.          	 dxdzd/            Zdxdyd0Z eed,d+d1.          	 dxdzd2            Zd3 ZeZd{d5Z e!dwd6            Z"d|d8Z#d9d&ddd:d}d>Z$ed~d?            Z%e	 	 	 	 	 dddE            Z&dF Z'edddG            Z(edwdH            Z)edwdI            Z*edwdJ            Z+edddL            Z, ee-j.        dMdMdM e/j0        dN          O          	 	 dddR            Z.dSe1dT<   e2	 	 ddd]            Z3e2	 	 ddd`            Z3 ee1dT         dab          	 	 dddf            Z3dgdhddkZ4edddl            Z5dm Z6dn Z7dS )r8   zS
    Common ops mixin to support a unified interface / docs for Series / Index
    i  tolistzfrozenset[str]_hidden_attrsrJ   r   c                     t          |           rb   r   rE   s    rG   dtypezIndexOpsMixin.dtype       "$'''rI   ExtensionArray | np.ndarrayc                     t          |           rb   r   rE   s    rG   _valueszIndexOpsMixin._values  r   rI   rF   r>   c                0    t          j        ||           | S )zw
        Return the transpose, which is by definition self.

        Returns
        -------
        %(klass)s
        )nvvalidate_transpose)rF   r   r   s      rG   	transposezIndexOpsMixin.transpose"  s     	dF+++rI   zD
        Return the transpose, which is by definition self.
        )r   r   c                    | j         j        S )z
        Return a tuple of the shape of the underlying data.

        Examples
        --------
        >>> s = pd.Series([1, 2, 3])
        >>> s.shape
        (3,)
        )r   shaperE   s    rG   r   zIndexOpsMixin.shape5  s     |!!rI   rW   c                     t          |           rb   r   rE   s    rG   __len__zIndexOpsMixin.__len__B  s    !$'''rI   
Literal[1]c                    dS )zO
        Number of dimensions of the underlying data, by definition 1.
        r   rv   rE   s    rG   r   zIndexOpsMixin.ndimF  s	    
 qrI   c                ~    t          |           dk    rt          t          |                     S t          d          )a  
        Return the first element of the underlying data as a Python scalar.

        Returns
        -------
        scalar
            The first element of %(klass)s.

        Raises
        ------
        ValueError
            If the data is not length-1.
        r   z6can only convert an array of size 1 to a Python scalar)r   nextiter
ValueErrorrE   s    rG   itemzIndexOpsMixin.itemM  s6     t99>>T

###QRRRrI   c                    | j         j        S )zD
        Return the number of bytes in the underlying data.
        )r   nbytesrE   s    rG   r   zIndexOpsMixin.nbytes`  s    
 |""rI   c                *    t          | j                  S )zG
        Return the number of elements in the underlying data.
        )r   r   rE   s    rG   sizezIndexOpsMixin.sizeg  s    
 4<   rI   r-   c                     t          |           )aM  
        The ExtensionArray of the data backing this Series or Index.

        Returns
        -------
        ExtensionArray
            An ExtensionArray of the values stored within. For extension
            types, this is the actual array. For NumPy native types, this
            is a thin (no copy) wrapper around :class:`numpy.ndarray`.

            ``.array`` differs ``.values`` which may require converting the
            data to a different form.

        See Also
        --------
        Index.to_numpy : Similar method that always returns a NumPy array.
        Series.to_numpy : Similar method that always returns a NumPy array.

        Notes
        -----
        This table lays out the different array types for each extension
        dtype within pandas.

        ================== =============================
        dtype              array type
        ================== =============================
        category           Categorical
        period             PeriodArray
        interval           IntervalArray
        IntegerNA          IntegerArray
        string             StringArray
        boolean            BooleanArray
        datetime64[ns, tz] DatetimeArray
        ================== =============================

        For any 3rd-party extension types, the array type will be an
        ExtensionArray.

        For all remaining dtypes ``.array`` will be a
        :class:`arrays.NumpyExtensionArray` wrapping the actual ndarray
        stored within. If you absolutely need a NumPy array (possibly with
        copying / coercing data), then use :meth:`Series.to_numpy` instead.

        Examples
        --------
        For regular NumPy types like int, and float, a PandasArray
        is returned.

        >>> pd.Series([1, 2, 3]).array
        <PandasArray>
        [1, 2, 3]
        Length: 3, dtype: int64

        For extension types, like Categorical, the actual ExtensionArray
        is returned

        >>> ser = pd.Series(pd.Categorical(['a', 'b', 'a']))
        >>> ser.array
        ['a', 'b', 'a']
        Categories (2, object): ['a', 'b']
        r   rE   s    rG   arrayzIndexOpsMixin.arrayn  s    ~ "$'''rI   NFr   npt.DTypeLike | Nonecopyboolna_valuerM   
np.ndarrayc                   t          | j                  r | j        j        |f||d|S |r:t	          |                                          d         }t          d| d          |t          j        url| j	        }t          ||          st          j        ||          }n|                                }||t          j        |                                           <   n| j	        }t          j        ||          }|r|t          j        u s|s}t!                      rot          j        | j	        dd         |dd                   rEt!                      r#|s!|                                }d|j        _        n|                                }|S )	a  
        A NumPy ndarray representing the values in this Series or Index.

        Parameters
        ----------
        dtype : str or numpy.dtype, optional
            The dtype to pass to :meth:`numpy.asarray`.
        copy : bool, default False
            Whether to ensure that the returned value is not a view on
            another array. Note that ``copy=False`` does not *ensure* that
            ``to_numpy()`` is no-copy. Rather, ``copy=True`` ensure that
            a copy is made, even if not strictly necessary.
        na_value : Any, optional
            The value to use for missing values. The default value depends
            on `dtype` and the type of the array.
        **kwargs
            Additional keywords passed through to the ``to_numpy`` method
            of the underlying array (for extension arrays).

        Returns
        -------
        numpy.ndarray

        See Also
        --------
        Series.array : Get the actual data stored within.
        Index.array : Get the actual data stored within.
        DataFrame.to_numpy : Similar method for DataFrame.

        Notes
        -----
        The returned array will be the same up to equality (values equal
        in `self` will be equal in the returned array; likewise for values
        that are not equal). When `self` contains an ExtensionArray, the
        dtype may be different. For example, for a category-dtype Series,
        ``to_numpy()`` will return a NumPy array and the categorical dtype
        will be lost.

        For NumPy dtypes, this will be a reference to the actual data stored
        in this Series or Index (assuming ``copy=False``). Modifying the result
        in place will modify the data stored in the Series or Index (not that
        we recommend doing that).

        For extension types, ``to_numpy()`` *may* require copying data and
        coercing the result to a NumPy type (possibly object), which may be
        expensive. When you need a no-copy reference to the underlying data,
        :attr:`Series.array` should be used instead.

        This table lays out the different dtypes and default return types of
        ``to_numpy()`` for various dtypes within pandas.

        ================== ================================
        dtype              array type
        ================== ================================
        category[T]        ndarray[T] (same dtype as input)
        period             ndarray[object] (Periods)
        interval           ndarray[object] (Intervals)
        IntegerNA          ndarray[object]
        datetime64[ns]     datetime64[ns]
        datetime64[ns, tz] ndarray[object] (Timestamps)
        ================== ================================

        Examples
        --------
        >>> ser = pd.Series(pd.Categorical(['a', 'b', 'a']))
        >>> ser.to_numpy()
        array(['a', 'b', 'a'], dtype=object)

        Specify the `dtype` to control how datetime-aware data is represented.
        Use ``dtype=object`` to return an ndarray of pandas :class:`Timestamp`
        objects, each with the correct ``tz``.

        >>> ser = pd.Series(pd.date_range('2000', periods=2, tz="CET"))
        >>> ser.to_numpy(dtype=object)
        array([Timestamp('2000-01-01 00:00:00+0100', tz='CET'),
               Timestamp('2000-01-02 00:00:00+0100', tz='CET')],
              dtype=object)

        Or ``dtype='datetime64[ns]'`` to return an ndarray of native
        datetime64 values. The values are converted to UTC and the timezone
        info is dropped.

        >>> ser.to_numpy(dtype="datetime64[ns]")
        ... # doctest: +ELLIPSIS
        array(['1999-12-31T23:00:00.000000000', '2000-01-01T23:00:00...'],
              dtype='datetime64[ns]')
        )r   r   r   z/to_numpy() got an unexpected keyword argument 'rr   r   Nr   F)r    r   r   to_numpyr   keys	TypeErrorr   
no_defaultr   r   r   asarrayr   
asanyarrayr&   r   shares_memoryviewflags	writeable)rF   r   r   r   r   r   valuesresults           rG   r   zIndexOpsMixin.to_numpy  s   ~ $DJ// 	&4:&uU4(UUfUUU 	FKKMM**1-HM(MMM   3>))\F#FH55 ' F%88819F2=--..\FF%000 		+X// 0,.. 0 RaR 0&!*== +&(( + +#[[]]F-2FL**#[[]]FrI   c                    | j          S rb   )r   rE   s    rG   emptyzIndexOpsMixin.empty3  s     9}rI   Tr   AxisInt | Noneskipnac                    t          j        |           t          j        ||           t          j        | j        |          S )a  
        Return the maximum value of the Index.

        Parameters
        ----------
        axis : int, optional
            For compatibility with NumPy. Only 0 or None are allowed.
        skipna : bool, default True
            Exclude NA/null values when showing the result.
        *args, **kwargs
            Additional arguments and keywords for compatibility with NumPy.

        Returns
        -------
        scalar
            Maximum value.

        See Also
        --------
        Index.min : Return the minimum value in an Index.
        Series.max : Return the maximum value in a Series.
        DataFrame.max : Return the maximum values in a DataFrame.

        Examples
        --------
        >>> idx = pd.Index([3, 2, 1])
        >>> idx.max()
        3

        >>> idx = pd.Index(['c', 'b', 'a'])
        >>> idx.max()
        'c'

        For a MultiIndex, the maximum is determined lexicographically.

        >>> idx = pd.MultiIndex.from_product([('a', 'b'), (2, 1)])
        >>> idx.max()
        ('b', 2)
        r   )r   validate_minmax_axisvalidate_maxr)   nanmaxr   rF   r   r   r   r   s        rG   maxzIndexOpsMixin.max8  ?    P 	%%%
f%%%}T\&9999rI   r   minlargest)opopposeru   c                6   | j         }t          j        |           t          j        |||          }t	          |t
                    r>|s(|                                                                rdS |                                S t          j
        ||          S )ab  
        Return int position of the {value} value in the Series.

        If the {op}imum is achieved in multiple locations,
        the first row position is returned.

        Parameters
        ----------
        axis : {{None}}
            Unused. Parameter needed for compatibility with DataFrame.
        skipna : bool, default True
            Exclude NA/null values when showing the result.
        *args, **kwargs
            Additional arguments and keywords for compatibility with NumPy.

        Returns
        -------
        int
            Row position of the {op}imum value.

        See Also
        --------
        Series.arg{op} : Return position of the {op}imum value.
        Series.arg{oppose} : Return position of the {oppose}imum value.
        numpy.ndarray.arg{op} : Equivalent method for numpy arrays.
        Series.idxmax : Return index label of the maximum values.
        Series.idxmin : Return index label of the minimum values.

        Examples
        --------
        Consider dataset containing cereal calories

        >>> s = pd.Series({{'Corn Flakes': 100.0, 'Almond Delight': 110.0,
        ...                'Cinnamon Toast Crunch': 120.0, 'Cocoa Puff': 110.0}})
        >>> s
        Corn Flakes              100.0
        Almond Delight           110.0
        Cinnamon Toast Crunch    120.0
        Cocoa Puff               110.0
        dtype: float64

        >>> s.argmax()
        2
        >>> s.argmin()
        0

        The maximum cereal calories is the third element and
        the minimum cereal calories is the first element,
        since series is zero-indexed.
        r   r   )r   r   r   validate_argmax_with_skipnar~   r-   r&   anyargmaxr)   	nanargmaxrF   r   r   r   r   delegates         rG   r   zIndexOpsMixin.argmaxd  s    l <
%%%/fEEh// 
	 )hmmoo1133 )r((( #   rI   c                    t          j        |           t          j        ||           t          j        | j        |          S )a  
        Return the minimum value of the Index.

        Parameters
        ----------
        axis : {None}
            Dummy argument for consistency with Series.
        skipna : bool, default True
            Exclude NA/null values when showing the result.
        *args, **kwargs
            Additional arguments and keywords for compatibility with NumPy.

        Returns
        -------
        scalar
            Minimum value.

        See Also
        --------
        Index.max : Return the maximum value of the object.
        Series.min : Return the minimum value in a Series.
        DataFrame.min : Return the minimum values in a DataFrame.

        Examples
        --------
        >>> idx = pd.Index([3, 2, 1])
        >>> idx.min()
        1

        >>> idx = pd.Index(['c', 'b', 'a'])
        >>> idx.min()
        'a'

        For a MultiIndex, the minimum is determined lexicographically.

        >>> idx = pd.MultiIndex.from_product([('a', 'b'), (2, 1)])
        >>> idx.min()
        ('a', 1)
        r   )r   r   validate_minr)   nanminr   r   s        rG   r   zIndexOpsMixin.min  r   rI   smallestc                6   | j         }t          j        |           t          j        |||          }t	          |t
                    r>|s(|                                                                rdS |                                S t          j
        ||          S )Nr   r   )r   r   r   validate_argmin_with_skipnar~   r-   r&   r   argminr)   	nanargminr   s         rG   r   zIndexOpsMixin.argmin  s     <
%%%/fEEh// 
	 )hmmoo1133 )r((( #   rI   c                4    | j                                         S )a  
        Return a list of the values.

        These are each a scalar type, which is a Python scalar
        (for str, int, float) or a pandas scalar
        (for Timestamp/Timedelta/Interval/Period)

        Returns
        -------
        list

        See Also
        --------
        numpy.ndarray.tolist : Return the array as an a.ndim-levels deep
            nested list of Python scalars.
        )r   r   rE   s    rG   r   zIndexOpsMixin.tolist  s    " |""$$$rI   r   c                    t          | j        t          j                  st	          | j                  S t          | j        j        t          | j        j                            S )a  
        Return an iterator of the values.

        These are each a scalar type, which is a Python scalar
        (for str, int, float) or a pandas scalar
        (for Timestamp/Timedelta/Interval/Period)

        Returns
        -------
        iterator
        )	r~   r   r   r   r   mapr   ranger   rE   s    rG   __iter__zIndexOpsMixin.__iter__  sM     $,
33 	D%%%t|(%0A*B*BCCCrI   c                ^    t          t          |                                                     S )z
        Return True if there are any NaNs.

        Enables various performance speedups.

        Returns
        -------
        bool
        )r   r&   r   rE   s    rG   hasnanszIndexOpsMixin.hasnans  s"     DJJNN$$%%%rI   npt.NDArray[np.bool_]c                *    t          | j                  S rb   )r&   r   rE   s    rG   r&   zIndexOpsMixin.isna!  s    DL!!!rI   r   )r   r   numeric_onlyfilter_typenamerK   r   c                   t          | |d          }|&t          t          |           j         d|            |dd|i|S )zA
        Perform the reduction type operation if we can.
        Nz cannot perform the operation r   rv   )r\   r   rD   rd   )	rF   r   r  r   r   r   r   kwdsr   s	            rG   _reducezIndexOpsMixin._reduce$  sc     tT4((<::&LLdLL   t**6*T***rI   c                  
 t          |          rit          |t                    rt          |d          r|

fd}n<ddlm} t          |          dk    r ||t          j                  }n ||          }t          |t                    r|dvrd| d}t          |          |d	k    r||j                                                 }t          | j                  r*t          d
| j                  }|                    |          S | j        }|j                            |          }t'          j        |j        |          }|S t+          | j                  r)t          | j        d          r| j        }|t,          d }	nM| j                            t0                    }|d	k    rd }	n$|t2          j        }	nd| d}t          |           |	||          }|S )a  
        An internal function that maps values using the input
        correspondence (which can be a dict, Series, or function).

        Parameters
        ----------
        mapper : function, dict, or Series
            The input correspondence object
        na_action : {None, 'ignore'}
            If 'ignore', propagate NA values, without passing them to the
            mapping function

        Returns
        -------
        Union[Index, MultiIndex], inferred
            The output of the mapping function applied to the index.
            If the function returns a tuple with more than one element
            a MultiIndex will be returned.
        __missing__c                ~    t          | t                    r t          j        |           rt          j        n|          S rb   )r~   floatr   isnannan)xdict_with_defaults    rG   <lambda>z+IndexOpsMixin._map_values.<locals>.<lambda>V  s2    #4(E22Irx{{IBFF$ rI   r   )r6   r   )Nignorez+na_action must either be 'ignore' or None, z was passedr  r4   r   Nc                ,    |                      |          S rb   )r   r   fs     rG   r  z+IndexOpsMixin._map_values.<locals>.<lambda>  s    fjjmm rI   c                    t          j        | |t          |                               t          j                            S rb   )r   map_infer_maskr&   r   r   uint8r  s     rG   r  z+IndexOpsMixin._map_values.<locals>.<lambda>  s0    #*<AtF||00::+ + rI   )r   r~   dictrS   pandasr6   r   r   float64r%   r   indexnotnar   r   r   r   r   get_indexerr(   take_ndr    NotImplementedErrorastyperM   r   	map_infer)rF   mapper	na_actionr6   msgcatr   indexer
new_valuesmap_fr  s             @rG   _map_valueszIndexOpsMixin._map_values9  s@   0  	,&$'' ,GFM,J,J , %+!    *)))))v;;!###VF"*===FF#VF^^Ffi(( 	 000. . . .  !oo%H$$ 2 2 4 45 $DJ// ' =$,77wwv&\Fl..v66G#+FNGDDJ $DJ// 	&GDL%4P4P 	&\F$))33EE\((00FH$$  ". . . .  !oo% U66**
rI   	normalizesort	ascendingdropnar6   c                6    t          j        | |||||          S )a	  
        Return a Series containing counts of unique values.

        The resulting object will be in descending order so that the
        first element is the most frequently-occurring element.
        Excludes NA values by default.

        Parameters
        ----------
        normalize : bool, default False
            If True then the object returned will contain the relative
            frequencies of the unique values.
        sort : bool, default True
            Sort by frequencies.
        ascending : bool, default False
            Sort in ascending order.
        bins : int, optional
            Rather than count values, group them into half-open bins,
            a convenience for ``pd.cut``, only works with numeric data.
        dropna : bool, default True
            Don't include counts of NaN.

        Returns
        -------
        Series

        See Also
        --------
        Series.count: Number of non-NA elements in a Series.
        DataFrame.count: Number of non-NA elements in a DataFrame.
        DataFrame.value_counts: Equivalent method on DataFrames.

        Examples
        --------
        >>> index = pd.Index([3, 1, 2, 3, 4, np.nan])
        >>> index.value_counts()
        3.0    2
        1.0    1
        2.0    1
        4.0    1
        Name: count, dtype: int64

        With `normalize` set to `True`, returns the relative frequency by
        dividing all values by the sum of values.

        >>> s = pd.Series([3, 1, 2, 3, 4, np.nan])
        >>> s.value_counts(normalize=True)
        3.0    0.4
        1.0    0.2
        2.0    0.2
        4.0    0.2
        Name: proportion, dtype: float64

        **bins**

        Bins can be useful for going from a continuous variable to a
        categorical variable; instead of counting unique
        apparitions of values, divide the index in the specified
        number of half-open bins.

        >>> s.value_counts(bins=3)
        (0.996, 2.0]    2
        (2.0, 3.0]      2
        (3.0, 4.0]      1
        Name: count, dtype: int64

        **dropna**

        With `dropna` set to `False` we can also see NaN index values.

        >>> s.value_counts(dropna=False)
        3.0    2
        1.0    1
        2.0    1
        4.0    1
        NaN    1
        Name: count, dtype: int64
        )r(  r)  r'  binsr*  )r(   value_counts)rF   r'  r(  r)  r,  r*  s         rG   r-  zIndexOpsMixin.value_counts  s1    n &
 
 
 	
rI   c                    | j         }t          |t          j                  s|                                }nt          j        |          }|S rb   )r   r~   r   r   r<   r(   unique1d)rF   r   r   s      rG   r<   zIndexOpsMixin.unique   sA    &"*-- 	1]]__FF(00FrI   c                j    |                                  }|rt          |          }t          |          S )a  
        Return number of unique elements in the object.

        Excludes NA values by default.

        Parameters
        ----------
        dropna : bool, default True
            Don't include NaN in the count.

        Returns
        -------
        int

        See Also
        --------
        DataFrame.nunique: Method nunique for DataFrame.
        Series.count: Count non-NA/null observations in the Series.

        Examples
        --------
        >>> s = pd.Series([1, 3, 5, 7, 7])
        >>> s
        0    1
        1    3
        2    5
        3    7
        4    7
        dtype: int64

        >>> s.nunique()
        4
        )r<   r'   r   )rF   r*  uniqss      rG   nuniquezIndexOpsMixin.nunique	  s3    F  	/'..E5zzrI   c                P    |                      d          t          |           k    S )zr
        Return boolean if values in the object are unique.

        Returns
        -------
        bool
        F)r*  )r2  r   rE   s    rG   	is_uniquezIndexOpsMixin.is_unique1  s#     ||5|))SYY66rI   c                .    ddl m}  ||           j        S )z
        Return boolean if values in the object are monotonically increasing.

        Returns
        -------
        bool
        r   r5   )r  r5   is_monotonic_increasingrF   r5   s     rG   r7  z%IndexOpsMixin.is_monotonic_increasing<  '     	!     uT{{22rI   c                .    ddl m}  ||           j        S )z
        Return boolean if values in the object are monotonically decreasing.

        Returns
        -------
        bool
        r   r6  )r  r5   is_monotonic_decreasingr8  s     rG   r;  z%IndexOpsMixin.is_monotonic_decreasingI  r9  rI   r[   c                   t          | j        d          r| j                            |          S | j        j        }|rLt	          |           r=t
          s6t          t          j        | j	                  }|t          j        |          z  }|S )aN  
        Memory usage of the values.

        Parameters
        ----------
        deep : bool, default False
            Introspect the data deeply, interrogate
            `object` dtypes for system-level memory consumption.

        Returns
        -------
        bytes used

        See Also
        --------
        numpy.ndarray.nbytes : Total bytes consumed by the elements of the
            array.

        Notes
        -----
        Memory usage does not include memory consumed by elements that
        are not components of the array if deep=False or if used on PyPy
        rY   rZ   )rS   r   rY   r   r!   r   r   r   r   r   r   memory_usage_of_objects)rF   r[   vr   s       rG   _memory_usagezIndexOpsMixin._memory_usageV  s    2 4:~.. 	:** +    J 	5OD)) 	5$ 	5"*dl33F,V444ArI   r9   z            sort : bool, default False
                Sort `uniques` and shuffle `codes` to maintain the
                relationship.
            )r   order	size_hintr(  use_na_sentinel"tuple[npt.NDArray[np.intp], Index]c                (   t          j        | j        ||          \  }}|j        t          j        k    r|                    t          j                  }t          | t                    r| 
                    |          }nddlm}  ||          }||fS )N)r(  rB  r   r6  )r(   	factorizer   r   r   float16r  float32r~   r$   rH   r  r5   )rF   r(  rB  codesuniquesr5   s         rG   rE  zIndexOpsMixin.factorizez  s    $ $-Lt_
 
 
w =BJ&&nnRZ00GdH%% 	%''00GG$$$$$$eGnnGg~rI   a  
        Find indices where elements should be inserted to maintain order.

        Find the indices into a sorted {klass} `self` such that, if the
        corresponding elements in `value` were inserted before the indices,
        the order of `self` would be preserved.

        .. note::

            The {klass} *must* be monotonically sorted, otherwise
            wrong locations will likely be returned. Pandas does *not*
            check this for you.

        Parameters
        ----------
        value : array-like or scalar
            Values to insert into `self`.
        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 `self` into ascending
            order. They are typically the result of ``np.argsort``.

        Returns
        -------
        int or array of int
            A scalar or array of insertion points with the
            same shape as `value`.

        See Also
        --------
        sort_values : Sort by the values along either axis.
        numpy.searchsorted : Similar method from NumPy.

        Notes
        -----
        Binary search is used to find the required insertion points.

        Examples
        --------
        >>> ser = pd.Series([1, 2, 3])
        >>> ser
        0    1
        1    2
        2    3
        dtype: int64

        >>> ser.searchsorted(4)
        3

        >>> ser.searchsorted([0, 4])
        array([0, 3])

        >>> ser.searchsorted([1, 3], side='left')
        array([0, 2])

        >>> ser.searchsorted([1, 3], side='right')
        array([1, 3])

        >>> ser = pd.Series(pd.to_datetime(['3/11/2000', '3/12/2000', '3/13/2000']))
        >>> ser
        0   2000-03-11
        1   2000-03-12
        2   2000-03-13
        dtype: datetime64[ns]

        >>> ser.searchsorted('3/14/2000')
        3

        >>> ser = pd.Categorical(
        ...     ['apple', 'bread', 'bread', 'cheese', 'milk'], ordered=True
        ... )
        >>> ser
        ['apple', 'bread', 'bread', 'cheese', 'milk']
        Categories (4, object): ['apple' < 'bread' < 'cheese' < 'milk']

        >>> ser.searchsorted('bread')
        1

        >>> ser.searchsorted(['bread'], side='right')
        array([3])

        If the values are not monotonically sorted, wrong locations
        may be returned:

        >>> ser = pd.Series([2, 1, 3])
        >>> ser
        0    2
        1    1
        2    3
        dtype: int64

        >>> ser.searchsorted(1)  # doctest: +SKIP
        0  # wrong result, correct would be 1
        searchsorted.ru   r3   sideLiteral['left', 'right']sorterr1   np.intpc                    d S rb   rv   rF   ru   rK  rM  s       rG   rJ  zIndexOpsMixin.searchsorted  s	     	rI   npt.ArrayLike | ExtensionArraynpt.NDArray[np.intp]c                    d S rb   rv   rP  s       rG   rJ  zIndexOpsMixin.searchsorted  s	     	rI   r5   )r:   left$NumpyValueArrayLike | ExtensionArraynpt.NDArray[np.intp] | np.intpc                   t          |t                    r'dt          |          j         d}t	          |          | j        }t          |t          j                  s|                    |||          S t          j        ||||          S )Nz(Value must be 1-D array-like or scalar, z is not supported)rK  rM  )
r~   r#   rD   rd   r   r   r   r   rJ  r(   )rF   ru   rK  rM  r!  r   s         rG   rJ  zIndexOpsMixin.searchsorted  s     e\** 	";;;'; ; ;  S//!&"*-- 	H&&u4&GGG&	
 
 
 	
rI   firstkeeprZ  r0   c               @    |                      |          }| |          S NrY  )_duplicated)rF   rZ  r=   s      rG   drop_duplicateszIndexOpsMixin.drop_duplicates2  s%    %%4%00
ZK  rI   c                8    t          j        | j        |          S r\  )r(   r=   r   )rF   rZ  s     rG   r]  zIndexOpsMixin._duplicated7  s    $T\====rI   c                d   t          j        | |          }| j        }t          |dd          }t          j        ||j                  }t          |          }t          j        d          5  t          j	        |||          }d d d            n# 1 swxY w Y   | 
                    ||          S )NT)extract_numpyextract_ranger  )all)r  )r*   get_op_result_namer   r/   maybe_prepare_scalar_for_opr   r.   r   errstatearithmetic_op_construct_result)rF   otherr   res_namelvaluesrvaluesr   s          rG   _arith_methodzIndexOpsMixin._arith_method;  s    )$66,TNNN1'7=II099[X&&& 	= 	=&w<<F	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= %%f8%<<<s   -BBBc                     t          |           )z~
        Construct an appropriately-wrapped result from the ArrayLike result
        of an arithmetic-like operation.
        r   )rF   r   r  s      rG   rh  zIndexOpsMixin._construct_resultH  s    
 "$'''rI   )rJ   r   )rJ   r   )rF   r>   rJ   r>   )rJ   r   rc   )rJ   r   )rJ   r-   )r   r   r   r   r   rM   rJ   r   )rJ   r   )NT)r   r   r   r   )r   r   r   r   rJ   rW   )rJ   r   )rJ   r   )r  rK   r   r   r   r   rb   )FTFNT)
r'  r   r(  r   r)  r   r*  r   rJ   r6   )T)r*  r   rJ   rW   )F)r[   r   rJ   rW   )FT)r(  r   rB  r   rJ   rC  )..)ru   r3   rK  rL  rM  r1   rJ   rN  )ru   rQ  rK  rL  rM  r1   rJ   rR  )rT  N)ru   rU  rK  rL  rM  r1   rJ   rV  )rZ  r0   )rX  )rZ  r0   rJ   r   )8rd   re   rf   rg   __array_priority__	frozensetr   rh   ri   r   r   r   r   Tr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   to_listr   r   r   r&   r  r&  r-  r<   r2  r4  r7  r;  r?  r(   rE  textwrapdedentr7   r   rJ  r^  r]  rm  rh  rv   rI   rG   r8   r8     s         
 $-I	
% %M     ( ( ( X( ( ( ( X( 	 	 	 U	 		 	 	A 
" 
" 
" X
"( ( ( (    X S S US$ # # # X# ! ! ! X! >( >( >( X>(@  '+>	A A A A UAF    X U*: *: *: *: *:X 	SE%y111:>C C C C 21CJ*: *: *: *: *:X 	SE%z::::>    ;:&% % %& GD D D D& & & & ^&" " " " + + + + + +* d d d UdL   ]
 ]
 ]
 ]
 U]
~   % % % % U%N 7 7 7 X7 
3 
3 
3 X
3 
3 
3 
3 X
3 ! ! ! ! U!F 	SX_
 
    $    ,`	 N  *-!	    X
  *-!	    X 	Sn	%W555 *0"	
 
 
 
 65
2 3: ! ! ! ! ! !
 > > > > U>= = =( ( ( ( (rI   )Srg   
__future__r   rs  typingr   r   r   r   r   r	   r
   r   r   r   numpyr   pandas._configr   pandas._libsr   pandas._typingr   r   r   r   r   r   r   pandas.compatr   pandas.compat.numpyr   r   pandas.errorsr   pandas.util._decoratorsr   r   pandas.core.dtypes.castr   pandas.core.dtypes.commonr   r   r    r!   r"   pandas.core.dtypes.genericr#   r$   r%   pandas.core.dtypes.missingr&   r'   pandas.corer(   r)   r*   pandas.core.accessorr+   pandas.core.arrayliker,   pandas.core.arraysr-   pandas.core.constructionr.   r/   r0   r1   r2   r3   r  r4   r5   r6   r7   rh   _indexops_doc_kwargsr>   rA   rl   rx   r8   rv   rI   rG   <module>r     s_     # " " " " "                             . . . . . .                              . . . . . . - - - - - -       
 5 4 4 4 4 4                      
       
         
 / . . . . . * * * * * * - - - - - -       
                        " ! ! ! !!	   WT))),$ ,$ ,$ ,$ ,$= ,$ ,$ ,$^- - - - - - - -DU U U U UWX& U U Up@( @( @( @( @(H @( @( @( @( @(rI   