U
    sVcz0                     @   s  d dl Zd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ dd Zdd Zdd	 Zd
d Zejddddejejgdddddgfdejgddgfdejgddgfejejgddgfejejejgedddgfgdd Zejdddgddgddgddgejdddedgeddgeddgejddigg	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 ejjd0ddgd1d2gd3d4d5 Z!d6d7 Z"dS )8    N)BooleanArray)coerce_to_arrayc               	   C   sR  t jddddgdd} t jddddgdd}t| |}tjdddd gdd}t|| tjtdd t| 	 | W 5 Q R X tjtdd t| |	  W 5 Q R X tjtdd t| 
t| W 5 Q R X tjtdd t| d  W 5 Q R X tjtd	d t| d
d| W 5 Q R X tjtd	d t| |d
d W 5 Q R X d S )NTFbooldtypebooleanz$values should be boolean numpy arraymatchz"mask should be boolean numpy arrayz"values.shape must match mask.shape   )nparrayr   pdtmassert_extension_array_equalpytestraises	TypeErrortolistZastypeint
ValueErrorreshapevaluesmaskresultexpected r   Q/tmp/pip-unpacked-wheel-xj8nt62q/pandas/tests/arrays/boolean/test_construction.pytest_boolean_array_constructor
   s"    
r   c                  C   s   t jddddgdd} t jddddgdd}t| |}|j| ksDt|j|ksRtt| |dd}|j| k	snt|j|k	s|td S )NTFr   r   )copy)r   r   r   _dataAssertionError_mask)r   r   r   r   r   r   #test_boolean_array_constructor_copy%   s    
r$   c                  C   s  t tdddgtdddg} tjdddgdd}t||  tjtdddgdd}t||  tjtjdddgtddd}t||  t tdddgtdddg} tjddd gdd}t||  tjtjddd gtddd}t||  d S )NTFr   r   r   r   r   r   r   r   objectr   r   r   r   r   test_to_boolean_array2   s$      r(   c                  C   sp   t tdddgtdddg} tjd d d gdd}t||  tjtjd d d gtddd}t||  d S )NTr   r   r%   r'   r   r   r   test_to_boolean_array_all_noneI   s
    "r)   za, bTFr   c                 C   s,   t j| dd}t j|dd}t|| d S )Nr   r   r   r   r   r   )abr   r   r   r   r   (test_to_boolean_array_missing_indicatorsR   s    r-   r   Zfoobar12r
            ?g       @Z20130101)Zperiodsr+   c              	   C   s0   d}t jt|d tj| dd W 5 Q R X d S )NzNeed to pass bool-like valuer   r   r   )r   r   r   r   r   )r   msgr   r   r   test_to_boolean_array_errorb   s    r4   c                  C   s   t jtddddgdd} t jddddgdd}t| | t jtdddd gdd} t jdddd gdd}t| | d S Nr
   r   r   r   TF)r   r   r   r   r   r   r   r   r   r   (test_to_boolean_array_from_integer_arrayx   s    r7   c                  C   s   t jtddddgdd} t jddddgdd}t| | t jtdddtjgdd} t jdddd gdd}t| | d S )Nr2   g        r   r   TF)r   r   r   r   r   nanr6   r   r   r   &test_to_boolean_array_from_float_array   s    r9   c                  C   st   t jddddgdd} t jddddgdd}t| | t jdddd gdd} t jdddd gdd}t| | d S r5   r*   r6   r   r   r   "test_to_boolean_array_integer_like   s    r:   c               	   C   s  t jddddgdd} t jddddgdd}tt| |d }t| |}t|| |j| ks`t|j|ksnttt| |dd }t| |}t|| |j| k	st|j|k	stddd dg} t jddddgdd}tt| |d }tt ddddgt ddddg}t|| ttt j| t	d|d }t|| tt| |
 d }t|| t jddddgdd} t jddddgdd}t| dd tjtd	d
 t| dd|d W 5 Q R X tjtd	d
 t| |ddd W 5 Q R X d S )NTFr   r   r   )r   r    r
   r   z&values.shape and mask.shape must matchr   )r   r   r   r   r   r   r!   r"   r#   r&   r   r   r   r   r   r   r   r   r   test_coerce_to_array   s>    

 r<   c               	   C   s   t jddddgdd} t jddddgdd}t| |}tt| }t|| |j|jks^t|j|jksnttt|ddi}t|| |j|jk	st|j|jk	stt	j
tdd t||d W 5 Q R X d S )	NTFr   r   r    z'cannot pass mask for BooleanArray inputr   r;   )r   r   r   r   r   r   r!   r"   r#   r   r   r   )r   r   arrr   r   r   r   'test_coerce_to_array_from_boolean_array   s    
r>   c               	   C   s   t jddd gdd} t| }tjddt jgdd}t|| t jdddgdd} t| }tjdddgdd}t|| tj| dd}tjdddgdd}t|| t jddd gdd} d}tjt|d tj| dd W 5 Q R X d S )	NTFr   r   r&   r   zqcannot convert to 'bool'-dtype NumPy array with missing values. Specify an appropriate 'na_value' for this dtype.r   )	r   r   r   NAr   assert_numpy_array_equalr   r   r   )r=   r   r   r3   r   r   r   test_coerce_to_numpy_array   s     

rA   c                  C   sf   t tjddddddtjgtd} t tdd	ddd	d	d	gtd	d	d	d	d	d	dg}t| | d S )
NTrueFalser/   z1.00z0.0r   TF)r   _from_sequence_of_stringsr   r   r8   r&   r   r   r6   r   r   r   "test_to_boolean_array_from_strings   s    rF   c                	   C   s*   t jtdd tdg W 5 Q R X d S )Nzcannot be castr   Zdonkey)r   r   r   r   rE   r   r   r   r   1test_to_boolean_array_from_strings_invalid_string   s    rG   boxZseriesr   )idsc              	   C   sb  | r
t jnt j}|dddgdd}| }tjdddgdd}t|| |ddd gdd}| }tjddt jgdd}t|| |ddd gdd}|jdd}tjddt jgtj dd}t|| |dddgdd}|jdd}tjdddgdd}t|| |ddd gdd}t	j
td	d
 |jdd}W 5 Q R X |ddd gdd}|jtd d}tjddd gdd}t|| |jtdd}tjdddgdd}t|| |jddd}tjdddgdd}t|| |jdtjd}tjddtjgdd}t|| t	j
tdd
 |jdd W 5 Q R X t	j
tdd
 |jdd W 5 Q R X d S )NTFr   r   r&   strZU5r   zcannot convert to 'bool'-dtyper   )r   Zna_valueZint64ir
   r   Zfloat64zcannot convert to 'int64'-dtypez!cannot convert to 'float64'-dtype)r   ZSeriesr   to_numpyr   r   r@   r?   ZENDIANr   r   r   r&   r   r8   )rH   conr=   r   r   r   r   r   test_to_numpy  sJ    rM   c                  C   s   t jdddgdd} | jtd}d|d< t| t jdddgdd t jdddgdd} | jtdd}d|d< t| t jdddgdd d S )NTFr   r   r   )r   r    )r   r   rK   r   r   r   )r=   r   r   r   r   test_to_numpy_copy:  s     rN   )#Znumpyr   r   Zpandasr   Zpandas._testingZ_testingr   Zpandas.arraysr   Zpandas.core.arrays.booleanr   r   r$   r(   r)   markZparametrizer8   r?   r   floatr-   Z
date_ranger4   r7   r9   r:   r<   r>   rA   rF   rG   rM   rN   r   r   r   r   <module>   sX   	



*
5