a
    Pf                     @   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                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )TestDataFrameInsertc                 C   s\  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 s0    Y  d}tjt|d" |dd|d  W d    n1 s"0    Y  d|j	_|dd|d  |j	jdksXJ d S )N   )      r   )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default_rngstandard_normalZarangeinserttmZassert_index_equalr   r   Zassert_series_equalZassert_almost_equalpytestraises
ValueErrornameselfdfmsg r!   `/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/frame/indexing/test_insert.pytest_insert   s&    02zTestDataFrameInsert.test_insertc                 C   s   t dddgi}|ji d}|ddddg |ji d}t ddgddggddgd}t|| |dd	d
dg |ji d}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   r   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|2 tdD ]}|d | ||d < q@W d    n1 sn0    Y  |rd|j	d< |j	d |d d ksJ |j	d dksJ n6d|j
d< |j	d |d d ksJ |j	d dksJ d S )	Nr   )   r   r   d   r   r   c   )r   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    4

z*TestDataFrameInsert.test_insert_item_cachec                 C   s`   t tjdjdddddd}td " tg d|d	< W d    n1 sR0    Y  d S )
Nr   r   r8   )r   r8   )sizeZInt64)Zdtype)r   r   r   r   )r   r   r   r   Zintegersr   r:   arrayr   r   r!   r!   r"   test_insert_EA_no_warninga   s
    z-TestDataFrameInsert.test_insert_EA_no_warningc                 C   sZ   t ddgddgd}d}tjt|d |dd| W d    n1 sL0    Y  d S )	Nr   r   r   r7   )Zcol1Zcol2zJExpected a one-dimensional object, got a DataFrame with 2 columns instead.r   Znewcol)r   r   r   r   r   r   r!   r!   r"   test_insert_framej   s
    z%TestDataFrameInsert.test_insert_framec                 C   sF   t dddgi}|tddd t|t ddgddgd d S )Nr   r   r   r   r
   )r
   r   )r   r   r   Zint64r   r*   rA   r!   r!   r"   test_insert_int64_loct   s    z)TestDataFrameInsert.test_insert_int64_locN)
__name__
__module____qualname__r#   r-   r6   r>   rB   rC   rD   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   