
    PiC                    x   d Z ddlmZ ddlZddlmZmZ ddlZddlm	Z	 ddl
mZ erddlmZ ddlmZ dd	lmZ dd
lmZ  G d d          Z G d d          Zdd dfd+dZ G d d          ZeZd,d#Zd$Z e	d%          d-d&            Zd'Z e	d%          d-d(            Zd)Z e	d%          d-d*            ZdS ).z

accessor.py contains base classes for implementing accessor properties
that can be mixed into or pinned onto other pandas classes.

    )annotationsN)TYPE_CHECKINGfinal)
set_module)find_stack_level)Callable)TypeTIndex)NDFramec                  ~     e Zd ZU  e            Zded<    e            Zded<   ed
d            Z	d
dZ
d fd	Z xZS )DirNamesMixinset[str]
_accessorszfrozenset[str]_hidden_attrsreturnc                     | j         | j        z  S )z:
        Delete unwanted __dir__ for this object.
        )r   r   selfs    h/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/core/accessor.py_dir_deletionszDirNamesMixin._dir_deletions#   s    
 !333    c                *      fd j         D             S )z9
        Add additional __dir__ for this object.
        c                4    h | ]}t          |          |S  )hasattr).0accessorr   s     r   	<setcomp>z/DirNamesMixin._dir_additions.<locals>.<setcomp>.   s(    TTTXGD(<S<STTTTr   )r   r   s   `r   _dir_additionszDirNamesMixin._dir_additions*   s"     UTTTTTTTr   	list[str]c                    t          t                                                                }||                                 z
  |                                 z  }t          |          S )z
        Provide method name lookup and completion.

        Notes
        -----
        Only provide 'public' methods.
        )setsuper__dir__r   r    sorted)r   rv	__class__s     r   r%   zDirNamesMixin.__dir__0   sS     ""##4&&(((D,?,?,A,AAbzzr   )r   r   )r   r!   )__name__
__module____qualname__r#   r   __annotations__	frozensetr   r   r   r    r%   __classcell__)r(   s   @r   r   r      s         355J    $-IKKM////
4 4 4 U4U U U U
 
 
 
 
 
 
 
 
 
r   r   c                  L    e Zd ZdZddZddZddZed	d
 dfdd            ZdS )PandasDelegatez@
    Abstract base class for delegating methods/properties.
    namestrc                &    t          d|           )NzYou cannot access the property 	TypeErrorr   r1   argskwargss       r   _delegate_property_getz%PandasDelegate._delegate_property_getB   s    @$@@AAAr   r   Nonec                (    t          d| d          )NzThe property z cannot be setr4   )r   r1   valuer7   r8   s        r   _delegate_property_setz%PandasDelegate._delegate_property_setE   s    <<<<===r   c                &    t          d|           )NzYou cannot call method r4   r6   s       r   _delegate_methodzPandasDelegate._delegate_methodH   s    8$88999r   Fc                    | S Nr   xs    r   <lambda>zPandasDelegate.<lambda>R   s    1 r   T	accessorsr!   typ	overwriteboolaccessor_mappingCallable[[str], str]raise_on_missingc                    dfd}dfd}|D ]_}	|st           |	          d          |dk    r ||	          }
n ||	          }
|st          | |	          st          | |	|
           `dS )a  
        Add accessors to cls from the delegate class.

        Parameters
        ----------
        cls
            Class to add the methods/properties to.
        delegate
            Class to get methods/properties and docstrings.
        accessors : list of str
            List of accessors to add.
        typ : {'property', 'method'}
        overwrite : bool, default False
            Overwrite the method/property in the target class if it exists.
        accessor_mapping: Callable, default lambda x: x
            Callable to map the delegate's function to the cls' function.
        raise_on_missing: bool, default True
            Raise if an accessor does not exist on delegate.
            False skips the missing accessor.
        r1   r2   c           
           fd} fd} |_          |_         t          ||t                                j                  S )Nc                .    |                                S rA   )r9   )r   r1   s    r   _getterz[PandasDelegate._add_delegate_accessors.<locals>._create_delegator_property.<locals>._getterk   s    224888r   c                0    |                      |          S rA   )r=   )r   
new_valuesr1   s     r   _setterz[PandasDelegate._add_delegate_accessors.<locals>._create_delegator_property.<locals>._settern   s    224DDDr   )fgetfsetdoc)r)   propertygetattr__doc__)r1   rO   rR   rI   delegates   `  r   _create_delegator_propertyzJPandasDelegate._add_delegate_accessors.<locals>._create_delegator_propertyj   s    9 9 9 9 9E E E E E  $G#GH&6&6t&<&<==E   r   c                z     t                                }t          j        |           fd            }|S )Nc                &     | j         g|R i |S rA   )r?   )r   r7   r8   r1   s      r   fzSPandasDelegate._add_delegate_accessors.<locals>._create_delegator_method.<locals>.f}   s&    ,t,TCDCCCFCCCr   )rW   	functoolswraps)r1   methodr]   rI   rY   s   `  r   _create_delegator_methodzHPandasDelegate._add_delegate_accessors.<locals>._create_delegator_methodz   sY    X'7'7'='=>>F_V$$D D D D %$D Hr   NrV   r1   r2   )rW   r   setattr)clsrY   rE   rF   rG   rI   rK   rZ   ra   r1   r]   s    `   `     r   _add_delegate_accessorsz&PandasDelegate._add_delegate_accessorsK   s    >	 	 	 	 	 	 	 	 	 	 	 	 	 	  	& 	&D$H&6&6t&<&<dCCKj  ..t44,,T22  &T 2 2 &T1%%%	& 	&r   Nrb   r1   r2   r   r:   )rE   r!   rF   r2   rG   rH   rI   rJ   rK   rH   r   r:   )	r)   r*   r+   rX   r9   r=   r?   classmethodre   r   r   r   r0   r0   =   s         B B B B> > > >: : : :   1<!%E& E& E& E& [E& E& E&r   r0   Fc                    | S rA   r   rB   s    r   rD   rD      s    q r   TrE   r!   rF   r2   rG   rH   rI   rJ   rK   c                &      fd}|S )a  
    Add delegated names to a class using a class decorator.  This provides
    an alternative usage to directly calling `_add_delegate_accessors`
    below a class definition.

    Parameters
    ----------
    delegate : object
        The class to get methods/properties & docstrings.
    accessors : Sequence[str]
        List of accessor to add.
    typ : {'property', 'method'}
    overwrite : bool, default False
       Overwrite the method/property in the target class if it exists.
    accessor_mapping: Callable, default lambda x: x
        Callable to map the delegate's function to the cls' function.
    raise_on_missing: bool, default True
        Raise if an accessor does not exist on delegate.
        False skips the missing accessor.

    Returns
    -------
    callable
        A class decorator.

    Examples
    --------
    @delegate_names(Categorical, ["categories", "ordered"], "property")
    class CategoricalAccessor(PandasDelegate):
        [...]
    c                >    |                                 | S )N)rG   rI   rK   )re   )rd   rI   rE   rY   rG   rK   rF   s    r   add_delegate_accessorsz.delegate_names.<locals>.add_delegate_accessors   s9    ##-- 	$ 	
 	
 	
 
r   r   )rY   rE   rF   rG   rI   rK   rk   s   `````` r   delegate_namesrl      sC    P	 	 	 	 	 	 	 	 	 	 "!r   c                       e Zd ZdZd	dZd ZdS )
Accessora  
    Custom property-like object.

    A descriptor for accessors.

    Parameters
    ----------
    name : str
        Namespace that will be accessed under, e.g. ``df.foo``.
    accessor : cls
        Class with the extension methods.

    Notes
    -----
    For accessor, The class's __init__ method assumes that one of
    ``Series``, ``DataFrame`` or ``Index`` as the
    single argument ``data``.
    r1   r2   r   r:   c                "    || _         || _        d S rA   )_name	_accessor)r   r1   r   s      r   __init__zAccessor.__init__   s    
!r   c                >    || j         S |                      |          S rA   )rq   )r   objrd   s      r   __get__zAccessor.__get__   s!    ;>!~~c"""r   Nrf   )r)   r*   r+   rX   rr   ru   r   r   r   rn   rn      sA         &" " " "# # # # #r   rn   r1   rd   type[NDFrame | Index]r   Callable[[TypeT], TypeT]c                     d fd}|S )a  
    Register a custom accessor on objects.

    Parameters
    ----------
    name : str
        Name under which the accessor should be registered. A warning is issued
        if this name conflicts with a preexisting attribute.

    Returns
    -------
    callable
        A class decorator.

    See Also
    --------
    register_dataframe_accessor : Register a custom accessor on DataFrame objects.
    register_series_accessor : Register a custom accessor on Series objects.
    register_index_accessor : Register a custom accessor on Index objects.

    Notes
    -----
    This function allows you to register a custom-defined accessor class
    for pandas objects (DataFrame, Series, or Index).
    The requirements for the accessor class are as follows:

    * Must contain an init method that:

      * accepts a single object

      * raises an AttributeError if the object does not have correctly
        matching inputs for the accessor

    * Must contain a method for each access pattern.

      * The methods should be able to take any argument signature.

      * Accessible using the @property decorator if no additional arguments are
        needed.

    r   r	   r   c           	         t                    r2t          j        d| dddt          t	                                 t          t          |                      j                                       | S )Nzregistration of accessor z under name z
 for type z: is overriding a preexisting attribute with the same name.)
stacklevel)	r   warningswarnUserWarningr   rc   rn   r   add)r   rd   r1   s    r   	decoratorz%_register_accessor.<locals>.decorator  s    3 	M1H 1 11 1%(1 1 1 +--    	T8D(334444   r   )r   r	   r   r	   r   )r1   rd   r   s   `` r   _register_accessorr      s0    Z       r   a  
An accessor that only accepts integers could
have a class defined like this:

>>> @pd.api.extensions.register_dataframe_accessor("int_accessor")
... class IntAccessor:
...     def __init__(self, pandas_obj):
...         if not all(pandas_obj[col].dtype == 'int64' for col in pandas_obj.columns):
...             raise AttributeError("All columns must contain integer values only")
...         self._obj = pandas_obj
...
...     def sum(self):
...         return self._obj.sum()
...
>>> df = pd.DataFrame([[1, 2], ['x', 'y']])
>>> df.int_accessor
Traceback (most recent call last):
...
AttributeError: All columns must contain integer values only.
>>> df = pd.DataFrame([[1, 2], [3, 4]])
>>> df.int_accessor.sum()
0    4
1    6
dtype: int64zpandas.api.extensionsc                .    ddl m} t          | |          S )a  
    Register a custom accessor on DataFrame objects.

    Parameters
    ----------
    name : str
        Name under which the accessor should be registered. A warning is issued
        if this name conflicts with a preexisting attribute.

    Returns
    -------
    callable
        A class decorator.

    See Also
    --------
    register_dataframe_accessor : Register a custom accessor on DataFrame objects.
    register_series_accessor : Register a custom accessor on Series objects.
    register_index_accessor : Register a custom accessor on Index objects.

    Notes
    -----
    This function allows you to register a custom-defined accessor class for DataFrame.
    The requirements for the accessor class are as follows:

    * Must contain an init method that:

      * accepts a single DataFrame object

      * raises an AttributeError if the DataFrame object does not have correctly
        matching inputs for the accessor

    * Must contain a method for each access pattern.

      * The methods should be able to take any argument signature.

      * Accessible using the @property decorator if no additional arguments are
        needed.

    Examples
    --------
    An accessor that only accepts integers could
    have a class defined like this:

    >>> @pd.api.extensions.register_dataframe_accessor("int_accessor")
    ... class IntAccessor:
    ...     def __init__(self, pandas_obj):
    ...         if not all(
    ...             pandas_obj[col].dtype == "int64" for col in pandas_obj.columns
    ...         ):
    ...             raise AttributeError("All columns must contain integer values only")
    ...         self._obj = pandas_obj
    ...
    ...     def sum(self):
    ...         return self._obj.sum()
    >>> df = pd.DataFrame([[1, 2], ["x", "y"]])
    >>> df.int_accessor
    Traceback (most recent call last):
    ...
    AttributeError: All columns must contain integer values only.
    >>> df = pd.DataFrame([[1, 2], [3, 4]])
    >>> df.int_accessor.sum()
    0    4
    1    6
    dtype: int64
    r   )	DataFrame)pandasr   r   )r1   r   s     r   register_dataframe_accessorr   E  s'    H !     dI...r   a  
An accessor that only accepts integers could
have a class defined like this:

>>> @pd.api.extensions.register_series_accessor("int_accessor")
... class IntAccessor:
...     def __init__(self, pandas_obj):
...         if not pandas_obj.dtype == 'int64':
...             raise AttributeError("The series must contain integer data only")
...         self._obj = pandas_obj
...
...     def sum(self):
...         return self._obj.sum()
...
>>> df = pd.Series([1, 2, 'x'])
>>> df.int_accessor
Traceback (most recent call last):
...
AttributeError: The series must contain integer data only.
>>> df = pd.Series([1, 2, 3])
>>> df.int_accessor.sum()
6c                .    ddl m} t          | |          S )aj  
    Register a custom accessor on Series objects.

    Parameters
    ----------
    name : str
        Name under which the accessor should be registered. A warning is issued
        if this name conflicts with a preexisting attribute.

    Returns
    -------
    callable
        A class decorator.

    See Also
    --------
    register_dataframe_accessor : Register a custom accessor on DataFrame objects.
    register_series_accessor : Register a custom accessor on Series objects.
    register_index_accessor : Register a custom accessor on Index objects.

    Notes
    -----
    This function allows you to register a custom-defined accessor class for Series.
    The requirements for the accessor class are as follows:

    * Must contain an init method that:

      * accepts a single Series object

      * raises an AttributeError if the Series object does not have correctly
        matching inputs for the accessor

    * Must contain a method for each access pattern.

      * The methods should be able to take any argument signature.

      * Accessible using the @property decorator if no additional arguments are
        needed.

    Examples
    --------
    An accessor that only accepts integers could
    have a class defined like this:

    >>> @pd.api.extensions.register_series_accessor("int_accessor")
    ... class IntAccessor:
    ...     def __init__(self, pandas_obj):
    ...         if not pandas_obj.dtype == "int64":
    ...             raise AttributeError("The series must contain integer data only")
    ...         self._obj = pandas_obj
    ...
    ...     def sum(self):
    ...         return self._obj.sum()
    >>> df = pd.Series([1, 2, "x"])
    >>> df.int_accessor
    Traceback (most recent call last):
    ...
    AttributeError: The series must contain integer data only.
    >>> df = pd.Series([1, 2, 3])
    >>> df.int_accessor.sum()
    6
    r   )Series)r   r   r   )r1   r   s     r   register_series_accessorr     s'    @ dF+++r   a[  
An accessor that only accepts integers could
have a class defined like this:

>>> @pd.api.extensions.register_index_accessor("int_accessor")
... class IntAccessor:
...     def __init__(self, pandas_obj):
...         if not all(isinstance(x, int) for x in pandas_obj):
...             raise AttributeError("The index must only be an integer value")
...         self._obj = pandas_obj
...
...     def even(self):
...         return [x for x in self._obj if x % 2 == 0]
>>> df = pd.DataFrame.from_dict(
...     {"row1": {"1": 1, "2": "a"}, "row2": {"1": 2, "2": "b"}}, orient="index"
... )
>>> df.index.int_accessor
Traceback (most recent call last):
...
AttributeError: The index must only be an integer value.
>>> df = pd.DataFrame(
...     {"col1": [1, 2, 3, 4], "col2": ["a", "b", "c", "d"]}, index=[1, 2, 5, 8]
... )
>>> df.index.int_accessor.even()
[2, 8]c                .    ddl m} t          | |          S )aQ  
    Register a custom accessor on Index objects.

    Parameters
    ----------
    name : str
        Name under which the accessor should be registered. A warning is issued
        if this name conflicts with a preexisting attribute.

    Returns
    -------
    callable
        A class decorator.

    See Also
    --------
    register_dataframe_accessor : Register a custom accessor on DataFrame objects.
    register_series_accessor : Register a custom accessor on Series objects.
    register_index_accessor : Register a custom accessor on Index objects.

    Notes
    -----
    This function allows you to register a custom-defined accessor class for Index.
    The requirements for the accessor class are as follows:

    * Must contain an init method that:

      * accepts a single Index object

      * raises an AttributeError if the Index object does not have correctly
        matching inputs for the accessor

    * Must contain a method for each access pattern.

      * The methods should be able to take any argument signature.

      * Accessible using the @property decorator if no additional arguments are
        needed.

    Examples
    --------
    An accessor that only accepts integers could
    have a class defined like this:

    >>> @pd.api.extensions.register_index_accessor("int_accessor")
    ... class IntAccessor:
    ...     def __init__(self, pandas_obj):
    ...         if not all(isinstance(x, int) for x in pandas_obj):
    ...             raise AttributeError("The index must only be an integer value")
    ...         self._obj = pandas_obj
    ...
    ...     def even(self):
    ...         return [x for x in self._obj if x % 2 == 0]
    >>> df = pd.DataFrame.from_dict(
    ...     {"row1": {"1": 1, "2": "a"}, "row2": {"1": 2, "2": "b"}}, orient="index"
    ... )
    >>> df.index.int_accessor
    Traceback (most recent call last):
    ...
    AttributeError: The index must only be an integer value.
    >>> df = pd.DataFrame(
    ...     {"col1": [1, 2, 3, 4], "col2": ["a", "b", "c", "d"]}, index=[1, 2, 5, 8]
    ... )
    >>> df.index.int_accessor.even()
    [2, 8]
    r   r
   )r   r   r   )r1   r   s     r   register_index_accessorr     s'    H dE***r   )
rE   r!   rF   r2   rG   rH   rI   rJ   rK   rH   )r1   r2   rd   rv   r   rw   )r1   r2   r   rw   ) rX   
__future__r   r^   typingr   r   r{   pandas.util._decoratorsr   pandas.util._exceptionsr   collections.abcr   pandas._typingr	   r   r   pandas.core.genericr   r   r0   rl   rn   CachedAccessorr   _register_df_examplesr   _register_series_examplesr   _register_index_examplesr   r   r   r   <module>r      s_    # " " " " "                  5 4 4 4 4 4 ,(((((($$$$$$++++++       <T& T& T& T& T& T& T& T&v -8[!3" 3" 3" 3" 3"l# # # # # # # #B : : : :z 4 #$$E/ E/ E/ %$E/P 0 #$$A, A, A, %$A,H
 6 #$$E+ E+ E+ %$E+ E+ E+r   