o
    ·¶ßd¢  ã                   @   sN   d Z ddlZddlZddlmZ ddlmZmZ ddl	m
Z G dd„ dƒZdS )zž
test_insert is specifically for the DataFrame.insert method; not to be
confused with tests with "insert" in their names that are really testing
__setitem__.
é    N)ÚPerformanceWarning)Ú	DataFrameÚIndexc                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTestDataFrameInsertc                 C   sT  t tj dd¡t d¡g d¢d}| dd|d ¡ t |jt	g d¢ƒ¡ tj
|d |d d	d
 | dd|d ¡ t |jt	g d¢ƒ¡ tj|d |d d	d
 tjtdd | dd|d ¡ W d   ƒ n1 slw   Y  d}tjt|d | dd|d ¡ W d   ƒ n1 sŽw   Y  d|j_| dd|d ¡ |jjdks¨J ‚d S )Né   é   )ÚcÚbÚa)ÚindexÚcolumnsr   Úfoor
   )r   r   r	   r
   F)Zcheck_namesé   Úbarr   )r   r   r   r	   r
   zalready exists©Úmatché   r	   zcannot insert c, already existsZ	some_nameZbaz)r   ÚnpÚrandomÚrandnZarangeÚinsertÚtmZassert_index_equalr   r   Zassert_series_equalZassert_almost_equalÚpytestÚraisesÚ
ValueErrorÚname©ÚselfÚdfÚmsg© r    ú[/app/.heroku/python/lib/python3.10/site-packages/pandas/tests/frame/indexing/test_insert.pyÚtest_insert   s&   ÿÿÿzTestDataFrameInsert.test_insertc                 C   s¼   t dddgiƒ}|ji d}| ddddg¡ |ji d}t|ƒ t ddgddggddgd}t ||¡ | dd	d
dg¡ |ji d}t|ƒ t g d¢g d¢gg d¢d}t ||¡ d S )Nr	   çš™™™™™ñ?çš™™™™™@©r   r   r
   r   r   r   çÍÌÌÌÌÌô?çffffff@)r&   r   r#   )r'   r   r$   )r   r
   r	   )r   Úrenamer   Ústrr   Úassert_frame_equal)r   r   ÚresultÚexpectedr    r    r!   Útest_insert_column_bug_4032,   s   z/TestDataFrameInsert.test_insert_column_bug_4032c                 C   sz   t ƒ }|jddg d¢dd |jddg d¢dd |jddg d¢dd t g d¢g d	¢g d
¢gg d¢d}t ||¡ d S )Nr   ÚA)ÚgÚhÚiT)Zallow_duplicates)ÚdÚeÚf)r
   r	   r   )r
   r2   r/   )r	   r3   r0   )r   r4   r1   )r.   r.   r.   r%   )r   r   r   r*   )r   r   Úexpr    r    r!   Útest_insert_with_columns_dups?   s   ÿz1TestDataFrameInsert.test_insert_with_columns_dupsc                 C   sì   t tj dd¡ƒ}|d }|rd }nt}t |¡ tdƒD ]}|d | ||d < qW d   ƒ n1 s5w   Y  |rYd|jd< |jd |d d ksNJ ‚|jd dksWJ ‚d S d|j	d< |jd |d d kskJ ‚|jd dkstJ ‚d S )Né   r   r   éd   r   éc   )r   r   )
r   r   r   r   r   r   Úassert_produces_warningÚrangeZilocÚvalues)r   Zusing_array_managerZusing_copy_on_writer   ZserZexpected_warningÚnr    r    r!   Útest_insert_item_cacheJ   s"   ÿÿ

z*TestDataFrameInsert.test_insert_item_cachec                 C   s\   t tjjdddddd}t d ¡ t g d¢¡|d< W d   ƒ d S 1 s'w   Y  d S )	Nr   r8   )r   r8   )ÚsizeZInt64)Zdtype)r   r   r   r
   )r   r   r   Úrandintr   r:   Úarray)r   r   r    r    r!   Útest_insert_EA_no_warninga   s   "ÿz-TestDataFrameInsert.test_insert_EA_no_warningc                 C   s\   t ddgddgdœƒ}d}tjt|d | dd|¡ W d   ƒ d S 1 s'w   Y  d S )	Nr   r   r   r7   )Zcol1Zcol2z5Expected a 1D array, got an array with shape \(2, 2\)r   Znewcol)r   r   r   r   r   r   r    r    r!   Útest_insert_frameh   s
   "ÿz%TestDataFrameInsert.test_insert_frameN)	Ú__name__Ú
__module__Ú__qualname__r"   r-   r6   r>   rB   rC   r    r    r    r!   r      s    r   )Ú__doc__Únumpyr   r   Zpandas.errorsr   Zpandasr   r   Zpandas._testingZ_testingr   r   r    r    r    r!   Ú<module>   s    