U
    +ify8                     @   sV   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 G dd dZdS )    N)union_categoricals)CategoricalCategoricalIndexSeriesc                   @   s\   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d Z
dd Zdd ZdS )TestUnionCategoricalsc                 C   s^  t dt dt dfdddgdddgddddddgfdd	dgdd
dgdd	ddd
dgfddtjdgdtjdgddtjddtjdgftddtddtddftjddddtjddddtjddddftddtddtddfg}|D ]L\}}}tttfD ]6}t	|t||t|g}t|}t
|| qqtdddg}tdddg}	t	||	g}tddddddgddddddgd}t
|| tdd	dgdd}tdd	dgdd}	t	||	g}tdd	ddd	dgdd}t
|| tdd	dg}tdddg}	d}
tjt|
d t	||	g W 5 Q R X d}
tjt|
d t	g  W 5 Q R X d S )NabcZabdZabcabdr               g333333?g333333@bacz
2014-01-01z
2014-01-05z
2014-01-06z
2014-01-07z
US/Central)tzxyz
categoriesTorderedz$dtype of categories must be the samematchzNo Categoricals to union)listnpnanpdZ
date_rangeZperiod_ranger   r   r   r   tmassert_categorical_equalpytestraises	TypeError
ValueError)selfdatar   r   combinedboxresultexpectedss2msg r,   _/home/mars/bis/venv/lib/python3.8/site-packages/pandas/tests/reshape/test_union_categoricals.pytest_union_categorical   s\      






 z,TestUnionCategoricals.test_union_categoricalc                 C   s  t tddtjgtddtjgg}tddtjddtjg}t|| t tddgtddtjgg}tddddtjg}t|| tdtdtjg}tjtdtdg}t t|t|g}t|| tdtdtdgd	}t|| t ttj	tjtjgt
d
tdgg}ttjtjdg}t|| t ttjtjgttjtjgg}ttjtjtjtjg}t|| d S )Nr   r	   r
   ABz
2011-01-01z
2011-03-01z
2011-02-01r   ZdtypeX)r   r   r   r   r   r   r   	TimestampZNaTarrayobject)r#   resexpZval1Zval2r,   r,   r-   test_union_categoricals_nanL   sB    z1TestUnionCategoricals.test_union_categoricals_nanc                 C   sX   t tg tg g}tg }t|| t tg tdgg}tdg}t|| d S )N1)r   r   r   r   )r#   r6   r7   r,   r,   r-   test_union_categoricals_emptyx   s    
z3TestUnionCategoricals.test_union_categoricals_emptyc              	   C   s   t ddddgddddgd}t dddtjgddddgd}t||g}t dddddddtjgddddgd}t|| t dddgdddgd}t dddgdddgd}t||g}t ddddddgdddgd}t|| d S )	Nr   r	   r
   r   r   r   r   r   )r   r   r   r   r   r   )r#   c1c2r6   r7   r,   r,   r-   $test_union_categorical_same_category   s    &z:TestUnionCategoricals.test_union_categorical_same_categoryc                 C   sj   t dddgdddgd}t dddgdddgd}t||g}t ddddddgdddgd}t|| d S )Nr   r   r   r   )r   r   r   r   r#   r;   r<   r'   r(   r,   r,   r-   6test_union_categorical_same_categories_different_order   s     zLTestUnionCategoricals.test_union_categorical_same_categories_different_orderc              	   C   s8  t dddgdd}t dddgdd}d}tjt|d t||g W 5 Q R X t||g}t ddddddgdd}t|| t dddtjgdd}t ddgdddgdd	}t||g}t dddtjddgdd}t|| t dddgdd}t dddgdddgdd	}d
}tjt|d t||g W 5 Q R X d S )Nr   r	   r
   Tr   F$Categorical.ordered must be the samer   r   r   >to union ordered Categoricals, all categories must be the same)	r   r   r    r!   r   r   r   r   r   )r#   r;   r<   r+   r6   r7   r,   r,   r-   test_union_categoricals_ordered   s$    z5TestUnionCategoricals.test_union_categoricals_orderedc              	   C   s  t dddgdd}t dddgdd}t||gdd}t ddddddg}t|| d}tjt|d	 t||gdd W 5 Q R X t||gdd}t ddddddg}t|| t||gdd}t ddddddgdddgdd
}t|| t dddtjgdd}t ddgdddgdd
}t||gdd}t dddtjddg}t|| t dddgdd}t dddgdddgdd
}t||gdd}t ddddddg}t|| t||gddd}t ddddddgdddgd}t|| t dddgdd}t dddgdd}t||gdd}t ddddddg}t|| d}tjt|d	 t||gdd W 5 Q R X tjt|d	 t||g W 5 Q R X d S )Nr   r	   r
   Tr   F)ignore_orderr@   r   rA   )rD   sort_categoriesr   r         rB   )	r   r   r   r   r   r    r!   r   r   )r#   r;   r<   r6   r7   r+   r'   r(   r,   r,   r-   $test_union_categoricals_ignore_order   sJ     z:TestUnionCategoricals.test_union_categoricals_ignore_orderc              	   C   s  t dddg}t dddg}t||gdd}t ddddddgddddddgd	}t|| t ddgdddgd	}t ddgdddgd	}t||gdd}t ddddgdddgd	}t|| t ddgdddgd	}t ddgdddgd	}t||gdd}t ddddgdddgd	}t|| t ddgdddgd	}t ddgdddgd	}t||gdd}t ddddgdddgd	}t|| t dtjg}t tjdg}t||gdd}t dtjtjdgddgd	}t|| t tjg}t tjg}t||gdd}t tjtjg}t|| t g }t g }t||gdd}t g }t|| t ddgdddgdd
}t ddgdddgdd
}d}tjt|d t||gdd W 5 Q R X d S )Nr   r   r   r   r   r   TrE   r   rA   z9Cannot use sort_categories=True with ordered Categoricalsr   )	r   r   r   r   r   r   r   r    r!   r#   r;   r<   r'   r(   r+   r,   r,   r-   test_union_categoricals_sort   sV     z2TestUnionCategoricals.test_union_categoricals_sortc                 C   sX  t dddg}t dddg}t||gdd}t ddddddgddddddgd	}t|| t ddgdddgd	}t ddgdddgd	}t||gdd}t ddddgdddgd	}t|| t ddgdddgd	}t ddgdddgd	}t||gdd}t ddddgdddgd	}t|| t dtjg}t tjdg}t||gdd}t dtjtjdgddgd	}t|| t tjg}t tjg}t||gdd}t tjtjg}t|| t g }t g }t||gdd}t g }t|| t ddgdddgd
d}t ddgdddgd
d}t||gdd}t ddddgdddgd
d}t|| d S )Nr   r   r   r   r   r   FrI   r   TrA   )r   r   r   r   r   r   r>   r,   r,   r-   "test_union_categoricals_sort_false  sT     
  z8TestUnionCategoricals.test_union_categoricals_sort_falsec              	   C   s   t ddg}tddgdd}t||g}t ddddg}t|| t|}t||g}t|| t|}t||g}t|| d}tjt|d t|dddgg W 5 Q R X d S )Nr   r   r   categoryr1   z-all components to combine must be Categoricalr   )	r   r   r   r   r   r   r   r    r!   rJ   r,   r,   r-   test_union_categorical_unwrapP  s    z3TestUnionCategoricals.test_union_categorical_unwrapN)__name__
__module____qualname__r.   r8   r:   r=   r?   rC   rH   rK   rL   rN   r,   r,   r,   r-   r      s   <,

462r   )numpyr   r   Zpandas.core.dtypes.concatr   Zpandasr   r   r   r   Zpandas._testingZ_testingr   r   r,   r,   r,   r-   <module>   s   