3
���h�! � @ s� d Z ddlmZ ddlZddlmZ ddlm Z ddl
mZmZ ddl
mZmZ ddlmZmZ dd lmZ dd
lmZ ddlmZ ddlmZ deeed�dd�Zd ee eed�dd�Zed�dd�Zed�dd�Z dd� Z!dd� Z"G dd� de�Z#dS )!z?
Shared methods for Index subclasses backed by ExtensionArray.
� )�ListN)�function)�AbstractMethodError)�cache_readonly�doc)�is_dtype_equal�is_object_dtype)�ABCDataFrame� ABCSeries)�ExtensionArray)�deprecate_ndim_indexing)�Index)�get_op_result_nameF)�name�cache�wrapc s� t |��� t� t�rp|r<�fdd�}�|_� j|_t|�}q���fdd�}�fdd�}�|_� j|_t||�}n*t� �s~� }n� �fdd�}�|_� j|_|S ) a�
Make an alias for a method of the underlying ExtensionArray.
Parameters
----------
name : str
Name of an attribute the class should inherit from its EA parent.
delegate : class
cache : bool, default False
Whether to convert wrapped properties into cache_readonly
wrap : bool, default False
Whether to wrap the inherited result in an Index.
Returns
-------
attribute, method, property, or cache_readonly
c s t | j� �S )N)�getattr�_data)�self)r � �?/tmp/pip-build-5_djhm0z/pandas/pandas/core/indexes/extension.py�cached, s z!inherit_from_data.<locals>.cachedc sZ t | j� �}�rVt|t| j��r4t| �j|| jd�S t|t�rH|j| �S t|| jd�S |S )N)r ) r r �
isinstance�type�_simple_newr r � set_indexr
)r �result)r r r r �fget5 s
zinherit_from_data.<locals>.fgetc s t | j� |� d S )N)�setattrr )r �value)r r r �fset? s zinherit_from_data.<locals>.fsetc s` � | j f|�|�}�r\t|t| j ��r:t| �j|| jd�S t|t�rN|j| �S t|| jd�S |S )N)r )r r r r r r r r
)r �args�kwargsr )�attrr r r �methodM s
z!inherit_from_data.<locals>.method)r r �property�__name__�__doc__r �callable)r �delegater r r r$ r r r )r# r r r �inherit_from_data s$
r* )�namesr r c s � ���fdd�}|S )a
Class decorator to pin attributes from an ExtensionArray to a Index subclass.
Parameters
----------
names : List[str]
delegate : class
cache : bool, default False
wrap : bool, default False
Whether to wrap the inherited result in an Index.
c s. x(�D ] }t |�� �d�}t| ||� qW | S )N)r r )r* r )�clsr �meth)r r) r+ r r r �wrapperi s
zinherit_names.<locals>.wrapperr )r+ r) r r r. r )r r) r+ r r �
inherit_names\ s
r/ )�opnamec s � fdd�}� |_ |S )zC
Create a comparison method that dispatches to ``._data``.
c s, t |t�r|j}t|�}t| j� �}||�S )N)r r
Z_values�_maybe_unwrap_indexr r )r �other�op)r0 r r r. x s
z,_make_wrapped_comparison_op.<locals>.wrapper)r& |