U
    Dvf‡  ã                   @   sH   d Z ddlmZmZ ddlmZ dd„ Zedœdd„Zedœd	d
„Z	dS )z!XArray support for pandas_flavor.é    )Úregister_dataarray_accessorÚregister_dataset_accessor)Úwrapsc                    s   G ‡ fdd„dƒ}|S )a  
    Makes an XArray-compatible accessor to wrap a method to be added to an
    xr.DataArray, xr.Dataset, or both.

    Args:
        method: A method which takes an XArray object and needed parameters.

    Returns:
        The result of calling ``method``.
    c                       s,   e Zd ZdZdd„ Ze” ƒ‡ fdd„ƒZdS )z)make_accessor_wrapper.<locals>.XRAccessorzXArray accessor for a method.c                 S   s
   || _ dS )z…Initialize the accessor.

            Args:
                xr_obj: The XArray object to which the accessor is attached.
            N©Z_xr_obj)ÚselfZxr_obj© r   ú8/tmp/pip-unpacked-wheel-c6c42brj/pandas_flavor/xarray.pyÚ__init__   s    z2make_accessor_wrapper.<locals>.XRAccessor.__init__c                    s   ˆ | j f|ž|ŽS )zþCall the method.

            Args:
                *args: Positional arguments to pass to the method.
                **kwargs: Keyword arguments to pass to the method.

            Returns:
                The result of calling ``method``.
            r   )r   ÚargsÚkwargs©Úmethodr   r   Ú__call__   s    z2make_accessor_wrapper.<locals>.XRAccessor.__call__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r   r   Ú
XRAccessor   s   r   r   )r   r   r   r   r   Úmake_accessor_wrapper   s    r   r   c                 C   s   t | ƒ}t| jƒ|ƒ | S )z¯Register a method on an XArray DataArray object.

    Args:
        method: A method which takes an XArray object and needed parameters.

    Returns:
        The method.
    )r   r   r   ©r   Zaccessor_wrapperr   r   r   Ú register_xarray_dataarray_method.   s    	r   c                 C   s   t | ƒ}t| jƒ|ƒ | S )z­Register a method on an XArray Dataset object.

    Args:
        method: A method which takes an XArray object and needed parameters.

    Returns:
        The method.
    )r   r   r   r   r   r   r   Úregister_xarray_dataset_method=   s    
r   N)
r   Zxarrayr   r   Ú	functoolsr   r   Úcallabler   r   r   r   r   r   Ú<module>   s
   (