o
    �¨Êh¡  ã                   @  s    d Z ddlmZ ddlZddlZddlmZ ddlZddl	m
Z
 ddlZddlmZmZ ddlmZ er:ddlmZ G d	d
„ d
e
ƒZG dd„ deƒZdd„ ZdS )zp
Test extension array for storing nested data in a pandas container.

The ListArray stores an ndarray of lists.
é    )ÚannotationsN)ÚTYPE_CHECKING)ÚExtensionDtype)Úis_object_dtypeÚis_string_dtype)ÚExtensionArray)Útype_tc                   @  s(   e Zd ZeZdZejZe	ddd„ƒZ
dS )Ú	ListDtypeÚlistÚreturnútype_t[ListArray]c                 C  s   t S )zq
        Return the array type associated with this dtype.

        Returns
        -------
        type
        )Ú	ListArray)Úcls© r   úS/var/www/html/env/lib/python3.10/site-packages/pandas/tests/extension/list/array.pyÚconstruct_array_type    s   	zListDtype.construct_array_typeN)r   r   )Ú__name__Ú
__module__Ú__qualname__r
   ÚtypeÚnameÚnpÚnanÚna_valueÚclassmethodr   r   r   r   r   r	      s    r	   c                   @  sx   e Zd Zeƒ ZdZdddd„Zedddœd	d
„ƒZdd„ Z	ddd„Z
dd„ Zddd„Zdd„ Zddd„Zedd„ ƒZdS ) r   iè  NFr   ÚNonec                 C  sT   t |tjƒs
tdƒ‚|D ]}t || jjƒs$t |¡s$tdt| jjƒ ƒ‚q|| _	d S )Nz$Need to pass a numpy array as valueszAll values must be of type )
Ú
isinstancer   ÚndarrayÚ	TypeErrorÚdtyper   ÚpdÚisnaÚstrÚdata)ÚselfÚvaluesr   ÚcopyÚvalr   r   r   Ú__init__0   s   €
zListArray.__init__©r   r&   c                C  s&   t jt|ƒtd�}||d d …< | |ƒS )N©r   )r   ÚemptyÚlenÚobject)r   Úscalarsr   r&   r#   r   r   r   Ú_from_sequence8   s   zListArray._from_sequencec                 C  s(   t |tjƒr| j| S t| ƒ| j| ƒS ©N)r   ÚnumbersÚIntegralr#   r   )r$   Úitemr   r   r   Ú__getitem__>   s   
zListArray.__getitem__Úintc                 C  s
   t | jƒS r0   )r,   r#   ©r$   r   r   r   Ú__len__E   s   
zListArray.__len__c                 C  s   t jdd„ | jD ƒtd�S )Nc                 S  s"   g | ]}t |tƒ ot |¡‘qS r   )r   r
   r   Úisnan©Ú.0Úxr   r   r   Ú
<listcomp>J   s   " z"ListArray.isna.<locals>.<listcomp>r*   )r   Úarrayr#   Úboolr6   r   r   r   r!   H   s   ÿzListArray.isnac              
     s²   t  |¡}d}|r7ˆ d u rˆjj‰ |dk  ¡ rt‚z‡ ‡fdd„|D ƒ}W n. ty6 } zt|ƒ|‚d }~ww z‡fdd„|D ƒ}W n tyS } zt|ƒ|‚d }~ww ˆ |¡S )NzIIndex is out of bounds or cannot do a non-empty take from an empty array.éÿÿÿÿc                   s"   g | ]}|d krˆj | nˆ ‘qS )r?   ©r#   ©r:   Úloc©Ú
fill_valuer$   r   r   r<   ^   s    ÿz"ListArray.take.<locals>.<listcomp>c                   s   g | ]}ˆ j | ‘qS r   r@   rA   r6   r   r   r<   e   s    )r   Úasarrayr   r   ÚanyÚ
ValueErrorÚ
IndexErrorr/   )r$   ÚindexerÚ
allow_fillrD   ÚmsgÚoutputÚerrr   rC   r   ÚtakeM   s.   
ÿ
ÿ
€ÿ
€ÿ
zListArray.takec                 C  s   t | ƒ| jd d … ƒS r0   )r   r#   r6   r   r   r   r&   k   s   zListArray.copyTc                 C  sz   t |t| jƒƒr|| jkr|r|  ¡ S | S t|ƒr*t|ƒs*tjdd„ | jD ƒ|d�S |s4tj	| j|d�S tj| j||d�S )Nc                 S  s   g | ]}t |ƒ‘qS r   )r"   r9   r   r   r   r<   u   s    z$ListArray.astype.<locals>.<listcomp>r*   r)   )
r   r   r   r&   r   r   r   r=   r#   rE   )r$   r   r&   r   r   r   Úastypen   s   zListArray.astypec                 C  s   t  dd„ |D ƒ¡}| |ƒS )Nc                 S  s   g | ]}|j ‘qS r   r@   r9   r   r   r   r<   }   s    z/ListArray._concat_same_type.<locals>.<listcomp>)r   Úconcatenate)r   Ú	to_concatr#   r   r   r   Ú_concat_same_type{   s   zListArray._concat_same_type)NF)r   r   )r   r5   )FN)T)r   r   r   r	   r   Ú__array_priority__r(   r   r/   r4   r7   r!   rN   r&   rO   rR   r   r   r   r   r   ,   s    


r   c                    s<   t j d¡‰ t jdtd�} ‡ fdd„tdƒD ƒ| d d …< | S )Né   éd   r*   c                   s*   g | ]}‡ fd d„t ˆ  dd¡ƒD ƒ‘qS )c                   s   g | ]
}ˆ   ttjƒ¡‘qS r   )Úchoicer
   ÚstringÚascii_letters©r:   Ú_©Úrngr   r   r<   †   s    z(make_data.<locals>.<listcomp>.<listcomp>r   é
   )ÚrangeÚintegersrY   r[   r   r   r<   …   s    ÿÿzmake_data.<locals>.<listcomp>)r   ÚrandomÚdefault_rngr+   r-   r^   r@   r   r[   r   Ú	make_data�   s   
þrb   )Ú__doc__Ú
__future__r   r1   rW   Útypingr   Únumpyr   Úpandas.core.dtypes.baser   Úpandasr    Úpandas.api.typesr   r   Úpandas.core.arraysr   Úpandas._typingr   r	   r   rb   r   r   r   r   Ú<module>   s    U