a
    Pfg;                     @   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ejdedededfg dg dg dfg dg d	g d
fddejdgdejdgddejddejdgfe	
dde	
dde	
ddfe	j
dddde	j
dddde	j
ddddfe	dde	dde	ddfgejdeeegdd Zdd Zdd Zdd Zdd Zdd  Zejd!g d"ggd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Z d;d< Z!d=d> Z"d?d@ Z#dAS )BTestUnionCategoricalsza, b, combinedabcZabdZabcabd)r         r	         )r   r   r	   r	   r   r   r   333333?r	   )r	   333333@r   )r   r   r	   r	   r   r   bacz
2014-01-01z
2014-01-05z
2014-01-06z
2014-01-07z
US/Central)tzboxc                 C   s4   t |t||t|g}t|}t|| d S )N)r   r   tmassert_categorical_equal)selfr   r   combinedr   resultexpected r   e/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/reshape/test_union_categoricals.pytest_union_categorical   s    z,TestUnionCategoricals.test_union_categoricalc                 C   sH   t g d}t g d}t||g}t g dg dd}t|| d S )Nxyzr   r   r   r   r    r!   r   r   r   
categoriesr   r   r   r   r   ss2r   r   r   r   r   )test_union_categorical_ordered_appearance3   s    z?TestUnionCategoricals.test_union_categorical_ordered_appearancec                 C   sL   t g ddd}t g ddd}t||g}t g ddd}t|| d S )Nr   Tordered)r   r   r	   r   r   r	   r&   r'   r   r   r   #test_union_categorical_ordered_true=   s
    z9TestUnionCategoricals.test_union_categorical_ordered_truec                 C   sZ   t g d}t g d}d}tjt|d t||g W d    n1 sL0    Y  d S )Nr   r
   z$dtype of categories must be the samematch)r   pytestraises	TypeErrorr   )r   r(   r)   msgr   r   r   "test_union_categorical_match_typesD   s
    z8TestUnionCategoricals.test_union_categorical_match_typesc                 C   s>   d}t jt|d tg  W d    n1 s00    Y  d S )NzNo Categoricals to unionr.   )r0   r1   
ValueErrorr   )r   r3   r   r   r   test_union_categorical_emptyL   s    z2TestUnionCategoricals.test_union_categorical_emptyc                 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tjdgt
d
d	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   npnanr   r   pd	TimestampZNaTarrayobjectIndex)r   resexpZval1Zval2r   r   r   test_union_categoricals_nanQ   sB    z1TestUnionCategoricals.test_union_categoricals_nanval1c                 C   sL   |r |dgkr | tjd ttg t|g}t|}t|| d S )NrF   zobject and strings dont match)Zapplymarkerr0   markZxfailr   r   r   r   )r   rE   requestZusing_infer_stringrB   rC   r   r   r   test_union_categoricals_empty}   s
    z3TestUnionCategoricals.test_union_categoricals_emptyc              	   C   sl   t g dg dd}t dddtjgg dd}t||g}t dddddddtjgg dd}t|| d S )N)r   r	   r   r   r$   r   r	   r   r   r   r;   r<   r   r   r   r   c1c2rB   rC   r   r   r   $test_union_categorical_same_category   s
    "z:TestUnionCategoricals.test_union_categorical_same_categoryc                 C   sX   t g dg dd}t g dg dd}t||g}t g dg dd}t|| d S )N)r!   r!   r!   r   r$   )r   r   r   )r!   r!   r!   r   r   r   r&   rK   r   r   r   (test_union_categorical_same_category_str   s
    z>TestUnionCategoricals.test_union_categorical_same_category_strc                 C   sX   t g dg dd}t g dg dd}t||g}t g dg dd}t|| d S )Nr"   r$   r   r   r   )r   r   r   r   r   r   r&   r   rL   rM   r   r   r   r   r   6test_union_categorical_same_categories_different_order   s    zLTestUnionCategoricals.test_union_categorical_same_categories_different_orderc                 C   sN  t g ddd}t g ddd}d}tjt|d t||g W d    n1 sT0    Y  t||g}t g ddd}t|| t dd	d
tjgdd}t d
d	gg ddd}t||g}t dd	d
tjd
d	gdd}t|| t g ddd}t g dg ddd}d}tjt|d t||g W d    n1 s@0    Y  d S )Nr   r	   r   Tr+   F$Categorical.ordered must be the samer.   r   r	   r   r   r	   r   r   r	   r   r%   r,   r   r	   r   >to union ordered Categoricals, all categories must be the same)	r   r0   r1   r2   r   r   r   r;   r<   )r   rL   rM   r3   rB   rC   r   r   r   test_union_categoricals_ordered   s$    *z5TestUnionCategoricals.test_union_categoricals_orderedc                 C   s  t g ddd}t g ddd}t||gdd}t g d}t|| d}tjt|d  t||gdd W d    n1 s0    Y  t||gdd}t g d}t|| t||gdd}t g dg ddd	}t|| t d
ddtjgdd}t ddgg ddd	}t||gdd}t d
ddtjddg}t|| t g ddd}t g dg ddd	}t||gdd}t g d}t|| t||gddd}t g dg dd}t|| t g ddd}t g ddd}t||gdd}t g d}t|| d}tjt|d  t||gdd W d    n1 sD0    Y  tjt|d t||g W d    n1 s0    Y  d S )NrS   Tr+   F)ignore_orderrU   rT   r.   rV   r   r	   r   rW   )rZ   sort_categoriesr$   )r         )r   r	   r   r   r\   r]   rX   )	r   r   r   r   r0   r1   r2   r;   r<   )r   rL   rM   rB   rC   r3   r   r   r   r   r   $test_union_categoricals_ignore_order   sJ    .0z:TestUnionCategoricals.test_union_categoricals_ignore_orderc                 C   s  t g d}t g d}t||gdd}t g dg dd}t|| t dd	gg d
d}t d	dgg d
d}t||gdd}t g dg dd}t|| t dd	gg dd}t d	dgg dd}t||gdd}t g dg dd}t|| t dd	gg dd}t d	dgg dd}t||gdd}t g dg d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g d
dd}t ddgg d
dd}d}tjt|d  t||gdd W d    n1 s0    Y  d S )Nr   r"   Tr[   r#   )r   r   r   r   r    r!   r$   r   r   rP   r   r   r   r   r   )r   r   r   r   rV   z9Cannot use sort_categories=True with ordered Categoricalsr.   )	r   r   r   r   r;   r<   r0   r1   r2   r   rL   rM   r   r   r3   r   r   r   test_union_categoricals_sort   sT    z2TestUnionCategoricals.test_union_categoricals_sortc                 C   sL   t g d}t g d}t||gdd}t g dg dd}t|| d S )Nr   r"   Fr_   r#   r$   r&   rQ   r   r   r   "test_union_categoricals_sort_false#  s    z8TestUnionCategoricals.test_union_categoricals_sort_falsec                 C   s\   t ddgg dd}t ddgg dd}t||gdd}t g dg dd}t|| d S )	Nr   r   rP   r$   r   Fr_   r`   r&   rQ   r   r   r   +test_union_categoricals_sort_false_fastpath-  s
    zATestUnionCategoricals.test_union_categoricals_sort_false_fastpathc                 C   s\   t ddgg dd}t ddgg dd}t||gdd}t g dg dd}t|| d S )	Nr   r   r"   r$   r   Fr_   r`   r&   rQ   r   r   r   -test_union_categoricals_sort_false_skipresort5  s
    zCTestUnionCategoricals.test_union_categoricals_sort_false_skipresortc                 C   sX   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|| d S )Nr   r   Fr_   r$   rJ   rQ   r   r   r   *test_union_categoricals_sort_false_one_nan=  s
    z@TestUnionCategoricals.test_union_categoricals_sort_false_one_nanc                 C   sH   t tjg}t tjg}t||gdd}t tjtjg}t|| d S NFr_   rJ   rQ   r   r   r   +test_union_categoricals_sort_false_only_nanD  s
    zATestUnionCategoricals.test_union_categoricals_sort_false_only_nanc                 C   s8   t g }t g }t||gdd}t g }t|| d S rg   r&   rQ   r   r   r   (test_union_categoricals_sort_false_emptyK  s
    z>TestUnionCategoricals.test_union_categoricals_sort_false_emptyc                 C   sb   t ddgg ddd}t ddgg ddd}t||gdd}t g d	g ddd}t|| d S )
Nr   r   rP   TrV   r   Fr_   )r   r   r   r   r&   rQ   r   r   r   /test_union_categoricals_sort_false_ordered_trueR  s    zETestUnionCategoricals.test_union_categoricals_sort_false_ordered_truec                 C   s   t ddg}tddgdd}t||g}t g d}t|| t|}t||g}t|| t|}t||g}t|| d}tjt|d  t|g d	g W d    n1 s0    Y  d S )
Nr   r   r   categoryr9   r`   z-all components to combine must be Categoricalr.   r"   )	r   r   r   r   r   r   r0   r1   r2   ra   r   r   r   test_union_categorical_unwrap[  s    z3TestUnionCategoricals.test_union_categorical_unwrapN)$__name__
__module____qualname__r0   rG   Zparametrizelistr;   r<   r=   Z
date_rangeZperiod_ranger   r   r   r   r*   r-   r4   r6   rD   rI   rN   rO   rR   rY   r^   rb   rc   rd   re   rf   rh   ri   rj   rl   r   r   r   r   r      s\   







,

46
	r   )numpyr;   r0   Zpandas.core.dtypes.concatr   Zpandasr=   r   r   r   Zpandas._testingZ_testingr   r   r   r   r   r   <module>   s   