HOME


sh-3ll 1.0
DIR:/opt/cloudlinux/venv/lib/python3.11/site-packages/pandas/core/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/pandas/core/__pycache__/accessor.cpython-311.pyc
�

���h<'��^�dZddlmZddlmZmZddlZddlmZddl	m
Z
Gd�d��ZGd	�d
��Zdd�d
fd%d�Z
Gd�d��Zedd���d&d���Zeed���d&d ���Zeed!���d&d"���Zeed#���d&d$���ZdS)'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�~��eZdZUe��Zded<e��Zded<ed
d���Z	d
d�Z
d�fd	�Z�xZS)�
DirNamesMixin�set[str]�
_accessorszfrozenset[str]�
_hidden_attrs�returnc� �|j|jzS)z:
        Delete unwanted __dir__ for this object.
        )rr��selfs �K/opt/cloudlinux/venv/lib64/python3.11/site-packages/pandas/core/accessor.py�_dir_deletionszDirNamesMixin._dir_deletionss��
���!3�3�3�c�*���fd��jD��S)z9
        Add additional __dir__ for this object.
        c�4��h|]}t�|���|��S�)�hasattr)�.0�accessorrs  �r�	<setcomp>z/DirNamesMixin._dir_additions.<locals>.<setcomp>"s(���T�T�T�X�G�D�(�<S�<S�T��T�T�Tr)rrs`r�_dir_additionszDirNamesMixin._dir_additionss"���U�T�T�T���T�T�T�Tr�	list[str]c����tt�������}||���z
|���z}t|��S)z�
        Provide method name lookup and completion.

        Notes
        -----
        Only provide 'public' methods.
        )�set�super�__dir__rr�sorted)r�rv�	__class__s  �rr zDirNamesMixin.__dir__$sS���������"�"�
#�
#���4�&�&�(�(�(�D�,?�,?�,A�,A�
A���b�z�z�r)r
r
)r
r)
�__name__�
__module__�__qualname__rr�__annotations__�	frozensetrrrrr �
__classcell__)r#s@rr	r	s����������3�5�5�J� � � � �$-�I�K�K�M�/�/�/�/�
�4�4�4��U�4�U�U�U�U�
�
�
�
�
�
�
�
�
�
rr	c�L�eZdZdZdd�Zdd�Zdd�Zedd�d	fdd���ZdS)�PandasDelegatez@
    Abstract base class for delegating methods/properties.
    �name�strc�&�td|�����)NzYou cannot access the property ��	TypeError�rr,�args�kwargss    r�_delegate_property_getz%PandasDelegate._delegate_property_get6s���@�$�@�@�A�A�Arc�(�td|�d����)Nz
The property z cannot be setr/)rr,�valuer2r3s     r�_delegate_property_setz%PandasDelegate._delegate_property_set9s���<��<�<�<�=�=�=rc�&�td|�����)NzYou cannot call method r/r1s    r�_delegate_methodzPandasDelegate._delegate_method<s���8�$�8�8�9�9�9rFc��|S�Nr��xs r�<lambda>zPandasDelegate.<lambda>Fs��1�rT�	accessorsr�typ�	overwrite�bool�accessor_mapping�Callable[[str], str]�raise_on_missingr
�Nonec�����d��fd�}d��fd�}|D]_}	|st��|	��d����|dkr||	��}
n||	��}
|st||	��st||	|
���`dS)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
�����fd�}�fd�}�|_�|_t||t�������j���S)Nc�.��|����Sr;)r4)rr,s �r�_getterz[PandasDelegate._add_delegate_accessors.<locals>._create_delegator_property.<locals>._getter_s����2�2�4�8�8�8rc�0��|��|��Sr;)r7)r�
new_valuesr,s  �r�_setterz[PandasDelegate._add_delegate_accessors.<locals>._create_delegator_property.<locals>._setterbs����2�2�4��D�D�Dr)�fget�fsetr)r$�property�getattr�__doc__)r,rJrMrC�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�&6�t�&<�&<�=�=�E����
rc�h����fd�}�|_t�������j|_|S)Nc�&��|j�g|�Ri|��Sr;)r9)rr2r3r,s   �r�fzSPandasDelegate._add_delegate_accessors.<locals>._create_delegator_method.<locals>.fos&���,�t�,�T�C�D�C�C�C�F�C�C�Cr)r$rQrR)r,rWrCrSs` ��r�_create_delegator_methodzHPandasDelegate._add_delegate_accessors.<locals>._create_delegator_methodnsP����
D�
D�
D�
D�
D��A�J���*:�*:�4�*@�*@�A�A�I�A�I��HrNrP�r,r-)rQr�setattr)�clsrSr?r@rArCrErTrXr,rWs `   `     r�_add_delegate_accessorsz&PandasDelegate._add_delegate_accessors?s�����>	�	�	�	�	�	�	� 	�	�	�	�	�	�	��	&�	&�D�$�
��H�&6�&6�t�&<�&<�d�C�C�K���j� � �.�.�t�4�4���,�,�T�2�2���
&���T� 2� 2�
&���T�1�%�%�%��	&�	&rNrY)r?rr@r-rArBrCrDrErBr
rF)	r$r%r&rRr4r7r9�classmethodr\rrrr+r+1s���������B�B�B�B�>�>�>�>�:�:�:�:�� �1<��!%�E&�E&�E&�E&��[�E&�E&�E&rr+Fc��|Sr;rr<s rr>r>�s��q�rTr?rr@r-rArBrCrDrEc�&�������������fd�}|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)rArCrE)r\)r[rCr?rSrArEr@s ������r�add_delegate_accessorsz.delegate_names.<locals>.add_delegate_accessors�s9����#�#�����-�-�
	$�	
�	
�	
��
rr)rSr?r@rArCrEras`````` r�delegate_namesrb�sC��������P	�	�	�	�	�	�	�	�	�	�"�!rc� �eZdZdZd	d�Zd�ZdS)
�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
rFc�"�||_||_dSr;)�_name�	_accessor)rr,rs   r�__init__zCachedAccessor.__init__�s����
�!����rc��|�|jS|�|��}t�||j|��|Sr;)rg�object�__setattr__rf)r�objr[�accessor_objs    r�__get__zCachedAccessor.__get__�sB���;��>�!��~�~�c�*�*��
	���3��
�L�9�9�9��rN)r,r-r
rF)r$r%r&rRrhrnrrrrdrd�sA��������&"�"�"�"�
�
�
�
�
rrd�)�klass�othersr,c������fd�}|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����rYtjdt|���dt����dt����d�tt�����t
��t�|�����j�	���|S)Nzregistration of accessor z under name z
 for type z: is overriding a preexisting attribute with the same name.)�
stacklevel)
r�warnings�warn�repr�UserWarningrrZrdr�add)rr[r,s ��r�	decoratorz%_register_accessor.<locals>.decorator2s�����3����	��M�1�D��N�N�1�1���:�:�1�1�)-�c���1�1�1��+�-�-�
�
�
�
�	��T�>�$��9�9�:�:�:�����4� � � ��rr)r,r[rzs`` r�_register_accessorr{�s+����R�������r�	DataFrame)rpc�.�ddlm}t||��S)Nr)r|)�pandasr|r{)r,r|s  r�register_dataframe_accessorrBs$�� � � � � � ��d�I�.�.�.r�Seriesc�.�ddlm}t||��S)Nr)r�)r~r�r{)r,r�s  r�register_series_accessorr�Is$���������d�F�+�+�+r�Indexc�.�ddlm}t||��S)Nr)r�)r~r�r{)r,r�s  r�register_index_accessorr�Ps$���������d�E�*�*�*r)
r?rr@r-rArBrCrDrErBrY)rR�
__future__r�typingrrru�pandas.util._decoratorsr�pandas.util._exceptionsrr	r+rbrdr{rr�r�rrr�<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��2�b����U�U�U���U�p���{�+�+�+�/�/�/�,�+�/����x�(�(�(�,�,�,�)�(�,����w�'�'�'�+�+�+�(�'�+�+�+r