a
    DBìj  ã                   @   sž   d dl Zd dlZd dlmZmZmZmZ d dl	m
Z ej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d„ ZdS )é    N)Ú	DataFrameÚSeriesÚarrayÚ
date_rangec                   C   s   t g d¢g d¢dœƒS )z$
    base dataframe for testing
    ©é   é   é   )é   é   é   )ÚaÚb)r   © r   r   úi/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pandas/tests/series/methods/test_case_when.pyÚdf   s    r   c                 C   sN   d}|d7 }t jt|d��  | d jdd� W d  ƒ n1 s@0    Y  dS )z5
    Raise ValueError if caselist is not a list.
    z(The caselist argument should be a list; zinstead got.+©Úmatchr   r   ©ZcaselistN)ÚpytestÚraisesÚ	TypeErrorÚ	case_when©r   Úmsgr   r   r   Ú%test_case_when_caselist_is_not_a_list   s    r   c                 C   sL   d}|d7 }t jt|d�� | d  g ¡ W d  ƒ n1 s>0    Y  dS )z6
    Raise ValueError if no caselist is provided.
    z(provide at least one boolean condition, z!with a corresponding replacement.r   r   N)r   r   Ú
ValueErrorr   r   r   r   r   Útest_case_when_no_caselist   s    r   c                 C   sf   d}|d7 }t jt|d��8 | d  | d  d¡d| j d¡fg¡ W d  ƒ n1 sX0    Y  dS )z4
    Raise ValueError if no of caselist is odd.
    zArgument 0 must have length 2; z2a condition and replacement; instead got length 3.r   r   r   N)r   r   r   r   Úeqr   Úgtr   r   r   r   Útest_case_when_odd_caselist)   s    r    c                 C   sX   d}t jt|d��2 | d  | d  d¡ddgfg¡ W d  ƒ n1 sJ0    Y  dS )z-
    Raise Error from within Series.mask
    z,Failed to apply condition0 and replacement0.r   r   r   r   N)r   r   r   r   r   r   r   r   r   Ú$test_case_when_raise_error_from_mask4   s    r!   c                 C   sJ   t tjtjtjgƒ | j d¡dfg¡}t dtjtjgƒ}t ||¡ dS )z,
    Test output on a single condition.
    r   N©r   ÚnpÚnanr   r   r   ÚtmÚassert_series_equal©r   ÚresultÚexpectedr   r   r   Útest_case_when_single_condition=   s    (r*   c                 C   sV   t tjtjtjgƒ | j d¡dft g d¢ƒdfg¡}t ddtjgƒ}t ||¡ dS )zB
    Test output when booleans are derived from a computation
    r   )FTFr   Nr"   r'   r   r   r   Ú"test_case_when_multiple_conditionsF   s
    ÿr+   c                 C   sf   t tjtjtjgƒ g d¢df| d  d¡| d  d¡@ g d¢fg¡}t ddtjgƒ}t ||¡ dS )	z0
    Test output when replacement is a list
    ©TFFr   r   r   r   r   r   N)r   r#   r$   r   r   r   r%   r&   r'   r   r   r   Ú3test_case_when_multiple_conditions_replacement_listQ   s
    .ÿr-   c                 C   sr   t tjtjtjgƒ g d¢df| d  d¡| d  d¡@ tg d¢dd�fg¡}t dd	tjgd
d�}t ||¡ dS )z=
    Test output when replacement has an extension dtype
    r,   r   r   r   r   r   ZInt64)Zdtyper   ZFloat64N)	r   r#   r$   r   r   r   Úpd_arrayr%   r&   r'   r   r   r   Ú>test_case_when_multiple_conditions_replacement_extension_dtype\   s    
*þÿr/   c                 C   sp   t tjtjtjgƒ t g d¢¡df| d  d¡| d  d¡@ t g d¢ƒfg¡}t ddtjgƒ}t ||¡ dS )	z2
    Test output when replacement is a Series
    r,   r   r   r   r   r   r   N)	r   r#   r$   r   r   r   r   r%   r&   r'   r   r   r   Ú5test_case_when_multiple_conditions_replacement_seriesj   s    &þÿr0   c                  C   s’   t jjdd�} tddd�}t| jdd�|g d¢d	�}td
|jdd� |j	 
d¡|jfg¡}|j	 |j	 
d¡|j¡ |j	 
d¡d
¡}t ||¡ dS )z0
    Test output if index is not RangeIndex
    é{   )Úseedz1/1/2000é   )Zperiods)r3   r
   )Úsize)ÚAÚBÚCÚD)ÚindexÚcolumnsr   r5   )r9   Únamer   N)r#   ÚrandomZdefault_rngr   r   Zstandard_normalr   r9   r   r5   r   r6   ÚmaskÚwherer%   r&   )ÚrngÚdatesr   r(   r)   r   r   r   Útest_case_when_non_range_indexx   s    ÿ&(rA   c                  C   sx   t  ddd¡} t| ƒ}|jdd„ dd„ fdd„ dd„ fgd	�}t  | | d
k | d
kgdd„ dd„ g¡}t |t|ƒ¡ dS )z#
    Test output on a callable
    g      Àg      @r   c                 S   s   | dk S ©Nr   r   ©r   r   r   r   Ú<lambda>�   ó    z)test_case_when_callable.<locals>.<lambda>c                 S   s   |  S ©Nr   rC   r   r   r   rD   �   rE   c                 S   s   | dkS rB   r   rC   r   r   r   rD   �   rE   c                 S   s   | S rF   r   rC   r   r   r   rD   �   rE   r   r   c                 S   s   |  S rF   r   ©Úxr   r   r   rD   “   rE   c                 S   s   | S rF   r   rG   r   r   r   rD   “   rE   N)r#   Zlinspacer   r   Z	piecewiser%   r&   )rH   Zserr(   r)   r   r   r   Útest_case_when_callable†   s    þÿ&rI   )Únumpyr#   r   Zpandasr   r   r   r.   r   Zpandas._testingZ_testingr%   Zfixturer   r   r   r    r!   r*   r+   r-   r/   r0   rA   rI   r   r   r   r   Ú<module>   s    


		