
    Eg<'                    ^   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dS )'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                  ~     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    I/var/www/sysmax/venv/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__$   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   r,   argskwargss       r   _delegate_property_getz%PandasDelegate._delegate_property_get6   s    @$@@AAAr   c                (    t          d| d          )NzThe property z cannot be setr/   )r   r,   valuer2   r3   s        r   _delegate_property_setz%PandasDelegate._delegate_property_set9   s    <<<<===r   c                &    t          d|           )NzYou cannot call method r/   r1   s       r   _delegate_methodzPandasDelegate._delegate_method<   s    8$88999r   Fc                    | S Nr   xs    r   <lambda>zPandasDelegate.<lambda>F   s    1 r   T	accessorsr   typ	overwriteboolaccessor_mappingCallable[[str], str]raise_on_missingr   Nonec                    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 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.
        r,   r-   c           
           fd} fd} |_          |_         t          ||t                                j                  S )Nc                .    |                                S r;   )r4   )r   r,   s    r   _getterz[PandasDelegate._add_delegate_accessors.<locals>._create_delegator_property.<locals>._getter_   s    224888r   c                0    |                      |          S r;   )r7   )r   
new_valuesr,   s     r   _setterz[PandasDelegate._add_delegate_accessors.<locals>._create_delegator_property.<locals>._setterb   s    224DDDr   )fgetfsetr   )r$   propertygetattr__doc__)r,   rJ   rM   rC   delegates   `  r   _create_delegator_propertyzJPandasDelegate._add_delegate_accessors.<locals>._create_delegator_property^   s    9 9 9 9 9E E E E E  $G#GH&6&6t&<&<==E   r   c                h      fd} |_         t                                j        |_        |S )Nc                &     | j         g|R i |S r;   )r9   )r   r2   r3   r,   s      r   fzSPandasDelegate._add_delegate_accessors.<locals>._create_delegator_method.<locals>.fo   s&    ,t,TCDCCCFCCCr   )r$   rQ   rR   )r,   rW   rC   rS   s   ` r   _create_delegator_methodzHPandasDelegate._add_delegate_accessors.<locals>._create_delegator_methodn   sP    D D D D D AJ*:*:4*@*@AAIAIHr   NrP   r,   r-   )rQ   r   setattr)clsrS   r?   r@   rA   rC   rE   rT   rX   r,   rW   s    `   `     r   _add_delegate_accessorsz&PandasDelegate._add_delegate_accessors?   s    >	 	 	 	 	 	 	 	 	 	 	 	 	 	  	& 	&D$H&6&6t&<&<dCCKj  ..t44,,T22  &T 2 2 &T1%%%	& 	&r   NrY   )r?   r   r@   r-   rA   rB   rC   rD   rE   rB   r   rF   )	r$   r%   r&   rR   r4   r7   r9   classmethodr\   r   r   r   r+   r+   1   s         B B B B> > > >: : : :   1<!%E& E& E& E& [E& E& E&r   r+   Fc                    | S r;   r   r<   s    r   r>   r>      s    q r   Tr?   r   r@   r-   rA   rB   rC   rD   rE   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 & 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                >    |                                 | S )N)rA   rC   rE   )r\   )r[   rC   r?   rS   rA   rE   r@   s    r   add_delegate_accessorsz.delegate_names.<locals>.add_delegate_accessors   s9    ##-- 	$ 	
 	
 	
 
r   r   )rS   r?   r@   rA   rC   rE   ra   s   `````` r   delegate_namesrb      sC    P	 	 	 	 	 	 	 	 	 	 "!r   c                       e Zd ZdZd	dZd ZdS )
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``.
    r,   r-   r   rF   c                "    || _         || _        d S r;   )_name	_accessor)r   r,   r   s      r   __init__zCachedAccessor.__init__   s    
!r   c                    || j         S |                      |          }t                              || j        |           |S r;   )rg   object__setattr__rf   )r   objr[   accessor_objs       r   __get__zCachedAccessor.__get__   sB    ;>!~~c**
 	3
L999r   N)r,   r-   r   rF   )r$   r%   r&   rR   rh   rn   r   r   r   rd   rd      sA         &" " " "
 
 
 
 
r   rd    )klassothersr,   c                      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           
     L   t                    rYt          j        dt          |            dt                     dt                     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reprUserWarningr   rZ   rd   r   add)r   r[   r,   s    r   	decoratorz%_register_accessor.<locals>.decorator2  s    3 	M1DNN 1 1::1 1)-c1 1 1 +--    	T>$99:::4   r   r   )r,   r[   rz   s   `` r   _register_accessorr{      s+    R      r   	DataFrame)rp   c                .    ddl m} t          | |          S )Nr   )r|   )pandasr|   r{   )r,   r|   s     r   register_dataframe_accessorr   B  s$          dI...r   Seriesc                .    ddl m} t          | |          S )Nr   )r   )r~   r   r{   )r,   r   s     r   register_series_accessorr   I  s$    dF+++r   Indexc                .    ddl m} t          | |          S )Nr   )r   )r~   r   r{   )r,   r   s     r   register_index_accessorr   P  s$    dE***r   )
r?   r   r@   r-   rA   rB   rC   rD   rE   rB   rY   )rR   
__future__r   typingr   r   ru   pandas.util._decoratorsr   pandas.util._exceptionsr   r	   r+   rb   rd   r{   r   r   r   r   r   r   <module>r      s    # " " " " "         ' ' ' ' ' ' 4 4 4 4 4 4       <T& T& T& T& T& T& T& T&v -8[!3" 3" 3" 3" 3"x" " " " " " " "J 2bU U U Up {+++/ / / ,+/ x(((, , , )(, w'''+ + + ('+ + +r   