o
    5c}                     @  s   d Z ddlmZ ddlZddlZddlZddlZddl	m
Z
 ddlZddlmZmZmZ ddlmZ ddlmZ ddlmZ eG d	d
 d
eZeG dd deZG dd deZG dd deZG dd deZdS )a  
Rudimentary Apache Arrow-backed ExtensionArray.

At the moment, just a boolean array / type is implemented.
Eventually, we'll want to parametrize the type and support
multiple dtypes. Not all methods are implemented yet, and the
current implementation is not efficient.
    )annotationsN)type_t)ExtensionDtyperegister_extension_dtypetake)	is_scalar)ArrowExtensionArray)extract_arrayc                   @  s<   e Zd ZejZdZdZej	Z
edddZeddd	Zd
S )ArrowBoolDtypeb
arrow_boolreturntype_t[ArrowBoolArray]c                 C     t S zq
        Return the array type associated with this dtype.

        Returns
        -------
        type
        )ArrowBoolArraycls r   Y/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/tests/extension/arrow/arrays.pyconstruct_array_type&      	z#ArrowBoolDtype.construct_array_typeboolc                 C  s   dS )NTr   selfr   r   r   _is_boolean1   s   zArrowBoolDtype._is_booleanN)r   r   r   r   )__name__
__module____qualname__npbool_typekindnamepaNULLna_valueclassmethodr   propertyr   r   r   r   r   r
      s    
r
   c                   @  s,   e Zd ZeZdZdZejZ	e
dddZdS )	ArrowStringDtypeUarrow_stringr   type_t[ArrowStringArray]c                 C  r   r   )ArrowStringArrayr   r   r   r   r   >   r   z%ArrowStringDtype.construct_array_typeN)r   r-   )r   r   r   strr"   r#   r$   r%   r&   r'   r(   r   r   r   r   r   r*   6   s    r*   c                      s   e Zd ZU ded< ed)ddZdd Zd* fddZdd Zd+ fdd	Z	e
dd Zdd Zdd Zd,ddZedd Zdd Zddd-d"d#Zd.d%d&Zd.d'd(Z  ZS )/r   zpa.ChunkedArray_dataNFc                 C  sd   t || r
| |jS t|s"t |tr"| tu rtnt}tjg |d}t	
t	t|g}| |S )Ndtype)
isinstancer0   lenlistr   r   r/   r    arrayr%   chunked_arrayasarray)r   valuesr2   copyarrr   r   r   _from_sequenceM   s   


z"ArrowExtensionArray._from_sequencec                 C  s   t | j dt| j dS )N())r"   r   reprr0   r   r   r   r   __repr__^   s   zArrowExtensionArray.__repr__r   r   c                   s4   |d u s
|| j ju rt|   S tt |S N)r2   r'   r   isnaanysuper__contains__)r   obj	__class__r   r   rE   a   s   z ArrowExtensionArray.__contains__c                 C  s2   t |r| j | S | j | }t| |S rA   )r   r0   	to_pandasr"   r<   )r   itemvalsr   r   r   __getitem__i   s   zArrowExtensionArray.__getitem__Tc                   s8   t |t| jr|| jkr|r|  S | S t ||S rA   )r3   r"   r2   r:   rD   astype)r   r2   r:   rG   r   r   rM   p   s
   zArrowExtensionArray.astypec                 C  s   | j S rA   )_dtyper   r   r   r   r2   x   s   zArrowExtensionArray.dtypec              	   C  sT   t |t| s
t |t| jt|j}tttj|t	
| j dgS )N)mask)r3   r"   NotImplementedErrorr    r6   r0   r   r%   r7   pdrB   rI   )r   otheropresultr   r   r   _logical_method|   s    z#ArrowExtensionArray._logical_methodc                 C  s,   t |t| st| |S | |tjS rA   )r3   r"   r    r8   __eq__rU   operatoreq)r   rR   r   r   r   rV      s   zArrowExtensionArray.__eq__c                 C  sJ   | j  }t|dd}|r|d u r| jj}t||||d}| j|| jdS )NT)extract_numpy)
fill_value
allow_fillr1   )r0   rI   r	   r2   r'   r   r<   )r   indicesr[   rZ   datarT   r   r   r   r      s   
zArrowExtensionArray.takec                 C  s,   t tjdd |D }t|}| |S )Nc                 s  s    | ]}|j jV  qd S rA   )r0   chunks).0xr   r   r   	<genexpr>   s    z8ArrowExtensionArray._concat_same_type.<locals>.<genexpr>)r5   	itertoolschainfrom_iterabler%   r7   )r   	to_concatr^   r;   r   r   r   _concat_same_type   s   
z%ArrowExtensionArray._concat_same_typec                 C  s   t | | j  S rA   )r"   r<   r0   rI   r   r   r   r   
__invert__   s   zArrowExtensionArray.__invert__)skipnar$   r/   rh   c             
   K  sT   |r
| |     }n| }zt||}W n ty" } zt|d }~ww |di |S )Nr   )rB   getattrAttributeError	TypeError)r   r$   rh   kwargsr;   rS   errr   r   r   _reduce   s   zArrowExtensionArray._reducer   c                 C     t | j  S rA   )r   r0   rI   rC   r   axisoutr   r   r   rC         zArrowExtensionArray.anyc                 C  ro   rA   )r   r0   rI   allrp   r   r   r   rt      rs   zArrowExtensionArray.all)NFr   )T)FN)r$   r/   rh   r   )r   N)r   r   r   __annotations__r(   r<   r@   rE   rL   rM   r)   r2   rU   rV   r   rf   rg   rn   rC   rt   __classcell__r   r   rG   r   r   J   s&   
 
	



r   c                   @     e Zd ZdddZdS )r   r   Nonec                 C  4   t |tjst|jt ksJ || _t | _d S rA   )	r3   r%   ChunkedArray
ValueErrorr"   r!   r0   r
   rN   r   r9   r   r   r   __init__   
   zArrowBoolArray.__init__Nr   rx   r   r   r   r}   r   r   r   r   r          r   c                   @  rw   )r.   r   rx   c                 C  ry   rA   )	r3   r%   rz   r{   r"   stringr0   r*   rN   r|   r   r   r   r}      r~   zArrowStringArray.__init__Nr   r   r   r   r   r   r.      r   r.   )__doc__
__future__r   rb   rW   numpyr    pyarrowr%   pandas._typingr   pandasrQ   pandas.api.extensionsr   r   r   pandas.api.typesr   pandas.core.arrays.arrowr   _ArrowExtensionArraypandas.core.constructionr	   r
   r*   r   r.   r   r   r   r   <module>   s&    j
