a
    PfN                     @   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                	   @   sV  e Zd Zejd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d d! Zejdejejgd"d# Zejd$ejed%d%gfejed&d&gfejed&d&gfgd'd( Z d)d* Z!d+d, Z"ejj#d-d.d/d0 Z$d1d2 Z%d3S )4TestSeriesLogicalOpsz4ignore:Downcasting object dtype arrays:FutureWarning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   ]/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/series/test_logical_ops.pytest_bool_operators_with_nas   s    z1TestSeriesLogicalOps.test_bool_operators_with_nasc                 C   sp   t d}tg d|d}tg d|d}tg td}||@ }| }t|| ||B }| }t|| d S )NbcaTFTindexFFFr   )listr   r   Z
sort_indexr   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 g ddd}t|| |tj|tjB }t g d	d
d}t|| d S )N   int64r   r         int8r   r)   r   r)   )r)   r)   r   r   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_dtype2   s     zDTestSeriesLogicalOps.test_logical_operators_int_dtype_with_int_dtypec                 C   sV   t tddd}|d@ }t dgd }t|| |d@ }t g d}t|| d S )Nr&   r'   r   r   r)   r+   )r   r-   r   r   )r   r.   r$   r   r   r   r   0test_logical_operators_int_dtype_with_int_scalarJ   s    zETestSeriesLogicalOps.test_logical_operators_int_dtype_with_int_scalarc              	   C   sx  t tddd}d}d}tjt|d |tj@  W d    n1 sF0    Y  tjt|d |d@  W d    n1 s|0    Y  d}tjt|dJ tjt	|d |g d	@  W d    n1 s0    Y  W d    n1 s0    Y  tjt|d" |t
g d	@  W d    n1 s*0    Y  tjt|d  |t g d
@  W d    n1 sj0    Y  d S )Nr&   r'   r   LLogical ops \(and, or, xor\) between Pandas objects and dtype-less sequences7Cannot perform.+with a dtyped.+array and scalar of typematchQ	@z unsupported operand type.+for &:)皙?r&   r6   r   )r7   r&   gQ	r   )r   r-   pytestraises	TypeErrorr   r   r   assert_produces_warningFutureWarningarray)r   r.   warn_msgmsgr   r   r   +test_logical_operators_int_dtype_with_floatV   s     (&H2z@TestSeriesLogicalOps.test_logical_operators_int_dtype_with_floatc              	   C   s   t dgd dd}d}d}tjt|d |d@  W d    n1 sF0    Y  tjtd	dJ tjt|d |g d
@  W d    n1 s0    Y  W d    n1 s0    Y  d S )Nr)   r&   r*   r   r2   z=Cannot perform 'and_' with a dtyped.+array and scalar of typer4   azunsupported operand.+for &)rA   bcd)r   r8   r9   r:   r   r;   r<   )r   r/   r>   r?   r   r   r   )test_logical_operators_int_dtype_with_strm   s    &z>TestSeriesLogicalOps.test_logical_operators_int_dtype_with_strc                 C   s   t tddd}t dgd }|d@ }t|| d}tjt|d |dg@ }W d    n1 sd0    Y  t|| tjt|d |d@ }W d    n1 s0    Y  t|| |dA }t g d}t|| d S )	Nr&   r'   r   Fr2   r4   )F)FTTT)r   r-   r   r   r;   r<   )r   r.   r   r   r>   r   r   r   *test_logical_operators_int_dtype_with_bool|   s    (&z?TestSeriesLogicalOps.test_logical_operators_int_dtype_with_boolc                 C   s   t tddd}|t dtjddg@ }t dgd }t|| t ddtjdg}|rdd l}tj|j	j
d	d
 ||@  W d    q1 s0    Y  n6tjtdd
 ||@  W d    n1 s0    Y  d S )Nr&   r'   r   FrA   rB   rD   r   has no kernelr4   zunsupported.* 'int' and 'str')r   r-   r   r   r   r   pyarrowr8   r9   libArrowNotImplementedErrorr:   )r   using_infer_stringr.   r   r   Zs_abNdpar   r   r   ,test_logical_operators_int_dtype_with_object   s    (zATestSeriesLogicalOps.test_logical_operators_int_dtype_with_objectc                 C   s\   t d}tg d|d}tg d|d}|d@ }|}t|| |d@ }|}t|| d S )Nr   r   r   r    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   s  t g d}ddd dtjg}d}t g d}tjt|d ||@ }W d    n1 sX0    Y  t|| |t|@ }t|| |t|@ }t|| |t |@ }t|| t g d}tjt|d ||B }W d    n1 s0    Y  t|| |t|B }t|| |t|B }t|| |t |B }t|| t g d}tjt|d ||A }W d    n1 s0    Y  t|| |t|A }t|| |t|A }t|| |t |A }t|| d S )	N)TTTFTTFr2   )TFFFFr4   )TTTTT)FTTTT)	r   r   r   r   r;   r<   r   r=   r   )r   leftrightr?   r   r   r   r   r   (test_logical_ops_bool_dtype_with_ndarray   sD    &&(z=TestSeriesLogicalOps.test_logical_ops_bool_dtype_with_ndarrayc           	      C   s  t d}tg d|d}tg d|d}tg d|d}ttddd}tdgd	 g d
d}tt ||@ }W d    n1 s0    Y  t|| tdgd	 g d
d}tt ||@ }W d    n1 s0    Y  t|| tdgt d}tt ||@ }W d    n1 s*0    Y  |t d}t|| tt ||B }W d    n1 sx0    Y  |t d}t|| d S )Nr   r   r   TFFr&   r'   r   F   )r   r)   r   r   rA   rB   rC   r)   rB   abc)r!   r   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 g d}d}tjt|d  |tddd@  W d    n1 sD0    Y  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< d}tj	t
|d |t|@ }W d    n1 s0    Y  t|| d S )N)	r   r   r&         rS   r(   r   r
   r3   r4     r)   r   r   r&   rV   rW   rS   r(   r   Tr   Fr2   )r   r8   r9   r:   r   r   r   r   r   r;   r<   r!   r   )r   sr?   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&   rV   rW   rS   r(   r   rX   r)   AF)r   columns)	r   r   r   r   r   r-   r!   r   assert_frame_equal)r   rY   rD   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 g dtg d tg dt  fddttD } }t|| t fddttD td}}t|| d S )NTTFFTFTFr)   r   r)   r   c                    s   g | ]}|  | qS r   r   .0n)idx1r_   r   r   r   
<listcomp>-      zDTestSeriesLogicalOps.test_logical_ops_with_index.<locals>.<listcomp>c                    s   g | ]}|  | qS r   r   rc   )idx2r_   r   r   r   rg   2  rh   r   )r   r   r-   lenr   r   bool)r   r_   r   r   r   )rf   ri   r_   r   r   test_logical_ops_with_index&  s    "
&
z0TestSeriesLogicalOps.test_logical_ops_with_indexc                 C   s`   t g d}tg dtd}tg d}t g d}||A }t|| ||A }t|| d S )Nr`   ra   r   rb   )FTTF)r   r   rk   r   r   )r   r   rf   ri   r   r   r   r   r   +test_reversed_xor_with_index_returns_series7  s    z@TestSeriesLogicalOps.test_reversed_xor_with_index_returns_seriesc                 C   st   t g d}tg d}tg d}t ||j|j}|||}t|| ||t |}|||}t|| d S )Nr`   ra   rb   )r   r   valuesr   r   )r   r_   r   rf   ri   r   r   r   r   r   2test_reversed_logical_op_with_index_returns_seriesD  s    	

zGTestSeriesLogicalOps.test_reversed_logical_op_with_index_returns_serieszop, expectedFTc                 C   s2   t ddg}tddg}|||}t|| d S )NTF)r   r   r   r   )r   r_   r   r   idxr   r   r   r   test_reverse_ops_with_indexY  s    
z0TestSeriesLogicalOps.test_reverse_ops_with_indexc              
   C   s  t g dtd}t g dtd}t g dtd}||@ }t|| t g dtd}||B }t|| t g dtd}||A }t|| t g dtd}t g dtd}t g d	td}||@ }t|| t g d
td}||B }t|| t g td}|| @ }t g dtd}t|| || B }t g dtd}t|| tt" |t dgdg@ }W d    n1 s0    Y  t g dtd}t|| tt" |t dgdgB }W d    n1 s0    Y  t g d
td}t|| ttb | t dgdgt tj	|j
t tj	|j
fD ]"}|||B  }t|||  qXW d    n1 s0    Y  t dgfD ]}|rtnd }|r:dd l}	tj|ddP tj|	jjdd |||B  }W d    n1 s0    Y  W d    n1 s.0    Y  n|||B  }t|||  qtd}
t g d}dD ]6}t g d|
d|B }t g d|
d}t|| qrd}tj	dfD ]>}tjt|d ||B  W d    n1 s0    Y  qdD ]6}t g d|
d|B }t g d|
d}t|| qdD ]6}t g d|
d|@ }t g d|
d}t|| q8dD ]6}t g d|
d|@ }t g d|
d}t|| qtd}tj	fD ]>}tjt|d ||@  W d    n1 s0    Y  qd S )Nr   r   )FTFrT   TTFrR   )FTFTabcd)FTFFr`   r   r    r)   z)FFFFZabczr   zOperation between nonr4   rG   )Tr)   r   r   )TTTr3   Zfoo)Fr   )Tr)   )r   r!   r   r   r   copyr;   r<   r   r   r   rH   r8   r9   rI   rJ   r:   )r   rK   rA   rB   r   r   emptyewarnrL   r   tvr?   r   r   r   test_logical_ops_label_basedk  s    224N,z1TestSeriesLogicalOps.test_logical_ops_label_basedc                 C   s`  t g dtddd}t g dtddd}t g dtddd}t||@ | t||@ | t g d	tddd}t||B | t g d
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 g dtddd}t g dtddd}t g dtddd}t||@ | t||@ | t g d	tddd}t||B | t g dtddd}t||B | t| | @ |  t| | @ |  t| | B |  t| | B |  d S )Nr   ABCxr   namerr   ZABD)TFFFZABCD)TTTFr`   Tr   )TTTTra   )	r   r!   r   r   r]   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_compatz-Will pass once #52839 deprecation is enforced)reasonc                 C   sr   t g dg ddd}t g dg ddd}t||}t g dg ddd}t|| ||A }t|| d S )N)r)   r   r   )r
         rA   r~   )r
         )r   r
   r   )   r(      )r   r   Zbitwise_xorr   r   )r   Zser1ser2r   r   r   r   r   'test_int_dtype_different_index_not_bool
  s    z<TestSeriesLogicalOps.test_int_dtype_different_index_not_boolc                 C   s   t d tddg}tddgdd}||k}td|jd}t|| ||k}td|jd}t|| t jtd	d
 ||k W d    n1 s0    Y  d S )NrH   FTrA   rB   zstring[pyarrow_numpy]r   r   zInvalid comparisonr4   )r8   Zimportorskipr   r   r   r   r9   r:   )r   r   r   r   r   r   r   r   !test_pyarrow_numpy_string_invalid  s    
z6TestSeriesLogicalOps.test_pyarrow_numpy_string_invalidN)&__name__
__module____qualname__r8   markfilterwarningsZparametrizeoperatorand_or_xorr   r%   r0   r1   r@   rE   rF   rM   rN   rQ   rU   rZ   r^   rl   rm   r   Zrand_Zror_ro   r   Zrxorrq   r{   r   Zxfailr   r   r   r   r   r   r      sL   
+$



r-
r   )r   r   numpyr   r8   Zpandasr   r   r   r   Zpandas._testingZ_testingr   Zpandas.corer   r   r   r   r   r   <module>   s   