o
    hQ                     @   sz   d dl m Z  d dlZd dlZd dlZd dlmZ d dlmZm	Z	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)using_string_dtype)
ArrowDtype	DataFrameIndexSeriesStringDtypebdate_range)opsc                	   @   sh  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 ejj!e" d)d*d+d, Z#d-d. Z$ejj!d/d*d0d1 Z%d2d3 Z&d4S )5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
   )periodsdtype   r   	      F)	r   r	   objectnpnanisnafillnatmassert_series_equal)selfr   sermaskfilledresultexpected r!   [/var/www/html/pos/venv/lib/python3.10/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   
sort_indexr   r   )r   r'   s_tfts_fff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   r3   r   r3   )r3   r3   r   r   int32)r   ranger   r   astyper   int16r6   )r   s_0123s_3333s_4444r.   r    s_1111r!   r!   r"   /test_logical_operators_int_dtype_with_int_dtype6   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 )Nr0   r1   r   r   r3   r5   )r   r7   r   r   )r   r:   r.   r    r!   r!   r"   0test_logical_operators_int_dtype_with_int_scalarN   s   zETestSeriesLogicalOps.test_logical_operators_int_dtype_with_int_scalarc              	   C   sv  t tddd}d}d}tjt|d |tj@  W d    n1 s#w   Y  tjt|d |d@  W d    n1 s>w   Y  d}tjt|d% tjt	|d |g d	@  W d    n1 sew   Y  W d    n1 stw   Y  tjt|d |t
g d	@  W d    n1 sw   Y  tjt|d |t g d
@  W d    d S 1 sw   Y  d S )Nr0   r1   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 &:)皙?r0   rD   r   )rE   r0   gQ	r   )r   r7   pytestraises	TypeErrorr   r   r   assert_produces_warningFutureWarningarray)r   r:   warn_msgmsgr!   r!   r"   +test_logical_operators_int_dtype_with_floatZ   s.   
"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 s#w   Y  tjtd	d. tjt|d |g d
@  W d    n1 sHw   Y  W d    d S W d    d S 1 s`w   Y  d S )Nr3   r0   r4   r   r@   z=Cannot perform 'and_' with a dtyped.+array and scalar of typerB   azunsupported operand.+for &)rO   bcd)r   rF   rG   rH   r   rI   rJ   )r   r=   rL   rM   r!   r!   r"   )test_logical_operators_int_dtype_with_strq   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 s2w   Y  t|| tjt|d |d@ }W d    n1 sSw   Y  t|| |dA }t g d}t|| d S )	Nr0   r1   r   Fr@   rB   )F)FTTT)r   r7   r   r   rI   rJ   )r   r:   r    r   rL   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}tjtdd	 ||@  W d    d S 1 s@w   Y  d S )
Nr0   r1   r   FrO   rP   rR   z3unsupported.* 'int' and 'str'|'rand_' not supportedrB   )	r   r7   r   r   r   r   rF   rG   rH   )r   r:   r   r    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g d|d}tg d|d}|d@ }|}t|| |d@ }|}t|| d S )Nr$   r%   r&   r(   r   r3   )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 s,w   Y  t|| |t|@ }t|| |t|@ }t|| |t |@ }t|| t g d}tjt|d ||B }W d    n1 sxw   Y  t|| |t|B }t|| |t|B }t|| |t |B }t|| t g d}tjt|d ||A }W d    n1 sw   Y  t|| |t|A }t|| |t|A }t|| |t |A }t|| d S )	N)TTTFTTFr@   )TFFFFrB   )TTTTT)FTTTT)	r   r   r   r   rI   rJ   r   rK   r   )r   leftrightrM   r    r   r!   r!   r"   (test_logical_ops_bool_dtype_with_ndarray   sJ   


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 sCw   Y  t|| tdgd	 g d
d}tt ||@ }W d    n1 smw   Y  t|| tdgt d}tt ||@ }W d    n1 sw   Y  |t d}t|| tt ||B }W d    n1 sw   Y  |t d}t|| d S )Nr$   r%   r&   TFFr0   r1   r   F   )r   r3   r   r   rO   rP   rQ   r3   rP   abc)r)   r   r7   r   rI   rJ   r   reindex)	r   r'   r+   s_tffr:   r    r   s_a0b1c0r.   r!   r!   r"   <test_logical_operators_int_dtype_with_bool_dtype_and_reindex   s4   



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 s"w   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 shw   Y  t|| d S )N)	r   r   r0         r\   r2   r   r   rA   rB     r3   r   r   r0   rb   rc   r\   r2   r   Tr&   Fr@   )r   rF   rG   rH   r   r   r   r'   r   rI   rJ   r)   r   )r   srM   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   r0   rb   rc   r\   r2   r   rd   r3   AF)r'   columns)	r   r   r   r   r   r7   r)   r   assert_frame_equal)r   re   rR   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r3   r   r3   r   c                       g | ]}|  | qS r!   r!   .0n)idx1rk   r   r!   r"   
<listcomp>-      zDTestSeriesLogicalOps.test_logical_ops_with_index.<locals>.<listcomp>c                    ro   r!   r!   rp   )idx2rk   r   r!   r"   rt   2  ru   r   )r   r   r7   lenr   r   bool)r   rk   r    r   r!   )rs   rv   rk   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 )Nrl   rm   r   rn   )FTTF)r   r   rx   r   r   )r   r   rs   rv   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 )Nrl   rm   rn   )r   r   valuesr   r   )r   rk   r   rs   rv   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   rk   r    r   idxr   r!   r!   r"   test_reverse_ops_with_indexY  s   
z0TestSeriesLogicalOps.test_reverse_ops_with_indexzTODO(infer_string))reasonc              	   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 sw   Y  t g dtd}t|| tt |t dgdgB }W d    n1 sw   Y  t g d
td}t|| tt1 | t dgdgt tj	|j
t tj	|j
fD ]}|||B  }t|||  q*W d    n	1 sGw   Y  t dgfD ]3}|rvtjtdd |||B  }W d    n	1 spw   Y  n|||B  }t|||  qRtd}t g d}	dD ]}
t g d|d|
B }t g d|d}t|| qd}tj	dfD ]}
tjt|d |	|
B  W d    n	1 sw   Y  qdD ]}
t g d|d|
B }t g d|d}t|| qdD ]}
t g d|d|
@ }t g d|d}t|| qdD ]}
t g d|d|
@ }t g d|d}t|| qd}tj	fD ]}
tjt|d |	|
@  W d    n	1 sNw   Y  q5d S )Nr%   r$   )FTFr]   TTFr[   )FTFTabcd)FTFFrl   r   r(   r3   z)FFFFabczz0not supported for dtype|unsupported operand typerB   )Tr3   r   r&   )TTTrA   foo)Fr   )Tr3   )r   r)   r   r   r   copyrI   rJ   r   r   r'   rF   rG   rH   )r   using_infer_stringrO   rP   r    r   emptyer'   tvrM   r!   r!   r"   test_logical_ops_label_basedk  s   


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'   namer   ABD)TFFFABCD)TTTFrl   Tr&   )TTTTrm   )	r   r)   r   r   ri   to_framer   r   r   )r   s1s2expexp_or1exp_ors3s4r!   r!   r"   test_logical_ops_df_compat  s6     z/TestSeriesLogicalOps.test_logical_ops_df_compatz-Will pass once #52839 deprecation is enforcedc                 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)r3   r   r   )r         rO   r   )r         )r   r   r   )   r2      )r   r   bitwise_xorr   r   )r   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ttjdd}||k}td|jd}t|| ||k}td|jd}t|| t j	t
d	d
 ||k W d    n1 sOw   Y  |d}||k}t||d ||k}	t|	|d t j	t
d	d
 ||k W d    n1 sw   Y  |t| }
|
|k}t||d |
|k}t||d t j	t
d	d
 ||
k W d    d S 1 sw   Y  d S )NpyarrowFTrO   rP   )na_valuer   r&   zInvalid comparisonrB   zstring[pyarrow]zbool[pyarrow])rF   importorskipr   r   r   r   r'   r   r   rG   rH   r8   r   string)r   par   r   r   expected_eqexpected_neser3
result3_eq
result3_neser4
result4_eq
result4_ner!   r!   r"   !test_pyarrow_numpy_string_invalid  s8   




"z6TestSeriesLogicalOps.test_pyarrow_numpy_string_invalidN)'__name__
__module____qualname__rF   markfilterwarningsparametrizeoperatorand_or_xorr#   r/   r>   r?   rN   rS   rT   rV   rW   rZ   ra   rf   rj   ry   rz   r
   rand_ror_r|   r   rxorr~   xfailr   r   r   r   r   r!   r!   r!   r"   r      sP    
+$




p-
r   )r   r   numpyr   rF   pandas._configr   pandasr   r   r   r   r   r	   pandas._testing_testingr   pandas.corer
   r   r!   r!   r!   r"   <module>   s     