
    Owg                       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 ddl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( ddl)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0m1Z1 ddl2m3Z3m4Z4 ddl5m6Z6m7Z7m8Z8 ddl9m:Z: ddl;m<Z< ddl=m>Z> ddl?m@Z@mAZA erddlBmCZCmDZD ddlmEZEmFZFmGZGmHZH ddlImJZJmKZKmLZL i ZMdeNd<   dddddZO G d d e:      ZP G d! d"      ZQ G d# d$ee         ZR G d% de<      ZSy)&z.
Base and utility classes for pandas objects.
    )annotationsN)TYPE_CHECKINGAnyGenericLiteralcastfinaloverload)using_copy_on_write)lib)AxisIntDtypeObj
IndexLabelNDFrameTSelfShapenpt)PYPY)functionAbstractMethodError)cache_readonlydoc)find_stack_level)can_hold_element)is_object_dtype	is_scalar)ExtensionDtype)ABCDataFrameABCIndex	ABCSeries)isnaremove_na_arraylike)
algorithmsnanopsops)DirNamesMixin)OpsMixin)ExtensionArray)ensure_wrapped_if_datetimelikeextract_array)HashableIterator)DropKeepNumpySorterNumpyValueArrayLikeScalarLike_co)	DataFrameIndexSerieszdict[str, str]_shared_docsIndexOpsMixin )klassinplaceunique
duplicatedc                  R     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 )zK
        Class constructor (for this class it's just `__class__`).
        )typeselfs    G/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/core/base.py_constructorzPandasObject._constructorl   s    
 Dz    c                ,    t         j                  |       S )zI
        Return a string representation for a particular object.
        )object__repr__rA   s    rC   rH   zPandasObject.__repr__s   s    
 t$$rE   c                    t        | d      sy|| j                  j                          y| j                  j                  |d       y)zV
        Reset cached properties. If ``key`` is passed, only clears that key.
        r>   N)hasattrr>   clearpop)rB   keys     rC   _reset_cachezPandasObject._reset_cachez   s8     tX&;KKKKOOC&rE   c                    t        | dd      }|r3 |d      }t        t        |      r|      S |j                               S t        |          S )zx
        Generates the total memory usage for an object that returns
        either a value or Series of values
        memory_usageNTdeep)getattrintr   sumsuper
__sizeof__)rB   rP   mem	__class__s      rC   rW   zPandasObject.__sizeof__   sO    
 t^T:D)Cins<<#'')<< w!##rE   )returnstrN)rM   z
str | NonerZ   NonerZ   rT   )__name__
__module____qualname____doc____annotations__propertyrD   rH   rN   rW   __classcell__)rY   s   @rC   r=   r=   d   s6    
  %	'$ $rE   r=   c                       e Zd ZdZddZddZy)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)`.
    c                2    t         j                  | dd       y)z9
        Prevents setting additional attributes.
        __frozenTN)rG   __setattr__rA   s    rC   _freezezNoNewAttributesMixin._freeze   s     	4T2rE   c                    t        | dd      r8|dk(  s3|t        |       j                  v st        | |d       t        d| d      t        j                  | ||       y )Nri   Fr>   z"You cannot add any new attribute '')rS   r@   __dict__AttributeErrorrG   rj   )rB   rM   values      rC   rj   z NoNewAttributesMixin.__setattr__   s_     4U+8Od4j)))tS$'3 #EcU!!LMM4e,rE   N)rZ   r]   )rM   r[   rZ   r]   )r_   r`   ra   rb   rk   rj    rE   rC   rg   rg      s    	3-rE   rg   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e	dd       Zd ZeZy)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]
exclusionsr>   __setstate__c                    t        | j                  t        t        t        t
        t        j                  f      s| j                  gS | j                  S r\   )
isinstanceru   listtupler!   r    npndarrayrA   s    rC   _selection_listzSelectionMixin._selection_list   s=     OOdE9h

K
 OO$$rE   c                    | j                   t        | j                  t              r| j                  S | j                  | j                      S r\   )ru   ry   rt   r!   rA   s    rC   _selected_objzSelectionMixin._selected_obj   s5    ??"j9&E88O88DOO,,rE   c                .    | j                   j                  S r\   )r   ndimrA   s    rC   r   zSelectionMixin.ndim   s     !!&&&rE   c                H   t        | j                  t              r| j                  S | j                  %| j                  j	                  | j
                        S t        | j                        dkD  r(| j                  j                  | j                  dd      S | j                  S )Nr      T)axis
only_slice)	ry   rt   r!   ru   _getitem_nocopyr~   lenrv   
_drop_axisrA   s    rC   _obj_with_exclusionsz#SelectionMixin._obj_with_exclusions   s|     dhh	*88O??&88++D,@,@AAt!#
 88&&tQ4&PP88OrE   c                   | j                   t        d| j                    d      t        |t        t        t
        t        t        j                  f      rt        | j                  j                  j                  |            t        t        |            k7  rQt        t        |      j                  | j                  j                              }t        dt!        |      dd        | j#                  t        |      d      S || j                  vrt        d|       | j                  |   j$                  }| j#                  ||      S )	Nz
Column(s) z already selectedzColumns not found: r      )r   zColumn not found: )ru   
IndexErrorry   rz   r{   r!   r    r|   r}   r   rt   columnsintersectionset
differenceKeyErrorr[   _gotitemr   )rB   rM   bad_keysr   s       rC   __getitem__zSelectionMixin.__getitem__   s	   ??&z$//)::KLMMcD%HbjjIJ488##0056#c#h-GC 3 3DHH4D4D EF!4S]1R5H4IJKK==c=33 $(("!3C59::88C=%%D==4=00rE   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   )rB   rM   r   subsets       rC   r   zSelectionMixin._gotitem   s     "$''rE   c                    d}|j                   dk(  r2t        j                  |      r||v st        j                  |      r|}|S |j                   dk(  r&t        j                  |      r||j                  k(  r|}|S )zO
        Infer the `selection` to pass to our constructor in _gotitem.
        Nr   r   )r   r   r   is_list_likename)rB   rM   r   	selections       rC   _infer_selectionzSelectionMixin._infer_selection  sp     	;;!]]3C6Mc6F6Fs6KI  [[A#--"49KIrE   c                    t        |       r\   r   )rB   funcargskwargss       rC   	aggregatezSelectionMixin.aggregate  s    !$''rE   r^   r\   )r   rT   )r   zSeries | DataFrame)r_   r`   ra   rb   rc   ru   _internal_namesr   _internal_names_setr	   rd   r~   r   r   r   r   r   r   r   r   aggrq   rE   rC   rs   rs      s    
 
M$(J!(##0Oo.
   - - '  '    1 (  ( CrE   rs   c            	         e Zd ZU dZdZ edg      Zded<   ed9d       Z	ed:d       Z
ed;d       Z eed	
      Zed<d       Zd=dZed>d       Zed        Zed=d       Zed=d       Zed?d       Zeddej,                  f	 	 	 	 	 	 	 d@d       ZeedAd              Z eddd      	 dB	 	 	 	 	 dCd       Z eeddd      	 dB	 	 	 	 	 dCd       Zd ZeZdDdZedAd       Z edBdEd        Z!e	 	 	 	 	 dF	 	 	 	 	 	 	 	 	 dGd!       Z"d" Z#edHdId#       Z$edAd$       Z%edAd%       Z&edAd&       Z'edJdKd'       Z( ee)jT                  d(d(d( e+jX                  d)      *      	 	 dL	 	 	 	 	 dMd+       Z*d,e-d-<   e.	 	 dN	 	 	 	 	 	 	 dOd.       Z/e.	 	 dN	 	 	 	 	 	 	 dPd/       Z/ ee-d-   d01      	 	 dQ	 	 	 	 	 	 	 dRd2       Z/d3d4dSd5Z0edTdUd6       Z1d7 Z2d8 Z3y)Vr6   zS
    Common ops mixin to support a unified interface / docs for Series / Index
    i  tolistzfrozenset[str]_hidden_attrsc                    t        |       r\   r   rA   s    rC   dtypezIndexOpsMixin.dtype'       "$''rE   c                    t        |       r\   r   rA   s    rC   _valueszIndexOpsMixin._values,  r   rE   c                2    t        j                  ||       | S )zw
        Return the transpose, which is by definition self.

        Returns
        -------
        %(klass)s
        )nvvalidate_transpose)rB   r   r   s      rC   	transposezIndexOpsMixin.transpose1  s     	dF+rE   a  
        Return the transpose, which is by definition self.

        Examples
        --------
        For Series:

        >>> s = pd.Series(['Ant', 'Bear', 'Cow'])
        >>> s
        0     Ant
        1    Bear
        2     Cow
        dtype: object
        >>> s.T
        0     Ant
        1    Bear
        2     Cow
        dtype: object

        For Index:

        >>> idx = pd.Index([1, 2, 3])
        >>> idx.T
        Index([1, 2, 3], dtype='int64')
        )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   shaperA   s    rC   r   zIndexOpsMixin.shapeZ  s     ||!!!rE   c                    t        |       r\   r   rA   s    rC   __len__zIndexOpsMixin.__len__g  s    !$''rE   c                     y)a  
        Number of dimensions of the underlying data, by definition 1.

        Examples
        --------
        >>> s = pd.Series(['Ant', 'Bear', 'Cow'])
        >>> s
        0     Ant
        1    Bear
        2     Cow
        dtype: object
        >>> s.ndim
        1

        For Index:

        >>> idx = pd.Index([1, 2, 3])
        >>> idx
        Index([1, 2, 3], dtype='int64')
        >>> idx.ndim
        1
        r   rq   rA   s    rC   r   zIndexOpsMixin.ndimk  s    0 rE   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 Series or Index.

        Raises
        ------
        ValueError
            If the data is not length = 1.

        Examples
        --------
        >>> s = pd.Series([1])
        >>> s.item()
        1

        For an index:

        >>> s = pd.Series([1], index=['a'])
        >>> s.index.item()
        'a'
        r   z6can only convert an array of size 1 to a Python scalar)r   nextiter
ValueErrorrA   s    rC   itemzIndexOpsMixin.item  s*    6 t9>T
##QRRrE   c                .    | j                   j                  S )a  
        Return the number of bytes in the underlying data.

        Examples
        --------
        For Series:

        >>> s = pd.Series(['Ant', 'Bear', 'Cow'])
        >>> s
        0     Ant
        1    Bear
        2     Cow
        dtype: object
        >>> s.nbytes
        24

        For Index:

        >>> idx = pd.Index([1, 2, 3])
        >>> idx
        Index([1, 2, 3], dtype='int64')
        >>> idx.nbytes
        24
        )r   nbytesrA   s    rC   r   zIndexOpsMixin.nbytes  s    4 ||"""rE   c                ,    t        | j                        S )a  
        Return the number of elements in the underlying data.

        Examples
        --------
        For Series:

        >>> s = pd.Series(['Ant', 'Bear', 'Cow'])
        >>> s
        0     Ant
        1    Bear
        2     Cow
        dtype: object
        >>> s.size
        3

        For Index:

        >>> idx = pd.Index([1, 2, 3])
        >>> idx
        Index([1, 2, 3], dtype='int64')
        >>> idx.size
        3
        )r   r   rA   s    rC   sizezIndexOpsMixin.size  s    4 4<<  rE   c                    t        |       )ac  
        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 from ``.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 NumpyExtensionArray
        is returned.

        >>> pd.Series([1, 2, 3]).array
        <NumpyExtensionArray>
        [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   rA   s    rC   arrayzIndexOpsMixin.array  s    ~ "$''rE   NFc                l   t        | j                  t              r  | j                  j                  |f||d|S |r1t        t        |j                                     }t        d| d      |t        j                  uxrC |t        j                  u xr. t        j                  | j                  t        j                         }| j                  }|rUt!        ||      st        j"                  ||      }n|j%                         }||t        j&                  t)        |             <   t        j"                  ||      }|r|r|sot+               ret        j,                  | j                  dd |dd       r?t+               r%|s#|j/                         }d|j0                  _        |S |j%                         }|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]')
        )copyna_valuez/to_numpy() got an unexpected keyword argument 'rm   )r   Nr   F)ry   r   r   r   to_numpyr   r   keys	TypeErrorr   
no_defaultr|   nan
issubdtypefloatingr   r   asarrayr   
asanyarrayr"   r   shares_memoryviewflags	writeable)	rB   r   r   r   r   r   fillnavaluesresults	            rC   r   zIndexOpsMixin.to_numpy  si   ~ djj.1&4::&&uU4(UfUUD/0HA(1M 
 CNN* T'RBMM$**bkk,RS 	 #FH5 F%808F2==d,-F%02E2GRa 0&!*=&(#[[]F-2FLL*  $[[]FrE   c                    | j                    S r\   )r   rA   s    rC   emptyzIndexOpsMixin.empty  s     99}rE   maxminlargest)opopposerp   c                   | j                   }t        j                  |       t        j                  |||      }t	        |t
              rl|sZ|j                         j                         r<t        j                  dt        |       j                   dt        t                      y|j                         S t        j                   ||      }|dk(  r;t        j                  dt        |       j                   dt        t                      |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.
        The behavior of x.argmax/argmin with skipna=False and NAs, or with all-NAs is deprecated. In a future version this will raise ValueError.
stacklevelr   skipna)r   r   validate_minmax_axisvalidate_argmax_with_skipnary   r)   r"   anywarningswarnr@   r_   FutureWarningr   argmaxr%   	nanargmaxrB   r   r   r   r   delegater   s          rC   r   zIndexOpsMixin.argmax  s    l <<
%//fEh/hmmo113&tDz':':&; <F F "/1 ((%%hv>F|&tDz':':&; <F F "/1 MrE   smallestc                   | j                   }t        j                  |       t        j                  |||      }t	        |t
              rl|sZ|j                         j                         r<t        j                  dt        |       j                   dt        t                      y|j                         S t        j                   ||      }|dk(  r;t        j                  dt        |       j                   dt        t                      |S )Nr   r   r   r   r   )r   r   r   validate_argmin_with_skipnary   r)   r"   r   r   r   r@   r_   r   r   argminr%   	nanargminr   s          rC   r   zIndexOpsMixin.argmin  s     <<
%//fEh/hmmo113&tDz':':&; <F F "/1 ((%%hv>F|&tDz':':&; <F F "/1 MrE   c                6    | j                   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.

        Examples
        --------
        For Series

        >>> s = pd.Series([1, 2, 3])
        >>> s.to_list()
        [1, 2, 3]

        For Index:

        >>> idx = pd.Index([1, 2, 3])
        >>> idx
        Index([1, 2, 3], dtype='int64')

        >>> idx.to_list()
        [1, 2, 3]
        )r   r   rA   s    rC   r   zIndexOpsMixin.tolist  s    D ||""$$rE   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

        Examples
        --------
        >>> s = pd.Series([1, 2, 3])
        >>> for x in s:
        ...     print(x)
        1
        2
        3
        )	ry   r   r|   r}   r   mapr   ranger   rA   s    rC   __iter__zIndexOpsMixin.__iter__D  sK    , $,,

3%%t||((%0A0A*BCCrE   c                F    t        t        |       j                               S )ak  
        Return True if there are any NaNs.

        Enables various performance speedups.

        Returns
        -------
        bool

        Examples
        --------
        >>> s = pd.Series([1, 2, 3, None])
        >>> s
        0    1.0
        1    2.0
        2    3.0
        3    NaN
        dtype: float64
        >>> s.hasnans
        True
        )boolr"   r   rA   s    rC   hasnanszIndexOpsMixin.hasnans`  s    2 DJNN$%%rE   c                    | j                   }t        |t              r|j                  ||      S t	        j
                  ||||      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
        convert : bool, default True
            Try to find better dtype for elementwise function results. If
            False, leave as dtype=object. Note that the dtype is always
            preserved for some extension array dtypes, such as Categorical.

        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.
        )	na_action)r   convert)r   ry   r)   r   r$   	map_array)rB   mapperr   r   arrs        rC   _map_valueszIndexOpsMixin._map_values{  sA    2 llc>*776Y777##C9gVVrE   c                8    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 when True. Preserve the order of the data when False.
        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
        )sort	ascending	normalizebinsdropna)r$   value_counts_internal)rB   r  r  r  r  r  s         rC   value_countszIndexOpsMixin.value_counts  s*    n //
 	
rE   c                    | j                   }t        |t        j                        s|j	                         }|S t        j                  |      }|S r\   )r   ry   r|   r}   r:   r$   unique1d)rB   r   r   s      rC   r:   zIndexOpsMixin.unique  sB    &"**-]]_F   ((0FrE   c                R    | 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   )rB   r  uniqss      rC   nuniquezIndexOpsMixin.nunique  s'    F '.E5zrE   c                >    | j                  d      t        |       k(  S )a.  
        Return boolean if values in the object are unique.

        Returns
        -------
        bool

        Examples
        --------
        >>> s = pd.Series([1, 2, 3])
        >>> s.is_unique
        True

        >>> s = pd.Series([1, 2, 3, 1])
        >>> s.is_unique
        False
        F)r  )r  r   rA   s    rC   	is_uniquezIndexOpsMixin.is_unique,  s    & ||5|)SY66rE   c                2    ddl m}  ||       j                  S )aY  
        Return boolean if values in the object are monotonically increasing.

        Returns
        -------
        bool

        Examples
        --------
        >>> s = pd.Series([1, 2, 2])
        >>> s.is_monotonic_increasing
        True

        >>> s = pd.Series([3, 2, 1])
        >>> s.is_monotonic_increasing
        False
        r   r3   )pandasr3   is_monotonic_increasingrB   r3   s     rC   r  z%IndexOpsMixin.is_monotonic_increasingA      & 	!T{222rE   c                2    ddl m}  ||       j                  S )a\  
        Return boolean if values in the object are monotonically decreasing.

        Returns
        -------
        bool

        Examples
        --------
        >>> s = pd.Series([3, 2, 2, 1])
        >>> s.is_monotonic_decreasing
        True

        >>> s = pd.Series([1, 2, 3])
        >>> s.is_monotonic_decreasing
        False
        r   r  )r  r3   is_monotonic_decreasingr  s     rC   r  z%IndexOpsMixin.is_monotonic_decreasingX  r  rE   c                H   t        | j                  d      r| j                  j                  |      S | j                  j                  }|rWt	        | j
                        rBt        s<t        t        j                  | j                        }|t        j                  |      z  }|S )a  
        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

        Examples
        --------
        >>> idx = pd.Index([1, 2, 3])
        >>> idx.memory_usage()
        24
        rP   rQ   )rJ   r   rP   r   r   r   r   r   r|   r}   r   r   memory_usage_of_objects)rB   rR   vr   s       rC   _memory_usagezIndexOpsMixin._memory_usageo  s    > 4::~.::** +   JJODJJ/"**dll3F,,V44ArE   r7   z            sort : bool, default False
                Sort `uniques` and shuffle `codes` to maintain the
                relationship.
            )r   order	size_hintr  c                2   t        j                  | j                  ||      \  }}|j                  t        j
                  k(  r|j                  t        j                        }t        | t              r| j                  |      }||fS ddlm}  ||      }||fS )N)r  use_na_sentinelr   r  )r$   	factorizer   r   r|   float16astypefloat32ry   r    rD   r  r3   )rB   r  r  codesuniquesr3   s         rC   r   zIndexOpsMixin.factorize  s    $ $--LLt_
w ==BJJ&nnRZZ0GdH%''0G
 g~ %GnGg~rE   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
        searchsortedc                     y r\   rq   rB   rp   sidesorters       rC   r&  zIndexOpsMixin.searchsorted#       	rE   c                     y r\   rq   r(  s       rC   r&  zIndexOpsMixin.searchsorted,  r+  rE   r3   )r8   c                   t        |t              r$dt        |      j                   d}t	        |      | j
                  }t        |t        j                        s|j                  |||      S t        j                  ||||      S )Nz(Value must be 1-D array-like or scalar, z is not supported)r)  r*  )
ry   r   r@   r_   r   r   r|   r}   r&  r$   )rB   rp   r)  r*  msgr   s         rC   r&  zIndexOpsMixin.searchsorted5  s     e\*:;''((9;  S/!&"**-&&u4&GG&&	
 	
rE   firstkeepc               2    | j                  |      }| |    S Nr0  )_duplicated)rB   r1  r;   s      rC   drop_duplicateszIndexOpsMixin.drop_duplicatesO  s"    %%4%0
ZK  rE   c                    | j                   }t        |t              r|j                  |      S t	        j                  ||      S r3  )r   ry   r)   r;   r$   )rB   r1  r   s      rC   r4  zIndexOpsMixin._duplicatedT  s9    llc>*>>t>,,$$St44rE   c                   t        j                  | |      }| j                  }t        |dd      }t        j                  ||j
                        }t        |      }t        |t              r5t        j                  |j                  |j                  |j                        }t        j                  d      5  t        j                  |||      }d d d        | j!                  |      S # 1 sw Y   xY w)NT)extract_numpyextract_rangeignore)all)r   )r&   get_op_result_namer   r+   maybe_prepare_scalar_for_opr   r*   ry   r   r|   arangestartstopsteperrstatearithmetic_op_construct_result)rB   otherr   res_namelvaluesrvaluesr   s          rC   _arith_methodzIndexOpsMixin._arith_method[  s    ))$6,,TN11'7==I09gu%iiw||W\\JG[[X& 	=&&w<F	= %%f8%<<	= 	=s   7C**C3c                    t        |       )z~
        Construct an appropriately-wrapped result from the ArrayLike result
        of an arithmetic-like operation.
        r   )rB   r   r   s      rC   rD  zIndexOpsMixin._construct_resultj  s    
 "$''rE   )rZ   r   )rZ   zExtensionArray | np.ndarray)rZ   r   )rZ   r   r^   )rZ   z
Literal[1])rZ   r)   )r   znpt.DTypeLike | Noner   r   r   rG   rZ   z
np.ndarray)rZ   r   )NT)r   zAxisInt | Noner   r   rZ   rT   )rZ   r-   )r   r   )FTFNT)
r  r   r  r   r  r   r  r   rZ   r4   )T)r  r   rZ   rT   )F)rR   r   rZ   rT   )FT)r  r   r  r   rZ   z"tuple[npt.NDArray[np.intp], Index])..)rp   r1   r)  Literal['left', 'right']r*  r/   rZ   znp.intp)rp   znpt.ArrayLike | ExtensionArrayr)  rK  r*  r/   rZ   znpt.NDArray[np.intp])leftN)rp   z$NumpyValueArrayLike | ExtensionArrayr)  rK  r*  zNumpySorter | NonerZ   znpt.NDArray[np.intp] | np.intp)r1  r.   )r/  )r1  r.   rZ   znpt.NDArray[np.bool_])4r_   r`   ra   rb   __array_priority__	frozensetr   rc   rd   r   r   r	   r   Tr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   to_listr   r   r   r   r  r:   r  r  r  r  r  r$   r   textwrapdedentr5   r
   r&  r5  r4  rI  rD  rq   rE   rC   r6   r6     sO   
 $-	
%M>  ( ( ( ( 	 	 		A: 
" 
"(  2 S S< # #6 ! !6 >( >(@  '+>>	C#C C 	C 
C CJ    	E%y1:>Q"Q37Q	Q 2Qf 	E%z::>"37	 ;B"%H GD8 & &4 W W>   ]
]
 ]
 	]
 ]
 
]
 ]
~ % %N 7 7( 3 3, 3 3, ' 'R 	X__
  $  
,	,`	 R  *-!	 ' 	
 
   *-!	- ' 	
 
  	n	%W5 *0%)	
3
 '
 #	

 
(
 6
2 3: !
 5 5=(rE   )Trb   
__future__r   rQ  typingr   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.util._exceptionsr   pandas.core.dtypes.castr   pandas.core.dtypes.commonr   r   pandas.core.dtypes.dtypesr   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+   collections.abcr,   r-   r.   r/   r0   r1   r  r2   r3   r4   r5   rc   _indexops_doc_kwargsr=   rg   rs   r6   rq   rE   rC   <module>rj     s   #      .     . - 5 4 5 

 
 / * -
 
    "n !!	 ,$= ,$^- -DdWX& dNS(H S(rE   