
    Owg<'                    ,   d Z ddlmZ ddlmZmZ ddl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dd      dd       Z eed      dd       Z eed      dd       Z eed      dd       Zy)z

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

    )annotations)CallablefinalN)doc)find_stack_levelc                  l     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_attrsc                4    | j                   | j                  z  S )z:
        Delete unwanted __dir__ for this object.
        )r   r   )selfs    K/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/core/accessor.py_dir_deletionszDirNamesMixin._dir_deletions   s    
 !3!333    c                Z    | j                   D ch c]  }t        | |      s| c}S c c}w )z9
        Add additional __dir__ for this object.
        )r   hasattr)r   accessors     r   _dir_additionszDirNamesMixin._dir_additions   s%     *.TXGD(<STTTs   ((c                    t        t        | 	               }|| j                         z
  | j	                         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__$   sA     "#4&&((D,?,?,AAbzr   )returnr
   )r   	list[str])__name__
__module____qualname__r   r   __annotations__	frozensetr   r   r   r   r   __classcell__)r   s   @r   r	   r	      s=    5J $-KM>/
4 4U
 
r   r	   c                  Z    e Zd ZdZd
dZd
dZd
dZedd df	 	 	 	 	 	 	 	 	 	 	 dd       Zy	)PandasDelegatez@
    Abstract base class for delegating methods/properties.
    c                    t        d|       )NzYou cannot access the property 	TypeErrorr   nameargskwargss       r   _delegate_property_getz%PandasDelegate._delegate_property_get6   s    9$@AAr   c                     t        d| d      )NzThe property z cannot be setr(   )r   r+   valuer,   r-   s        r   _delegate_property_setz%PandasDelegate._delegate_property_set9   s    -v^<==r   c                    t        d|       )NzYou cannot call method r(   r*   s       r   _delegate_methodzPandasDelegate._delegate_method<   s    1$899r   Fc                    | S N xs    r   <lambda>zPandasDelegate.<lambda>F   s    1 r   Tc                    dfd}dfd}|D ]J  }	|st         |	      d      |dk(  r	 ||	      }
n ||	      }
|st        | |	      r>t        | |	|
       L y)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 doc-strings.
        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.
        c           
           fd} fd} |_          |_         t        ||t                      j                        S )Nc                &    | j                        S r5   )r.   )r   r+   s    r   _getterz[PandasDelegate._add_delegate_accessors.<locals>._create_delegator_property.<locals>._getter_   s    22488r   c                (    | j                  |      S r5   )r1   )r   
new_valuesr+   s     r   _setterz[PandasDelegate._add_delegate_accessors.<locals>._create_delegator_property.<locals>._setterb   s    224DDr   )fgetfsetr   )r   propertygetattr__doc__)r+   r=   r@   accessor_mappingdelegates   `  r   _create_delegator_propertyzJPandasDelegate._add_delegate_accessors.<locals>._create_delegator_property^   sI    9E  $G#GH&6t&<=EE r   c                d      fd} |_         t                      j                  |_        |S )Nc                0     | j                   g|i |S r5   )r3   )r   r,   r-   r+   s      r   fzSPandasDelegate._add_delegate_accessors.<locals>._create_delegator_method.<locals>.fo   s     ,t,,TCDCFCCr   )r   rD   rE   )r+   rK   rF   rG   s   ` r   _create_delegator_methodzHPandasDelegate._add_delegate_accessors.<locals>._create_delegator_methodn   s1    D AJ*:4*@AIIAIHr   NrC   r+   str)rD   r   setattr)clsrG   	accessorstyp	overwriterF   raise_on_missingrH   rL   r+   rK   s    `   `     r   _add_delegate_accessorsz&PandasDelegate._add_delegate_accessors?   so    >	 	  	&D$H&6t&<dCKj .t4,T2 T 2T1%	&r   NrM   )rQ   r   rR   rN   rS   boolrF   Callable[[str], str]rT   rV   r   None)	r   r    r!   rE   r.   r1   r3   classmethodrU   r6   r   r   r&   r&   1   sz    B>:   1<!%E& E& 	E&
 E& /E& E& 
E& E&r   r&   Fc                    | S r5   r6   r7   s    r   r9   r9      s    q r   Tc                &      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 & doc-strings.
    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                6    | j                         | S )N)rS   rF   rT   )rU   )rP   rF   rQ   rG   rS   rT   rR   s    r   add_delegate_accessorsz.delegate_names.<locals>.add_delegate_accessors   s/    ##-- 	$ 	
 
r   r6   )rG   rQ   rR   rS   rF   rT   r]   s   `````` r   delegate_namesr^      s    P	 	 "!r   c                      e Zd ZdZddZd Zy)CachedAccessora  
    Custom property-like object.

    A descriptor for caching 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``.
    c                     || _         || _        y r5   )_name	_accessor)r   r+   r   s      r   __init__zCachedAccessor.__init__   s    
!r   c                    || j                   S | j                  |      }t        j                  || j                  |       |S r5   )rc   object__setattr__rb   )r   objrP   accessor_objs       r   __get__zCachedAccessor.__get__   s=    ;>>!~~c*
 	3

L9r   N)r+   rN   r   rX   )r   r    r!   rE   rd   rj   r6   r   r   r`   r`      s    &"
r   r`    )klassothersc                      fd}|S )aG  
    Register a custom accessor on {klass} 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
    -----
    When accessed, your accessor will be initialized with the pandas object
    the user is interacting with. So the signature must be

    .. code-block:: python

        def __init__(self, pandas_object):  # noqa: E999
            ...

    For consistency with pandas methods, you should raise an ``AttributeError``
    if the data passed to your accessor has an incorrect dtype.

    >>> pd.Series(['a', 'b']).dt
    Traceback (most recent call last):
    ...
    AttributeError: Can only use .dt accessor with datetimelike values

    Examples
    --------
    In your library code::

        import pandas as pd

        @pd.api.extensions.register_dataframe_accessor("geo")
        class GeoAccessor:
            def __init__(self, pandas_obj):
                self._obj = pandas_obj

            @property
            def center(self):
                # return the geographic center point of this DataFrame
                lat = self._obj.latitude
                lon = self._obj.longitude
                return (float(lon.mean()), float(lat.mean()))

            def plot(self):
                # plot this array's data on a map, e.g., using Cartopy
                pass

    Back in an interactive IPython session:

        .. code-block:: ipython

            In [1]: ds = pd.DataFrame({{"longitude": np.linspace(0, 10),
               ...:                    "latitude": np.linspace(0, 20)}})
            In [2]: ds.geo.center
            Out[2]: (5.0, 10.0)
            In [3]: ds.geo.plot()  # plots data on a map
    c           
        t              rIt        j                  dt        |        dt               dt               dt        t                      t        t        |              j                  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reprUserWarningr   rO   r`   r   add)r   rP   r+   s    r   	decoratorz%_register_accessor.<locals>.decorator2  s{    3MM+DN+;<:,jc 401 +- 	T>$9:4 r   r6   )r+   rP   rv   s   `` r   _register_accessorrw      s    R r   	DataFrame)rl   c                &    ddl m} t        | |      S )Nr   )rx   )pandasrx   rw   )r+   rx   s     r   register_dataframe_accessorr{   B  s     dI..r   Seriesc                &    ddl m} t        | |      S )Nr   )r|   )rz   r|   rw   )r+   r|   s     r   register_series_accessorr~   I  s    dF++r   Indexc                &    ddl m} t        | |      S )Nr   )r   )rz   r   rw   )r+   r   s     r   register_index_accessorr   P  s    dE**r   )
rQ   r   rR   rN   rS   rV   rF   rW   rT   rV   rM   )rE   
__future__r   typingr   r   rq   pandas.util._decoratorsr   pandas.util._exceptionsr   r	   r&   r^   r`   rw   r{   r~   r   r6   r   r   <module>r      s    #  ' 4 <T& T&v -8!3"3" 
3" 	3"
 +3" 3"x" "J 2bU Up {+/ ,/ x(, ), w'+ (+r   