a
    Pf(                     @   sR   d dl Zd dlZd dlZd dlmZmZmZmZm	Z	 d dl
mZ G dd dZdS )    N)	DataFrame
RangeIndexSeriesconcat
date_rangec                   @   sH  e Zd Zdd Zdd Zejdddgejdg g d	gd
d Zejde	j
e	je	jfe	j
e	je	jfde	j
e	jfde	je	jfde	j
e	jfde	je	jfddgdd Zejdg ddd Zejdg dejdg ddd Zdd Zdd Zd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 )/TestEmptyConcatc           
      C   s<  t tjddtdd}|d d  }d|d< |dd }||||dd  g}t|d|d	}|jg d
d}|d 	|st
nd|d< d|jdddf< t|| t dtditddddd}t  }t||gdd}	t|	| t||gdd}	t|	| t||g}	t|	| t||g}	t|	| d S )N   )
      abcdcolumns   barfoor   )axissort)abcdr   zstring[pyarrow_numpy]r
   Ai'  Z20130101s)Zperiodsfreqindex   r   )r   nprandomZdefault_rngZstandard_normallistcopyr   Zreindexastypeobjectloctmassert_frame_equalranger   )
selfr   using_infer_stringdfZdfcopyemptyframesZ	concattedexpectedresult r/   _/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/reshape/concat/test_empty.pytest_handle_empty_objects   s4    
z)TestEmptyConcat.test_handle_empty_objectsc                 C   s<  t g ddd}t ddd}t||gdd}tg dtjtjtjgd	td
d}t|| t g ddd}t ddd}d}tjt	|d  t||gdd}W d    n1 s0    Y  t g d}t
|| t g ddd}t d dd}t||gdd}tg dtjtjtjgdddgtd
d}t|| d S )Nr   r      x)nameyfloat64)r5   dtyper   r   )r4   r6   r3   r   zDThe behavior of array concatenation with empty entries is deprecated)matchr   )r4   r   )r   r   )r   r   r   r   nanr   r%   r&   Zassert_produces_warningFutureWarningassert_series_equal)r(   s1s2resexpmsgr/   r/   r0   test_concat_empty_series4   s0    .z(TestEmptyConcat.test_concat_empty_seriestzNUTCvaluesr2   c                 C   sx   t g ddj|}|rd ntj}t ||d}tt tjgt| ddj||d}t	||gdd}t
|| d S )NM8[ns]r8   )r   r   r   r   )r   dtZtz_localizer   r7   r   pdZNaTlenr   r%   r&   )r(   rC   rE   firstr8   secondr-   r.   r/   r/   r0   !test_concat_empty_series_timelikeS   s    z1TestEmptyConcat.test_concat_empty_series_timelikezleft,right,expectedm8[ns]rF   )categoryrO   rO   )rO   r#   r#   c                 C   s*   t t|dt|dg}|j|ks&J d S NrG   )r   r   r8   )r(   leftrightr-   r.   r/   r/   r0   test_concat_empty_series_dtypese   s    z/TestEmptyConcat.test_concat_empty_series_dtypesr8   )r7   int8uint8boolrN   rF   c                 C   sR   t |}tt|dg}|j|ks(J tt|dt|dg}|j|ksNJ d S rP   )r   r8   r   r   )r(   r8   r.   r/   r/   r0   0test_concat_empty_series_dtypes_match_roundtripsz   s
    
z@TestEmptyConcat.test_concat_empty_series_dtypes_match_roundtrips)r7   rT   rU   rN   rF   dtype2c                    sz   ||krt d dd dd   fdd}t|}t|}|||}tt|dt|dgj}|j|ksvJ d S )	Nz%same dtype is not applicable for testc                 S   s`   | j |j h}t|h d s4| j dks0|j dkr4dS t|ddh s\| j dksX|j dkr\dS d S )N>   ir   urY   rZ   r   kindrJ   r8   rX   Ztypsr/   r/   r0   int_result_type   s    zSTestEmptyConcat.test_concat_empty_series_dtypes_roundtrips.<locals>.int_result_typec                 S   s8   | j |j h}t|h d s4| j dks0|j dkr4dS d S )N>   rY   frZ   r_   r[   r]   r/   r/   r0   float_result_type   s    zUTestEmptyConcat.test_concat_empty_series_dtypes_roundtrips.<locals>.float_result_typec                    s0    | |}|d ur|S | |}|d ur,|S dS )NOr/   )r8   rX   r.   r`   r^   r/   r0   get_result_type   s    

zSTestEmptyConcat.test_concat_empty_series_dtypes_roundtrips.<locals>.get_result_typerG   )pytestskipr   r8   r   r   r\   )r(   r8   rX   rc   r-   r.   r/   rb   r0   *test_concat_empty_series_dtypes_roundtrips   s    
	


z:TestEmptyConcat.test_concat_empty_series_dtypes_roundtripsc                 C   s4   t tddttjdttjdgjtjks0J d S )NrF   rG   )r   r   r   bool_int64r8   object_r(   r/   r/   r0   &test_concat_empty_series_dtypes_triple   s    z6TestEmptyConcat.test_concat_empty_series_dtypes_triplec                 C   s.   t ttg ddtddgjdks*J d S )NrO   rG   r7   )r   r   r   arrayr8   rj   r/   r/   r0   2test_concat_empty_series_dtype_category_with_array   s    zBTestEmptyConcat.test_concat_empty_series_dtype_category_with_arrayc                 C   s   t tdddtdddg}|jdks2J t tdddtddg}ttj}|j|ksjJ t tdddtddg}td}|j|ksJ d S )Nr7   rG   ZSparsezSparse[float64]r#   )r   r   r"   r8   rI   ZSparseDtyper   r7   )r(   r.   r-   r/   r/   r0   &test_concat_empty_series_dtypes_sparse   s     
z6TestEmptyConcat.test_concat_empty_series_dtypes_sparsec                 C   sP   t g dtjg dd}t |jd}t||gdd}|t}t|| d S )N)r   r   r   r2   )RowZEmptyColZ	NumberColr   r   r   )	r   r   r:   r   r   r"   r#   r%   r&   )r(   Zdf_1Zdf_2r.   r-   r/   r/   r0   !test_concat_empty_df_object_dtype   s
    
z1TestEmptyConcat.test_concat_empty_df_object_dtypec                 C   s   t tdd}|d tj|d< |d tj|d< |d tj|d< t||g}|d jtjksjJ |d jtjks~J |d jtjksJ t||tjg}|d jtj	ksJ |d jtjksJ |d jtjksJ d S )Nabcr   r   r   r   )
r   r    r"   r   rg   int32r7   r   r8   ri   )r(   r*   r.   r/   r/   r0   "test_concat_empty_dataframe_dtypes   s    z2TestEmptyConcat.test_concat_empty_dataframe_dtypesc                 C   sv   t  }t dddgiddgdd}t dg itddd}t||gddd}t|| t||gdd	d}t|| d S )
Nr   r   r   r   rh   )r   r8   inner)r   joinouter)r   r   r   r%   r&   )r(   df_emptyZdf_aZdf_expectedr.   r/   r/   r0   test_concat_inner_join_empty   s    z,TestEmptyConcat.test_concat_inner_join_emptyc                 C   s\   t dd gdd ggddgd}t dd gdd ggddgd}t||g}|j}t|j| d S )Nr   r   r   r   )datar   r3   r
   )r   r   Zdtypesr%   r<   )r(   df1df2r.   r-   r/   r/   r0   test_empty_dtype_coerce   s
    z'TestEmptyConcat.test_empty_dtype_coercec                 C   s   t ddgd}t ddgd}t|||g}t g dd}t|| t ddgd}t dgd}t||g}t ddgd}t|| d S )Nr   r   r   r   r   r   r   )r   r   r%   r&   )r(   rz   r{   r.   r-   Zdf3Zdf4r/   r/   r0   test_concat_empty_dataframe
  s    z+TestEmptyConcat.test_concat_empty_dataframec                 C   sx   t g dg dd}t dg di}t|d d |d d g}|d jtjksVJ |sl|d jtjkstndstJ d S )Nr2   r}   )r   r   r   r   r   string)r   r   r8   r   rh   ri   )r(   r)   rz   r{   r.   r/   r/   r0   ,test_concat_empty_dataframe_different_dtypes  s
    z<TestEmptyConcat.test_concat_empty_dataframe_different_dtypesc                 C   s\   t dtjg t di}t dtjg dt di}| }t||g}t|| dS )z<48510 `concat` to an empty EA should maintain type EA dtype.r   rG   r2   N)r   rI   rl   Z
Int64Dtyper!   r   r%   r&   )r(   rw   Zdf_newr-   r.   r/   r/   r0   test_concat_to_empty_ea!  s
    z'TestEmptyConcat.test_concat_to_empty_ea)__name__
__module____qualname__r1   rB   rd   markZparametrizerM   r   rg   rr   ri   Zfloat32rh   rS   rW   rf   rk   rm   rn   rp   rs   rx   r|   r~   r   r   r/   r/   r/   r0   r      sL   $

	(		r   )numpyr   rd   ZpandasrI   r   r   r   r   r   Zpandas._testingZ_testingr%   r   r/   r/   r/   r0   <module>   s
   