U
    sVc[E                     @   sf   d dl m Z  d dlZd dlZd dlZd dlmZmZmZm	Z	 d dl
mZ d dlmZ G dd dZdS )    )datetimeN)	DataFrameIndexSeriesbdate_range)opsc                
   @   sd  e Zd Zejdejejej	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dd Zdd Zdd Zdd Zejdejejej	gdd Zejdd d! Zejdejejejjd"ed#d$ejejejjd%ed#d$gd&d' Z ejd(eje!d)d*gfeje!d)d*gfej"e!g e#d+fgd,d- Z$d.d/ Z%d0d1 Z&d2S )3TestSeriesLogicalOpsbool_opc                 C   s   t tdddtd}tj|d d d< | }||d }|||d k ||d k}|||d k ||d k}d	||< t|| d S )
Nz1/1/2000
   )ZperiodsZdtype   r   	      F)	r   r   objectnpnanZisnaZfillnatmassert_series_equal)selfr	   sermaskZfilledresultexpected r   H/tmp/pip-unpacked-wheel-xj8nt62q/pandas/tests/series/test_logical_ops.pytest_bool_operators_with_nas   s    z1TestSeriesLogicalOps.test_bool_operators_with_nasc                 C   sl   t d}tdddg|d}tdddg|d}tg td}||@ }|}t|| ||B }|}t|| d S )NbcaTFindexr   )listr   r   r   r   )r   r   s_tfts_fffZs_emptyresr   r   r   r   ,test_logical_operators_bool_dtype_with_empty!   s    zATestSeriesLogicalOps.test_logical_operators_bool_dtype_with_emptyc                 C   s   t tddd}t dgd }t dgd }||@ }t tddd}t|| ||B }t tdddd}t|| t dgd dd}||@ }t ddddgdd}t|| |tj|tjB }t ddddgd	d}t|| d S )
N   int64r   r         int8r   int32)r   ranger   r   Zastyper   Zint16r)   )r   s_0123Zs_3333Zs_4444r"   r   s_1111r   r   r   /test_logical_operators_int_dtype_with_int_dtype1   s     zDTestSeriesLogicalOps.test_logical_operators_int_dtype_with_int_dtypec                 C   sZ   t tddd}|d@ }t dgd }t|| |d@ }t ddddg}t|| d S )Nr$   r%   r   r   r'   r   r*   r   r   )r   r+   r"   r   r   r   r   0test_logical_operators_int_dtype_with_int_scalarI   s    zETestSeriesLogicalOps.test_logical_operators_int_dtype_with_int_scalarc              	   C   s   t tddd}d}tjt|d |tj@  W 5 Q R X tjt|d |d@  W 5 Q R X d}tjt|d |dddd	g@  W 5 Q R X tjt|d |tdddd	g@  W 5 Q R X tjt|d |t ddd
d	g@  W 5 Q R X d S )Nr$   r%   r   7Cannot perform.+with a dtyped.+array and scalar of typematchgQ	@z unsupported operand type.+for &:g?r   gQ	)r   r*   pytestraises	TypeErrorr   NaNarray)r   r+   msgr   r   r   +test_logical_operators_int_dtype_with_floatU   s     z@TestSeriesLogicalOps.test_logical_operators_int_dtype_with_floatc              	   C   sf   t dgd dd}d}tjt|d |d@  W 5 Q R X tjtdd |dd	d
dg@  W 5 Q R X d S )Nr'   r$   r(   r   z=Cannot perform 'and_' with a dtyped.+array and scalar of typer1   azunsupported operand.+for &bcd)r   r3   r4   r5   )r   r,   r8   r   r   r   )test_logical_operators_int_dtype_with_strf   s    z>TestSeriesLogicalOps.test_logical_operators_int_dtype_with_strc                 C   s   t tddd}t dgd }|d@ }t|| |dg@ }t|| |d@ }t|| |dA }t ddddg}t|| d S )Nr$   r%   r   F)FTr.   )r   r+   r   r   r   r   r   *test_logical_operators_int_dtype_with_booln   s    
z?TestSeriesLogicalOps.test_logical_operators_int_dtype_with_boolc              	   C   sx   t tddd}|t dtjddg@ }t dgd }t|| t ddtjdg}tjtdd	 ||@  W 5 Q R X d S )
Nr$   r%   r   Fr:   r;   r=   zunsupported.* 'int' and 'str'r1   )	r   r*   r   r6   r   r   r3   r4   r5   )r   r+   r   r   Zs_abNdr   r   r   ,test_logical_operators_int_dtype_with_object   s    zATestSeriesLogicalOps.test_logical_operators_int_dtype_with_objectc                 C   s`   t d}tdddg|d}tdddg|d}|d@ }|}t|| |d@ }|}t|| d S )Nr   TFr   r   r'   )r   r   r   r   )r   r   r    r!   r"   r   r   r   r   *test_logical_operators_bool_dtype_with_int   s    z?TestSeriesLogicalOps.test_logical_operators_bool_dtype_with_intc                 C   sv  t dddddg}ddd dtjg}t dddddg}||@ }t|| |t|@ }t|| |t|@ }t|| |t |@ }t|| t dddddg}||B }t|| |t|B }t|| |t|B }t|| |t |B }t|| t dddddg}||A }t|| |t|A }t|| |t|A }t|| |t |A }t|| d S )NTF)r   r   r   r   r   r7   r   )r   leftrightr   r   r   r   r   (test_logical_ops_bool_dtype_with_ndarray   s:    z=TestSeriesLogicalOps.test_logical_ops_bool_dtype_with_ndarrayc           	   	   C   s  t d}tdddg|d}tdddg|d}tdddg|d}ttddd}tdgd d	d
dddddgd}||@ }t|| tdgd d	d
dddddgd}||@ }t|| td
gt d}||@ }|t d}t|| ||B }|t d}t|| d S )Nr   TFr   r$   r%   r      r   r'   r   r   r:   r;   r<   abc)r   r   r*   r   r   Zreindex)	r   r   r    Zs_tffr+   r   r   Zs_a0b1c0r"   r   r   r   <test_logical_operators_int_dtype_with_bool_dtype_and_reindex   s$      zQTestSeriesLogicalOps.test_logical_operators_int_dtype_with_bool_dtype_and_reindexc                 C   s   t ddddddddd	g	}d
}tjt|d |tddd@  W 5 Q R X t ddddddddtdddg	}tj|d d d< t d|jd}d|d d d< |t|@ }t	
|| d S )Nr   r   r$         rE   r&   r   r
   r0   r1     r'   Tr   F)r   r3   r4   r5   r   r   r   r   r   r   r   )r   sr8   r   r   r   r   r   "test_scalar_na_logical_ops_corners   s    "z7TestSeriesLogicalOps.test_scalar_na_logical_ops_cornersc                 C   s   t ddddddddtd	d
d
g	}tj|d d d< td|i}tdtddgttd d}||@ }t|| ||@ }t|| d S )Nr   r   r$   rH   rI   rE   r&   r   rJ   r'   AF)r   columns)	r   r   r   r   r   r*   r   r   assert_frame_equal)r   rK   r=   r   r   r   r   r   )test_scalar_na_logical_ops_corners_aligns   s    " z>TestSeriesLogicalOps.test_scalar_na_logical_ops_corners_alignsopc                    s   t ddddgtddddg tddddgt  fddttD } }t|| t fddttD td}}t|| d S )	NTFr'   r   c                    s   g | ]}|  | qS r   r   .0n)idx1rQ   r   r   r   
<listcomp>  s     zDTestSeriesLogicalOps.test_logical_ops_with_index.<locals>.<listcomp>c                    s   g | ]}|  | qS r   r   rR   )idx2rQ   r   r   r   rV     s     r   )r   r   r*   lenr   r   bool)r   rQ   r   r   r   )rU   rW   rQ   r   r   test_logical_ops_with_index   s    "
&
z0TestSeriesLogicalOps.test_logical_ops_with_indexz3ignore:passing object-dtype arraylike:FutureWarningc              	   C   s   t ddddg}tddddgtd}tddddg}d}t||}tjt|d ||A }W 5 Q R X t|| t||}tjt|d ||A }W 5 Q R X t|| d S )NTFr   r'   r   operating as a set operationr1   )r   r   r   symmetric_differencer   assert_produces_warningFutureWarningassert_index_equal)r   r   rU   rW   r8   r   r   r   r   r   *test_reversed_xor_with_index_returns_index  s    
 z?TestSeriesLogicalOps.test_reversed_xor_with_index_returns_indexz1GH#22092 Index __and__ returns Index intersection)reasonr4   )Zmarksz)GH#22092 Index __or__ returns Index unionc              	   C   s   t ddddg}tddddg}tddddg}d}t ||j|j}tjt|d |||}W 5 Q R X t|| t ||j|j}tjt|d |||}W 5 Q R X t|| d S )NTFr'   r   r[   r1   )r   r   valuesr   r]   r^   r   )r   rQ   r   rU   rW   r8   r   r   r   r   r   2test_reversed_logical_op_with_index_returns_series   s    zGTestSeriesLogicalOps.test_reversed_logical_op_with_index_returns_serieszop, expectedFTr   c              	   C   sP   t ddg}tddg}d}tjt|d |||}W 5 Q R X t|| d S )NTFr[   r1   )r   r   r   r]   r^   r_   )r   rQ   r   r   idxr8   r   r   r   r   test_reverse_ops_with_indexE  s    z0TestSeriesLogicalOps.test_reverse_ops_with_indexc              
   C   s  t dddgtd}t dddgtd}t dddgtd}||@ }t|| t dddgtd}||B }t|| t dddgtd}||A }t|| t dddgtd}t ddddgtd}t ddddgtd}||@ }t|| t ddddgtd}||B }t|| t g td}|| @ }t dddgtd}t|| || B }t dddgtd}t|| |t dgdg@ }t ddddgtd	}t|| |t dgdgB }t ddddgtd	}t|| | t dgdgt tj|jt tj|jfD ]"}|||B  }t|||  qt dgfD ]"}|||B  }t|||  qHtd}t dddg}d
D ]:}	t dddg|d|	B }t dddg|d}t|| qd}
tjdfD ](}	t	j
t|
d ||	B  W 5 Q R X qdD ]:}	t dddg|d|	B }t dddg|d}t|| qdD ]:}	t dddg|d|	@ }t dddg|d}t|| q>dD ]:}	t dddg|d|	@ }t dddg|d}t|| q~d}
tjfD ](}	t	j
t|
d ||	@  W 5 Q R X qd S )NTFr   rF   Zabcdr   r'   zZabcz)Tr'   r   r   r0   Zfoor1   )Fr   )Tr'   )r   r   r   r   r   copyr   r   r   r3   r4   r5   )r   r:   r;   r   r   emptyer   tvr8   r   r   r   test_logical_ops_label_basedY  s    z1TestSeriesLogicalOps.test_logical_ops_label_basedc                 C   s  t dddgtddd}t dddgtddd}t ddddgtddd}t||@ | t||@ | t ddddgtddd}t||B | t ddddgtddd}t||B | t| | @ |  t| | @ |  tdddtjtjgitdd}t| | B |  t| | B |  t dddgtddd}t ddddgtddd}t ddddgtddd}t||@ | t||@ | t ddddgtddd}t||B | t ddddgtddd}t||B | t| | @ |  t| | @ |  t| | B |  t| | B |  d S )	NTFABCx)r   nameZABDABCDr   )	r   r   r   r   rO   Zto_framer   r   r   )r   s1s2expZexp_or1Zexp_orZs3Zs4r   r   r   test_logical_ops_df_compat  s6     z/TestSeriesLogicalOps.test_logical_ops_df_compatN)'__name__
__module____qualname__r3   markZparametrizeoperatorand_or_xorr   r#   r-   r/   r9   r>   r?   r@   rA   rD   rG   rL   rP   rZ   filterwarningsr`   paramr   Zrand_ZxfailAssertionErrorZror_rc   r   ZrxorrY   re   rl   rt   r   r   r   r   r      s^   
# 




er   )r   ry   Znumpyr   r3   Zpandasr   r   r   r   Zpandas._testingZ_testingr   Zpandas.corer   r   r   r   r   r   <module>   s   