
    OhQ                         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      Zy)    )datetimeN)using_string_dtype)
ArrowDtype	DataFrameIndexSeriesStringDtypebdate_range)opsc            
       t   e Zd Zej                  j                  d      ej                  j                  dej                  ej                  ej                  g      d               Zd Zd Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zej                  j                  dej                  ej                  ej                  g      d        Zd Zej                  j                  dej6                  ej8                  g      d        Zej                  j                  dej6                   eddg      fej8                   eddg      fej>                   eddg      fg      d        Z ej                  jC                   e"       d      d        Z#d Z$ej                  jC                  d      d        Z%d Z&y) TestSeriesLogicalOpsz4ignore:Downcasting object dtype arrays:FutureWarningbool_opc                 :   t        t        dd      t              }t        j                  |d d d<   |j                         }|j                  |d         } |||d   k  ||d   kD        } |||d   k  ||d   kD        }d	||<   t        j                  ||       y )
Nz1/1/2000
   )periodsdtype   r   	      F)	r   r
   objectnpnanisnafillnatmassert_series_equal)selfr   sermaskfilledresultexpecteds          l/var/www/html/diagnosisapp-backend/venv/lib/python3.12/site-packages/pandas/tests/series/test_logical_ops.pytest_bool_operators_with_nasz1TestSeriesLogicalOps.test_bool_operators_with_nas   s     [R8G66CaCxxzCF#s1vsSV|46F1I-vq	/AB
vx0    c                 $   t        d      }t        g d|      }t        g d|      }t        g t              }||z  }|j                         }t	        j
                  ||       ||z  }|j                         }t	        j
                  ||       y )NbcaTFTindexFFFr   )listr   r   
sort_indexr   r   )r   r+   s_tfts_fffs_emptyresr#   s          r$   ,test_logical_operators_bool_dtype_with_emptyzATestSeriesLogicalOps.test_logical_operators_bool_dtype_with_empty&   s    U*%8,E:6*go##%
sH-go##%
sH-r&   c                 p   t        t        d      d      }t        dgdz        }t        dgdz        }||z  }t        t        d      d      }t        j                  ||       ||z  }t        t        dd      d      }t        j                  ||       t        dgdz  d      }||z  }t        g dd      }t        j                  ||       |j	                  t
        j                        |j	                  t
        j                        z  }t        g d	d
      }t        j                  ||       y )N   int64r   r         int8r   r8   r   r8   )r8   r8   r   r   int32)r   ranger   r   astyper   int16r;   )r   s_0123s_3333s_4444r2   r#   s_1111s          r$   /test_logical_operators_int_dtype_with_int_dtypezDTestSeriesLogicalOps.test_logical_operators_int_dtype_with_int_dtype6   s     a0aavo%('2
sH-vo%1+W5
sH-av.vo,g6
sH-mmBHH%bhh(??,g6
sH-r&   c                     t        t        d      d      }|dz  }t        dgdz        }t        j                  ||       |dz  }t        g d      }t        j                  ||       y )Nr5   r6   r   r   r8   r:   )r   r<   r   r   )r   r?   r2   r#   s       r$   0test_logical_operators_int_dtype_with_int_scalarzETestSeriesLogicalOps.test_logical_operators_int_dtype_with_int_scalarN   s]    a0qj1#'?
sH-qj,'
sH-r&   c                    t        t        d      d      }d}d}t        j                  t        |      5  |t
        j                  z   d d d        t        j                  t        |      5  |dz   d d d        d}t        j                  t        |      5  t        j                  t        |      5  |g d	z   d d d        d d d        t        j                  t        |      5  |t        j                  g d	      z   d d d        t        j                  t        |      5  |t        g d
      z   d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   nxY w# 1 sw Y   y xY w)Nr5   r6   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 &:)皙?r5   rK   r   )rL   r5   gQ	r   )r   r<   pytestraises	TypeErrorr   r   r   assert_produces_warningFutureWarningarray)r   r?   warn_msgmsgs       r$   +test_logical_operators_int_dtype_with_floatz@TestSeriesLogicalOps.test_logical_operators_int_dtype_with_floatZ   s?   a0# 	
 H]]9C0 	RVVO	]]9C0 	TM	0]]9C0 	+++MJ +**+	+ ]]9C0 	1RXX/00	1]]9C0 	0V.//	0 	0	 		 	+ +	+ 	+	1 	1	0 	0sS   D?-EE#4E<E#'E/%E;?EEE 	E##E,/E8;Fc                 f   t        dgdz  d      }d}d}t        j                  t        |      5  |dz   d d d        t        j                  t        d	      5  t	        j
                  t        |      5  |g d
z   d d d        d d d        y # 1 sw Y   YxY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr8   r5   r9   r   rG   z=Cannot perform 'and_' with a dtyped.+array and scalar of typerI   azunsupported operand.+for &)rW   bcd)r   rM   rN   rO   r   rP   rQ   )r   rB   rS   rT   s       r$   )test_logical_operators_int_dtype_with_strz>TestSeriesLogicalOps.test_logical_operators_int_dtype_with_strq   s    av.# 	
 N]]9C0 	SL	]]9,HI 	.++MJ .--.	. 	.	 	. .	. 	.s/   BB'6B>B'BB$	 B''B0c                    t        t        d      d      }t        dgdz        }|dz  }t        j                  ||       d}t        j                  t
        |      5  |dgz  }d d d        t        j                  ||       t        j                  t
        |      5  |dz  }d d d        t        j                  ||       |dz  }t        g d      }t        j                  ||       y # 1 sw Y   xY w# 1 sw Y   TxY w)	Nr5   r6   r   FrG   rI   )F)FTTT)r   r<   r   r   rP   rQ   )r   r?   r#   r"   rS   s        r$   *test_logical_operators_int_dtype_with_boolz?TestSeriesLogicalOps.test_logical_operators_int_dtype_with_bool   s    a05'A+&%
vx0# 	 ''XF 	&ug%F	&
vx0''XF 	'h&F	'
vx0%34
vx0	& 	&	' 	's   C+C7+C47D c                 ^   t        t        d      d      }|t        dt        j                  ddg      z  }t        dgdz        }t	        j
                  ||       t        ddt        j                  dg      }t        j                  t        d	      5  ||z   d d d        y # 1 sw Y   y xY w)
Nr5   r6   r   FrW   rX   rZ   z3unsupported.* 'int' and 'str'|'rand_' not supportedrI   )	r   r<   r   r   r   r   rM   rN   rO   )r   r?   r"   r#   s_abNds        r$   ,test_logical_operators_int_dtype_with_objectzATestSeriesLogicalOps.test_logical_operators_int_dtype_with_object   s    a0&%!>??5'A+&
vx0c2663/0]]R
 	 VO	 	 	s   B##B,c                     t        d      }t        g d|      }t        g d|      }|dz  }|}t        j                  ||       |dz  }|}t        j                  ||       y )Nr(   r)   r*   r,   r   r8   )r-   r   r   r   )r   r+   r/   r0   r2   r#   s         r$   *test_logical_operators_bool_dtype_with_intz?TestSeriesLogicalOps.test_logical_operators_bool_dtype_with_int   sa    U*%8,E:ai
sH-ai
sH-r&   c                 $   t        g d      }ddd dt        j                  g}d}t        g d      }t        j                  t
        |      5  ||z  }d d d        t        j                  |       |t        j                  |      z  }t        j                  ||       |t        |      z  }t        j                  ||       |t        |      z  }t        j                  ||       t        g d      }t        j                  t
        |      5  ||z  }d d d        t        j                  ||       |t        j                  |      z  }t        j                  ||       |t        |      z  }t        j                  ||       |t        |      z  }t        j                  ||       t        g d      }t        j                  t
        |      5  ||z  }d d d        t        j                  ||       |t        j                  |      z  }t        j                  ||       |t        |      z  }t        j                  ||       |t        |      z  }t        j                  ||       y # 1 sw Y   xY w# 1 sw Y   fxY w# 1 sw Y   xY w)	N)TTTFTTFrG   )TFFFFrI   )TTTTT)FTTTT)	r   r   r   r   rP   rQ   r   rR   r   )r   leftrightrT   r#   r"   s         r$   (test_logical_ops_bool_dtype_with_ndarrayz=TestSeriesLogicalOps.test_logical_ops_bool_dtype_with_ndarray   s"   56udD"&&1# 	
 <=''SA 	"E\F	"
vx0'
vx0e$
vx0u%
vx089''SA 	"E\F	"
vx0'
vx0e$
vx0u%
vx09:''SA 	"E\F	"
vx0'
vx0e$
vx0u%
vx0=	" 	"	" 	"	" 	"s$   I,I9J,I69JJc                    t        d      }t        g d|      }t        g d|      }t        g d|      }t        t        d      d      }t        dgd	z  g d
      }t        j                  t
              5  ||z  }d d d        t        j                  |       t        dgd	z  g d
      }t        j                  t
              5  ||z  }d d d        t        j                  ||       t        dgt        d            }t        j                  t
              5  ||z  }d d d        |j                  t        d            }t        j                  |       t        j                  t
              5  ||z  }d d d        |j                  t        d            }t        j                  ||       y # 1 sw Y   5xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   _xY w)Nr(   r)   r*   TFFr5   r6   r   F   )r   r8   r   r   rW   rX   rY   r8   rX   abc)r-   r   r<   r   rP   rQ   r   reindex)	r   r+   r/   s_tffr?   r#   r"   s_a0b1c0r2   s	            r$   <test_logical_operators_int_dtype_with_bool_dtype_and_reindexzQTestSeriesLogicalOps.test_logical_operators_int_dtype_with_bool_dtype_and_reindex   s    U*%8*%8+59a0 5'A+-HI''6 	$V^F	$
vx0 5'A+-HI''6 	$e^F	$
vx01#tCy)''6 	#("C	#==e-
sH-''6 	#("C	#==e-
sH-+	$ 	$	$ 	$	# 	#
	# 	#s0   ;F4GG5G4F>G
GG"c                    t        g d      }d}t        j                  t        |      5  |t	        ddd      z   d d d        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        j                  t        |      5  |t        |      z  }d d d        t        j                  |       y # 1 sw Y   xY w# 1 sw Y   ,xY w)N)	r   r   r5         ri   r7   r   r   rH   rI     r8   r   r   r5   rp   rq   ri   r7   r   Tr*   FrG   )r   rM   rN   rO   r   r   r   r+   r   rP   rQ   r-   r   )r   srT   r#   r"   s        r$   "test_scalar_na_logical_ops_cornersz7TestSeriesLogicalOps.test_scalar_na_logical_ops_corners  s    /0G]]9C0 	%q!$$	% Aq!Q1aHT1a,@AB#A#$agg.1# 	 ''SA 	!a[F	!
vx0	% 	%	! 	!s   C#5C/#C,/C8c                 N   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            z         }||z  }t        j                  ||       ||z  }t        j                  ||       y )Nr   r   r5   rp   rq   ri   r7   r   rr   r8   AF)r+   columns)	r   r   r   r   r   r<   r-   r   assert_frame_equal)r   rs   rZ   r#   r"   s        r$   )test_scalar_na_logical_ops_corners_alignsz>TestSeriesLogicalOps.test_scalar_na_logical_ops_corners_aligns  s    Aq!Q1aHT1a,@AB#A#sAhU%(SEDqN<RSQ
fh/Q
fh/r&   opc           
         t        g d      }t        g d      }t        g d      }t        t        t        |            D cg c]  } |||   ||          c}      } |||      }t	        j
                  ||       t        t        t        |            D cg c]  } |||   ||          c}t              } |||      }t	        j
                  ||       y c c}w c c}w )NTTFFTFTFr8   r   r8   r   r   )r   r   r<   lenr   r   bool)r   rz   r   idx1idx2nr#   r"   s           r$   test_logical_ops_with_indexz0TestSeriesLogicalOps.test_logical_ops_with_index&  s     /0/0\"c#hH12c!fd1g.HIC
vx0c#hH12c!fd1g.HPTUC
vx0 I
 Is   CC"c                     t        g d      }t        g dt              }t        g d      }t        g d      }||z  }t        j                  ||       ||z  }t        j                  ||       y )Nr|   r}   r   r~   )FTTF)r   r   r   r   r   )r   r   r   r   r#   r"   s         r$   +test_reversed_xor_with_index_returns_seriesz@TestSeriesLogicalOps.test_reversed_xor_with_index_returns_series7  sa    /0/t<\"45
vx0
vx0r&   c                 >   t        g d      }t        g d      }t        g d      }t         ||j                  |j                              } |||      }t        j                  ||        ||t        |            } |||      }t        j                  ||       y )Nr|   r}   r~   )r   r   valuesr   r   )r   rz   r   r   r   r#   r"   s          r$   2test_reversed_logical_op_with_index_returns_serieszGTestSeriesLogicalOps.test_reversed_logical_op_with_index_returns_seriesD  s     /0/0\""T[[#**56C
vx0c6$<(C
vx0r&   zop, expectedFTc                 v    t        ddg      }t        ddg      } |||      }t        j                  ||       y )NTF)r   r   r   r   )r   rz   r#   r   idxr"   s         r$   test_reverse_ops_with_indexz0TestSeriesLogicalOps.test_reverse_ops_with_indexY  s;     dE]#UDM"C
vx0r&   zTODO(infer_string))reasonc                 0   t        g dt        d            }t        g dt        d            }t        g dt        d            }||z  }t        j                  ||       t        g dt        d            }||z  }t        j                  ||       t        g dt        d            }||z  }t        j                  ||       t        g dt        d            }t        g dt        d            }t        g d	t        d            }||z  }t        j                  ||       t        g d
t        d            }||z  }t        j                  ||       t        g t              }||j                         z  }t        g dt        d            }t        j                  ||       ||j                         z  }t        g dt        d            }t        j                  ||       t        j                  t              5  |t        dgdg      z  }d d d        t        g dt        d            }t        j                  ||       t        j                  t              5  |t        dgdg      z  }d d d        t        g d
t        d            }t        j                  ||       t        j                  t              5  |j                         t        dgdg      t        t        j                  |j                        t        t        j                  |j                        fD ]#  }|||z     }t        j                  |||          % 	 d d d        t        dg      fD ]R  }|r-t        j                  t        d      5  |||z     }d d d        n|||z     }t        j                  |||          T t        d      }t        g d      }	dD ]9  }
t        g d|      |
z  }t        g d|      }t        j                  ||       ; d}t        j                  dfD ]+  }
t        j                  t        |      5  |	|
z   d d d        - dD ]9  }
t        g d|      |
z  }t        g d|      }t        j                  ||       ; dD ]9  }
t        g d|      |
z  }t        g d|      }t        j                  ||       ; dD ]9  }
t        g d|      |
z  }t        g d|      }t        j                  ||       ; d}t        j                  fD ]+  }
t        j                  t        |      5  |	|
z   d d d        - y # 1 sw Y   :xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   hxY w# 1 sw Y   yxY w)Nr)   r(   )FTFrj   TTFrh   )FTFTabcd)FTFFr|   r   r,   r8   z)FFFFabczz0not supported for dtype|unsupported operand typerI   )Tr8   r   r*   )TTTrH   foo)Fr   )Tr8   )r   r-   r   r   r   copyrP   rQ   r   r   r+   rM   rN   rO   )r   using_infer_stringrW   rX   r#   r"   emptyer+   tvrT   s               r$   test_logical_ops_label_basedz1TestSeriesLogicalOps.test_logical_ops_label_basedk  s   
 &U4'e5.U<Q
vx0-tE{;Q
vx0.U<Q
vx0 &U4-tF|<5tF|DQ
vx04d6lCQ
vx0
 r(UZZ\!/e=
vx0UZZ\!-tE{;
vx0 ''6 	,cU++F	,6VE
vx0''6 	,cU++F	,4d6lC
vx0 ''6 	5

sSE"rvvqww'rvvqww'	 5 1q5&&vqt45	5 #- 
	1A! ]]%W & q1uXF& &
 1q5""61Q40
	1 U&' 	5A/u=AF0>H""684	5
 H&&% 	Ay4 A 	  	5A/u=AF1?H""684	5
  	5A/u=AF1?H""684	5
  	5A/u=AF35AH""684	5 H&& 	Ay4 A 		, 	,
	, 	,	5 	5& && & sI   U!UBU%	U2?U?:VUU"%U/2U<	?V		V	c                 (   t        g dt        d      d      }t        g dt        d      d      }t        g dt        d      d      }t        j                  ||z  |       t        j                  ||z  |       t        g d	t        d      d      }t        j                  ||z  |       t        g d
t        d      d      }t        j                  ||z  |       t        j                  |j                         |j                         z  |j                                t        j                  |j                         |j                         z  |j                                t        dddt        j                  t        j                  git        d            }t        j                  |j                         |j                         z  |j                                t        j                  |j                         |j                         z  |j                                t        g dt        d      d      }t        g dt        d      d      }t        g dt        d      d      }t        j                  ||z  |       t        j                  ||z  |       t        g d	t        d      d      }t        j                  ||z  |       t        g dt        d      d      }t        j                  ||z  |       t        j                  |j                         |j                         z  |j                                t        j                  |j                         |j                         z  |j                                t        j                  |j                         |j                         z  |j                                t        j                  |j                         |j                         z  |j                                y )Nr)   ABCxr+   namer   ABD)TFFFABCD)TTTFr|   Tr*   )TTTTr}   )	r   r-   r   r   rx   to_framer   r   r   )r   s1s2expexp_or1exp_ors3s4s           r$   test_logical_ops_df_compatz/TestSeriesLogicalOps.test_logical_ops_df_compat  s   'tE{E'tE{E0V3O
rBw,
rBw, 2$v,SQ
rBw02$v,SQ
rBw/ 	bkkmbkkm;S\\^L
bkkmbkkm;S\\^LtT266266:;4<P
bkkmbkkm;W=M=M=OP
bkkmbkkm;V__=NO 'tE{E,DLsK/tF|#N
rBw,
rBw, 2$v,SQ
rBw00V3O
rBw/
bkkmbkkm;S\\^L
bkkmbkkm;S\\^L
bkkmbkkm;W=M=M=OP
bkkmbkkm;V__=NOr&   z-Will pass once #52839 deprecation is enforcedc                     t        g dg dd      }t        g dg dd      }t        j                  ||      }t        g dg dd      }t        j                  ||       ||z  }t        j                  ||       y )N)r8   r   r   )r         rW   r   )r         )r   r   r   )   r7      )r   r   bitwise_xorr   r   )r   ser1ser2r"   r#   s        r$   'test_int_dtype_different_index_not_boolz<TestSeriesLogicalOps.test_int_dtype_different_index_not_bool	  sg     i|#>l,SAd++\D
vx0
vx0r&   c                 `   t        j                  d      }t        ddg      }t        ddgt        t        j
                              }||k(  }t        d|j                        }t        j                  ||       ||k7  }t        d|j                        }t        j                  ||       t        j                  t        d	
      5  ||kD   d d d        |j                  d      }||k(  }t        j                  ||j                  d             ||k7  }	t        j                  |	|j                  d             t        j                  t        d	
      5  ||kD   d d d        |j                  t        |j                                     }
|
|k(  }t        j                  ||j                  d             |
|k7  }t        j                  ||j                  d             t        j                  t        d	
      5  ||
kD   d d d        y # 1 sw Y   >xY w# 1 sw Y   xY w# 1 sw Y   y xY w)NpyarrowFTrW   rX   )na_valuer   r*   zInvalid comparisonrI   zstring[pyarrow]zbool[pyarrow])rM   importorskipr   r	   r   r   r+   r   r   rN   rO   r=   r   string)r   par   r   r"   expected_eqexpected_neser3
result3_eq
result3_neser4
result4_eq
result4_nes                r$   !test_pyarrow_numpy_string_invalidz6TestSeriesLogicalOps.test_pyarrow_numpy_string_invalid  s     +eT]#sCjRVV(DEU#))4
v{3T3
v{3]]9,@A 	$J	 {{,-S[

z;+=+=o+NOS[

z;+=+=o+NO]]9,@A 	$J	 {{:biik23S[

z;+=+=o+NOS[

z;+=+=o+NO]]9,@A 	$J	 	'	 		 		 	s$   	HH<H$HH!$H-N)'__name__
__module____qualname__rM   markfilterwarningsparametrizeoperatorand_or_xorr%   r3   rC   rE   rU   r[   r]   r`   rb   rf   rn   rt   ry   r   r   r   rand_ror_r   r   rxorr   xfailr   r   r   r   r    r&   r$   r   r      s   [[ VW[[Yhll(ST1 U X1. .0
.0..12.)1V".H1*0 [[THMM8<<#NO1 P1 1 [[IIHH	
11 [[YYu~./XXvtTl+,XXvtTl+,	
11 [[)+4HIn Jn`+PZ [[MN	1 O	1!r&   r   )r   r   numpyr   rM   pandas._configr   pandasr   r   r   r   r	   r
   pandas._testing_testingr   pandas.corer   r   r   r&   r$   <module>r      s2        -   b br&   