a
    DBìjÅ;  ã                   @   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   úk/mnt/bigstor/www/usecases/.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   sN   |r"|dgkr"|  tjjdd�¡ ttg ƒt|ƒgƒ}t|ƒ}t ||¡ d S )NrF   z0TDOD(infer_string) object and strings dont match)Úreason)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&   rL   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   rM   rN   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   rM   rN   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 s€0    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 �s€0    Y  d S )NrT   Tr+   F)Úignore_orderrV   rU   r.   rW   r   r	   r   rX   )r[   Úsort_categoriesr$   )r   é   é   )r   r	   r   r   r]   r^   rY   )	r   r   r   r   r0   r1   r2   r;   r<   )r   rM   rN   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 �s‚0    Y  d S )Nr   r"   T©r\   r#   )r   r   r   r   r    r!   r$   r   r   rQ   r   ©r   r   r   r   )r   r   r   r   rW   z9Cannot use sort_categories=True with ordered Categoricalsr.   )	r   r   r   r   r;   r<   r0   r1   r2   ©r   rM   rN   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&   rR   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   rQ   r$   r   Fr`   ra   r&   rR   r   r   r   Ú+test_union_categoricals_sort_false_fastpath1  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`   ra   r&   rR   r   r   r   Ú-test_union_categoricals_sort_false_skipresort9  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$   rK   rR   r   r   r   Ú*test_union_categoricals_sort_false_one_nanA  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`   rK   rR   r   r   r   Ú+test_union_categoricals_sort_false_only_nanH  s
    zATestUnionCategoricals.test_union_categoricals_sort_false_only_nanc                 C   s8   t g ƒ}t g ƒ}t||gdd�}t g ƒ}t ||¡ d S rh   r&   rR   r   r   r   Ú(test_union_categoricals_sort_false_emptyO  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   rQ   TrW   r   Fr`   )r   r   r   r   r&   rR   r   r   r   Ú/test_union_categoricals_sort_false_ordered_trueV  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 s¸0    Y  d S )
Nr   r   r   Úcategoryr9   ra   z-all components to combine must be Categoricalr.   r"   )	r   r   r   r   r   r   r0   r1   r2   rb   r   r   r   Útest_union_categorical_unwrap_  s    z3TestUnionCategoricals.test_union_categorical_unwrapN)$Ú__name__Ú
__module__Ú__qualname__r0   rH   ZparametrizeÚlistr;   r<   r=   Z
date_rangeZperiod_ranger   r   r   r   r*   r-   r4   r6   rD   rJ   rO   rP   rS   rZ   r_   rc   rd   re   rf   rg   ri   rj   rk   rm   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   