o
    ŀg                     @   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   ^/var/www/html/myenv/lib/python3.10/site-packages/pandas/tests/series/methods/test_case_when.pydf   s   r   c                 C   sP   d}|d7 }t jt|d | d jdd W d   dS 1 s!w   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   caselistN)pytestraises	TypeError	case_whenr   msgr   r   r   %test_case_when_caselist_is_not_a_list   s
   "r   c                 C   sN   d}|d7 }t jt|d | d g  W d   dS 1 s w   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   sh   d}|d7 }t jt|d | d | d dd| jdfg W d   dS 1 s-w   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   sZ   d}t jt|d | d | d dddgfg W d   dS 1 s&w   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   Int64)dtyper   Float64N)	r   r$   r%   r   r    r   pd_arrayr&   r'   r(   r   r   r   >test_case_when_multiple_conditions_replacement_extension_dtype\   s   
*r3   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   &r4   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   )periods)r7   r
   )size)ABCD)indexcolumnsr   r:   )r>   namer   N)r$   randomdefault_rngr   r   standard_normalr   r>   r   r:   r    r;   maskwherer&   r'   )rngdatesr   r)   r*   r   r   r   test_case_when_non_range_indexx   s   &(rH   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 Nr   rJ   r   r   r   rK          c                 S   s   | dkS rI   r   rJ   r   r   r   rK      rL   c                 S      | S rN   r   rJ   r   r   r   rK          r   r   c                 S   rM   rN   r   xr   r   r   rK      rO   c                 S   rP   rN   r   rR   r   r   r   rK      rQ   N)r$   linspacer   r   	piecewiser&   r'   )rS   serr)   r*   r   r   r   test_case_when_callable   s   &rW   )numpyr$   r   pandasr   r   r   r2   r   pandas._testing_testingr&   fixturer   r   r   r!   r"   r+   r,   r.   r3   r4   rH   rW   r   r   r   r   <module>   s"    


		