
    `Vg!                        d Z ddl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
Z
 G d d      Z edd      d        Z eed      d        Z eed      d        Z ee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.

    )annotationsN)doc)find_stack_levelc                  b     e Zd ZU  e       Zded<    e       Zded<   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    U/var/www/html/hubwallet-dev/venv/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   z	list[str])__name__
__module____qualname__r   r	   __annotations__	frozensetr
   r   r   r   __classcell__)r   s   @r   r   r      s0    5J $-KM>/4U
 
r   r   c                  >    e Zd ZdZd Zd Zd Ze	 d	 	 	 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_get1   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_set4   s    -v^<==r   c                    t        d|       )NzYou cannot call method r%   r'   s       r   _delegate_methodzPandasDelegate._delegate_method7   s    1$899r   c                    fd}fd}|D ]4  }|dk(  r	 ||      }n ||      }|st        | |      r(t        | ||       6 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.
        c                z      fd} fd} |_          |_         t        ||t               j                        S )Nc                &    | j                        S N)r+   )r   r(   s    r   _getterz[PandasDelegate._add_delegate_accessors.<locals>._create_delegator_property.<locals>._getterO   s    22488r   c                (    | j                  |      S r4   )r.   )r   
new_valuesr(   s     r   _setterz[PandasDelegate._add_delegate_accessors.<locals>._create_delegator_property.<locals>._setterR   s    224DDr   )fgetfsetr   )r   propertygetattr__doc__)r(   r5   r8   delegates   `  r   _create_delegator_propertyzJPandasDelegate._add_delegate_accessors.<locals>._create_delegator_propertyN   sA    9E  $G#G7$0G0O0O r   c                X      fd} |_         t               j                  |_        |S )Nc                0     | j                   g|i |S r4   )r0   )r   r)   r*   r(   s      r   fzSPandasDelegate._add_delegate_accessors.<locals>._create_delegator_method.<locals>.f]   s     ,t,,TCDCFCCr   )r   r<   r=   )r(   rB   r>   s   ` r   _create_delegator_methodzHPandasDelegate._add_delegate_accessors.<locals>._create_delegator_method\   s+    D AJ$/77AIHr   r;   N)r   setattr)	clsr>   	accessorstyp	overwriter?   rC   r(   rB   s	    `       r   _add_delegate_accessorsz&PandasDelegate._add_delegate_accessors:   sT    (		  		&Dj .t4,T2 T 2T1%		&r   NFrG   strrH   bool)	r   r   r   r=   r+   r.   r0   classmethodrI    r   r   r#   r#   ,   s>    B>: >C3&'*3&7;3& 3&r   r#   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.

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

    Examples
    --------
    @delegate_names(Categorical, ["categories", "ordered"], "property")
    class CategoricalAccessor(PandasDelegate):
        [...]
    c                2    | j                         | S )N)rH   )rI   )rE   rF   r>   rH   rG   s    r   add_delegate_accessorsz.delegate_names.<locals>.add_delegate_accessors   s    ##Hi	#R
r   rO   )r>   rF   rG   rH   rR   s   ```` r   delegate_namesrS   q   s    8 "!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 r4   )_name	_accessor)r   r(   r   s      r   __init__zCachedAccessor.__init__   s    
!r   c                    || j                   S | j                  |      }t        j                  || j                  |       |S r4   )rX   object__setattr__rW   )r   objrE   accessor_objs       r   __get__zCachedAccessor.__get__   s=    ;>>!~~c*
 	3

L9r   N)r(   rL   r   None)r   r   r   r=   rY   r_   rO   r   r   rU   rU      s    &"
r   rU    )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   rD   rU   r	   add)r   rE   r(   s    r   	decoratorz%_register_accessor.<locals>.decorator  s{    3MM+DN+;<:,jc 401 +- 	T>$9:4 r   rO   )r(   rE   rl   s   `` r   _register_accessorrm      s    R r   	DataFrame)rb   c                &    ddl m} t        | |      S )Nr   )rn   )pandasrn   rm   )r(   rn   s     r   register_dataframe_accessorrq     s     dI..r   Seriesc                &    ddl m} t        | |      S )Nr   )rr   )rp   rr   rm   )r(   rr   s     r   register_series_accessorrt     s    dF++r   Indexc                &    ddl m} t        | |      S )Nr   )ru   )rp   ru   rm   )r(   ru   s     r   register_index_accessorrw   &  s    dE**r   rJ   rK   )r=   
__future__r   rg   pandas.util._decoratorsr   pandas.util._exceptionsr   r   r#   rS   rU   rm   rq   rt   rw   rO   r   r   <module>r{      s    #  ' 4 :B& B&J "R" "J 2bU Up {+/ ,/ x(, ), w'+ (+r   