o
    h2+                     @  s   d dl mZ d dlmZ d dlZd dlZd dlmZ d dl	m
Z
 d dlZd dlmZ d dlmZ G dd dZG d	d
 d
eZG dd deZG dd deZdS )    )annotations)finalN)using_pyarrow_string_dtype)is_string_dtype)opsc                   @  s   e Zd ZU eZded< eZded< eZded< eZded< dd	d
Z	dddZ
dddZedddZedd ZeefdddZedddZdS )BaseOpsUtiltype[Exception] | Noneseries_scalar_excframe_scalar_excseries_array_exc
divmod_excop_namestrreturnc                 C  sr   |dv r| j }nt|tjrt|tjr| j}nt|tjr"| j}n| j}t r7|d ur7dd l}||j	j
tf}|S )N)
__divmod____rdivmod__r   )r   
isinstancepdSeriesr   r	   r
   r   pyarrowlibArrowNotImplementedErrorNotImplementedError)selfr   objotherresultpa r   s/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/pandas/tests/extension/base/ops.py_get_expected_exception   s   z#BaseOpsUtil._get_expected_exceptionc                 C  s   |S Nr   )r   r   r   r   pointwise_resultr   r   r   _cast_pointwise_result2   s   z"BaseOpsUtil._cast_pointwise_resultc                 C  s
   t |S r!   )tmget_op_from_name)r   r   r   r   r   r%   ;   s   
zBaseOpsUtil.get_op_from_nameser	pd.Seriesc                 C  s.   |  |||}| |}| ||||| d S r!   )r    r%   	_check_op)r   r&   r   r   excopr   r   r   check_opnameD   s   
zBaseOpsUtil.check_opnamec                 C  sP   t |tjr t|jdkrt|jd d df || }|S |||}|S )N   r   )	r   r   	DataFramelencolumnsr   iloccombineto_frame)r   r   r   r*   expectedr   r   r   _combineL   s   zBaseOpsUtil._combinec                 C  s   |d u r)|||}|  |||}| ||||}t|t|s!J t|| d S t| ||| W d    d S 1 s?w   Y  d S r!   )r4   r#   r   typer$   assert_equalpytestraises)r   r&   r*   r   r   r)   r   r3   r   r   r   r(   W   s   
"zBaseOpsUtil._check_opc           	      C  s   |t u r| d||}n| d||}|d u rC|||\}}|t u r,|| || }}n	|| || }}t|| t|| d S t| t || W d    d S 1 sYw   Y  d S )Nr   r   )divmodr    r$   assert_series_equalr7   r8   )	r   r&   r*   r   r)   
result_div
result_modexpected_divexpected_modr   r   r   _check_divmod_opi   s   "zBaseOpsUtil._check_divmod_opN)r   r   r   r   )r   r   )r&   r'   r   r   r&   r'   )__name__
__module____qualname__	TypeErrorr	   __annotations__r
   r   r   r    r#   r%   r   r+   r4   r   r(   r?   r   r   r   r   r      s"   
 


		

r   c                   @  s   e Zd ZU dZeZded< eZded< eZded< eZ	ded< 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ejddd ejej D dd ZdS )BaseArithmeticOpsTestsa?  
    Various Series and DataFrame arithmetic ops methods.

    Subclasses supporting various ops should set the class variables
    to indicate that they support ops of that kind

    * series_scalar_exc = TypeError
    * frame_scalar_exc = TypeError
    * series_array_exc = TypeError
    * divmod_exc = TypeError
    r   r	   r
   r   r   c                 C  sB   |dkrt |jrtd |}t|}| |||jd  d S )N__rmod__%Skip testing Python string formattingr   )r   dtyper7   skipr   r   r+   r0   r   dataall_arithmetic_operatorsr   r&   r   r   r   test_arith_series_with_scalar   s
   

z4BaseArithmeticOpsTests.test_arith_series_with_scalarc                 C  sD   |dkrt |jrtd |}td|i}| |||d  d S )NrG   rH   Ar   )r   rI   r7   rJ   r   r-   r+   )r   rL   rM   r   dfr   r   r   test_arith_frame_with_scalar   s
   
z3BaseArithmeticOpsTests.test_arith_frame_with_scalarc              	   C  s6   |}t |}| ||t |jd gt|  d S Nr   )r   r   r+   r0   r.   rK   r   r   r   test_arith_series_with_array   s   
(z3BaseArithmeticOpsTests.test_arith_series_with_arrayc                 C  s,   t |}| |td | dtj| d S )Nr,   r   r   r?   r9   r   rdivmod)r   rL   r&   r   r   r   test_divmod   s   
z"BaseArithmeticOpsTests.test_divmodc                 C  sJ   t |}| |t| |}| |tj| t |}| |tj| d S r!   rT   )r   rL   data_for_twosr&   r   r   r   r   test_divmod_series_array   s   

z/BaseArithmeticOpsTests.test_divmod_series_arrayc                 C  s~   t |}| d||}|d ur,t| ||  W d    d S 1 s%w   Y  d S || }t || }t|| d S )N__add__)r   r   r    r7   r8   r$   r:   )r   rL   r&   r)   r   r3   r   r   r   $test_add_series_with_extension_array   s   


z;BaseArithmeticOpsTests.test_add_series_with_extension_arrayboxr   c                 C  s   g | ]	}| d s|qS )__r)
startswith.0xr   r   r   
<listcomp>   s    z!BaseArithmeticOpsTests.<listcomp>c                 C  s4   ||}t ||rt|||}|tu sJ d S d S r!   )hasattrgetattrNotImplemented)r   rL   r[   r   r   r   r   r   r   6test_direct_arith_with_ndframe_returns_not_implemented   s   
zMBaseArithmeticOpsTests.test_direct_arith_with_ndframe_returns_not_implementedN)rA   rB   rC   __doc__rD   r	   rE   r
   r   r   rN   rQ   rS   rV   rX   rZ   r7   markparametrizer   r   r-   Indexr$   arithmetic_dunder_methodscomparison_dunder_methodsre   r   r   r   r   rF   }   s(   
 		

rF   c                   @  s*   e Zd ZdZdddZdd Zdd	 Zd
S )BaseComparisonOpsTestsz4Various Series and DataFrame comparison ops methods.r&   r'   c           	   
   C  s   |j dv r!|||}|||}| |j |||}t|| d S d }z|||}W n ty> } z|}W Y d }~nd }~ww |d u rZ|||}| |j |||}t|| d S tt| ||| W d    d S 1 ssw   Y  d S )N)eqne)	rA   r1   r#   r$   r:   	Exceptionr7   r8   r5   )	r   r&   rL   r*   r   r   r3   r)   errr   r   r   _compare_other   s*   


"z%BaseComparisonOpsTests._compare_otherc                 C  s   t |}| |||d d S rR   )r   r   rq   )r   rL   comparison_opr&   r   r   r   test_compare_scalar   s   
z*BaseComparisonOpsTests.test_compare_scalarc                 C  s<   t |}t j|d gt| |jd}| |||| d S )Nr   )rI   )r   r   r.   rI   rq   )r   rL   rr   r&   r   r   r   r   test_compare_array   s   
z)BaseComparisonOpsTests.test_compare_arrayNr@   )rA   rB   rC   rf   rq   rs   rt   r   r   r   r   rl      s
    
rl   c                   @  s6   e Zd Zdd Zejdejej	ej
gdd ZdS )BaseUnaryOpsTestsc                 C  s   t j|dd}zdd |d d D  W n< tyP   tt |  W d    n1 s.w   Y  tt |  W d    Y d S 1 sHw   Y  Y d S w | }t j| dd}t|| d S )Nname)rv   c                 S  s   g | ]}| qS r   r   r^   r   r   r   ra   	  s    z1BaseUnaryOpsTests.test_invert.<locals>.<listcomp>
   )r   r   rD   r7   r8   r$   r:   )r   rL   r&   r   r3   r   r   r   test_invert  s   &
zBaseUnaryOpsTests.test_invertufuncc                 C  s   t jdt jdt jdi| }d }zt|| }W n9 tyP } z-|}tt|t	f || W d    n1 s9w   Y  W Y d }~d S W Y d }~d S d }~ww ||}t
|| d S )N__pos____neg____abs__)nppositivenegativeabsrc   ro   r7   r8   r5   rD   r$   assert_extension_array_equal)r   rL   ry   attrr)   r   rp   altr   r   r   #test_unary_ufunc_dunder_equivalence  s   
8z5BaseUnaryOpsTests.test_unary_ufunc_dunder_equivalenceN)rA   rB   rC   rx   r7   rg   rh   r}   r~   r   r   r   r   r   r   r   ru     s    ru   )
__future__r   typingr   numpyr}   r7   pandas._configr   pandas.core.dtypes.commonr   pandasr   pandas._testing_testingr$   pandas.corer   r   rF   rl   ru   r   r   r   r   <module>   s    l_'