HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/core/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/core/__pycache__/accessor.cpython-36.pyc
3

���h"�@s�dZddlmZmZddlZddlmZGdd�d�ZGdd�d�Zde	e
d
�dd�ZGd
d�d�Zeddd�dd��Z
ee
dd�dd��Zee
dd�dd��Zee
dd�dd��ZdS)z�

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

�)�	FrozenSet�SetN)�docc@sBeZdZUe�Zeee�Ze	edd�Z
dd�Zdd�ZdS)�
DirNamesMixincCs|j|jBS)z:
        Delete unwanted __dir__ for this object.
        )�
_accessors�
_deprecations)�self�r	�6/tmp/pip-build-5_djhm0z/pandas/pandas/core/accessor.py�_dir_deletionsszDirNamesMixin._dir_deletionscCsHt�}x<|jD]2}yt||�|j|�Wqtk
r>YqXqW|S)z9
        Add additional __dir__ for this object.
        )�setr�getattr�add�AttributeError)r�rv�accessorr	r	r
�_dir_additionss

zDirNamesMixin._dir_additionscCs,ttt|���}||j�|j�B}t|�S)z�
        Provide method name lookup and completion.

        Notes
        -----
        Only provide 'public' methods.
        )r�dir�typerr�sorted)rrr	r	r
�__dir__$szDirNamesMixin.__dir__N)
�__name__�
__module__�__qualname__rrr�str�	frozensetrrrrrr	r	r	r
r
s


rc@s>eZdZdZdd�Zdd�Zdd�Zed
ee	d	�d
d��Z
dS)�PandasDelegatez@
    Abstract base class for delegating methods/properties.
    cOstd|����dS)NzYou cannot access the property )�	TypeError)r�name�args�kwargsr	r	r
�_delegate_property_get6sz%PandasDelegate._delegate_property_getcOstd|�d���dS)Nz
The property z cannot be set)r)rr�valuerr r	r	r
�_delegate_property_set9sz%PandasDelegate._delegate_property_setcOstd|����dS)NzYou cannot call method )r)rrrr r	r	r
�_delegate_method<szPandasDelegate._delegate_methodF)�typ�	overwritec	s`�fdd�}�fdd�}xB|D]:}|dkr4||�}n||�}|sLt||�rt|||�qWdS)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.
        cs:�fdd�}�fdd�}�|_�|_t||t���jd�S)Ncs
|j��S)N)r!)r)rr	r
�_getterTsz[PandasDelegate._add_delegate_accessors.<locals>._create_delegator_property.<locals>._gettercs|j�|�S)N)r#)rZ
new_values)rr	r
�_setterWsz[PandasDelegate._add_delegate_accessors.<locals>._create_delegator_property.<locals>._setter)�fget�fsetr)r�propertyr
�__doc__)rr'r()�delegate)rr
�_create_delegator_propertySszJPandasDelegate._add_delegate_accessors.<locals>._create_delegator_propertycs$�fdd�}�|_t���j|_|S)Ncs|j�f|�|�S)N)r$)rrr )rr	r
�fbszSPandasDelegate._add_delegate_accessors.<locals>._create_delegator_method.<locals>.f)rr
r,)rr/)r-)rr
�_create_delegator_methodaszHPandasDelegate._add_delegate_accessors.<locals>._create_delegator_methodr+N)�hasattr�setattr)	�clsr-�	accessorsr%r&r.r0rr/r	)r-r
�_add_delegate_accessors?s	

z&PandasDelegate._add_delegate_accessorsN)F)rrrr,r!r#r$�classmethodr�boolr5r	r	r	r
r1srF)r%r&cs����fdd�}|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):
        [...]
    cs|j����d�|S)N)r&)r5)r3)r4r-r&r%r	r
�add_delegate_accessors�sz.delegate_names.<locals>.add_delegate_accessorsr	)r-r4r%r&r8r	)r4r-r&r%r
�delegate_namesvsr9c@s(eZdZdZedd�dd�Zdd�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``.
    N)r�returncCs||_||_dS)N)�_name�	_accessor)rrrr	r	r
�__init__�szCachedAccessor.__init__cCs,|dkr|jS|j|�}tj||j|�|S)N)r=�object�__setattr__r<)r�objr3Zaccessor_objr	r	r
�__get__�s

zCachedAccessor.__get__)rrrr,rr>rBr	r	r	r
r:�sr:�)�klassZotherscs��fdd�}|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
    cs\t���r:tjdt|��dt���dt���d�tdd�t��t�|���jj��|S)Nzregistration of accessor z under name z
 for type z: is overriding a preexisting attribute with the same name.�)�
stacklevel)	r1�warnings�warn�repr�UserWarningr2r:rr)r)r3rr	r
�	decorator
s
"z%_register_accessor.<locals>.decoratorr	)rr3rKr	)r3rr
�_register_accessor�sI
rL�	DataFrame)rDcCsddlm}t||�S)Nr)rM)�pandasrMrL)rrMr	r	r
�register_dataframe_accessorsrO�SeriescCsddlm}t||�S)Nr)rP)rNrPrL)rrPr	r	r
�register_series_accessor$srQ�IndexcCsddlm}t||�S)Nr)rR)rNrRrL)rrRr	r	r
�register_index_accessor+srS)F)r,ZtypingrrrGZpandas.util._decoratorsrrrrr7r9r:rLrOrQrSr	r	r	r
�<module>s$E)%Y