U
    c'	                     @  sp   d Z ddlmZ ddlZddlZddlmZ ddlm	Z	 ddl
ZddlmZ G dd de	ZG d	d
 d
eZdS )zX
Test extension array that has custom attribute information (not stored on the dtype).

    )annotationsN)type_t)ExtensionDtype)ExtensionArrayc                   @  s,   e Zd ZeZdZejZe	ddddZ
dS )FloatAttrDtypeZ
float_attrztype_t[FloatAttrArray]returnc                 C  s   t S )zq
        Return the array type associated with this dtype.

        Returns
        -------
        type
        )FloatAttrArray)cls r   P/tmp/pip-unpacked-wheel-g7fro6k3/pandas/tests/extension/array_with_attr/array.pyconstruct_array_type   s    	z#FloatAttrDtype.construct_array_typeN)__name__
__module____qualname__floattypenamenpnanna_valueclassmethodr   r   r   r   r   r      s
   r   c                   @  sp   e Zd Ze ZdZdddddZeddd	Zd
d Z	ddddZ
dd ZdddZdd Zedd ZdS )r	   i  NNoner   c                 C  s6   t |tjstd|jdks&td|| _|| _d S )Nz5Need to pass a numpy array of float64 dtype as valuesfloat64)
isinstancer   Zndarray	TypeErrordtypedataattr)selfvaluesr   r   r   r   __init__(   s    
zFloatAttrArray.__init__Fc                 C  s   t j|d|d}| |S )Nr   )r   copy)r   array)r
   Zscalarsr   r"   r   r   r   r   _from_sequence0   s    zFloatAttrArray._from_sequencec                 C  s@   t |tjr| j| S tjj| |}t| | j| | j	S d S N)
r   numbersIntegralr   pdapiZindexersZcheck_array_indexerr   r   )r   itemr   r   r   __getitem__5   s    
zFloatAttrArray.__getitem__intc                 C  s
   t | jS r%   )lenr   r   r   r   r   __len__=   s    zFloatAttrArray.__len__c                 C  s   t | jS r%   )r   isnanr   r.   r   r   r   isna@   s    zFloatAttrArray.isnac                 C  sF   ddl m} | j}|r&|d kr&| jj}|||||d}t| || jS )Nr   )take)
fill_value
allow_fill)Zpandas.api.extensionsr2   r   r   r   r   r   )r   Zindexerr4   r3   r2   r   resultr   r   r   r2   C   s    zFloatAttrArray.takec                 C  s   t | | j | jS r%   )r   r   r"   r   r.   r   r   r   r"   M   s    zFloatAttrArray.copyc                 C  s4   t dd |D }t|r&|d jnd }| ||S )Nc                 S  s   g | ]
}|j qS r   )r   ).0xr   r   r   
<listcomp>R   s     z4FloatAttrArray._concat_same_type.<locals>.<listcomp>r   )r   Zconcatenater-   r   )r
   Z	to_concatr   r   r   r   r   _concat_same_typeP   s    z FloatAttrArray._concat_same_type)N)NF)FN)r   r   r   r   r   Z__array_priority__r!   r   r$   r+   r/   r1   r2   r"   r9   r   r   r   r   r	   $   s   

r	   )__doc__
__future__r   r&   Znumpyr   Zpandas._typingr   Zpandas.core.dtypes.baser   Zpandasr(   Zpandas.core.arraysr   r   r	   r   r   r   r   <module>   s   