
    ˀh3              	      j   d dl mZ d dlZd dlmZm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mZmZ d dlmZ d d	lmZ erd d
lmZ  ej6                  e      5  d dlmZ ddd       d$dZ eddd      dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 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ddd      dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d%d#       Z-y# 1 sw Y   xY w).    )annotationsN)TYPE_CHECKINGAny)deprecate_renamed_parameter)ArrayCategoricalListStringStructunpack_dtypes)FLOAT_DTYPES)ComputeErrorInvalidOperationError
ShapeError)Series)raise_assertion_error)DataType)assert_series_equal_pyc                    d}t        | t              rt        |t              s4t        ddt        |       j                  t        |      j                         y)NTinputszunexpected input types)
isinstancer   r   type__name__)leftright__tracebackhide__s      y/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/polars/testing/asserts/series.py_assert_correct_input_typer      sH    tV$E6)B$JK  		
     check_dtypecheck_dtypesz0.20.31)versionTFgh㈵>g:0yE>r!   check_namescheck_ordercheck_exactrtolatolcategorical_as_strc               p    d}	t        | |       t        | j                  |j                  |||||||	       y)a  
    Assert that the left and right Series are equal.

    Raises a detailed `AssertionError` if the Series differ.
    This function is intended for use in unit tests.

    .. versionchanged:: 0.20.31
        The `check_dtype` parameter was renamed `check_dtypes`.

    Parameters
    ----------
    left
        The first Series to compare.
    right
        The second Series to compare.
    check_dtypes
        Requires data types to match.
    check_names
        Requires names to match.
    check_order
        Requires elements to appear in the same order.
    check_exact
        Requires float values to match exactly. If set to `False`, values are considered
        equal when within tolerance of each other (see `rtol` and `atol`).
        Only affects columns with a Float data type.
    rtol
        Relative tolerance for inexact checking, given as a fraction of the values in
        `right`.
    atol
        Absolute tolerance for inexact checking.
    categorical_as_str
        Cast categorical columns to string before comparing. Enabling this helps
        compare columns that do not share the same string cache.

    See Also
    --------
    assert_frame_equal
    assert_series_not_equal

    Notes
    -----
    When using pytest, it may be worthwhile to shorten Python traceback printing
    by passing `--tb=short`. The default mode tends to be unhelpfully verbose.
    More information in the
    `pytest docs <https://docs.pytest.org/en/latest/how-to/output.html#modifying-python-traceback-printing>`_.

    Examples
    --------
    >>> from polars.testing import assert_series_equal
    >>> s1 = pl.Series([1, 2, 3])
    >>> s2 = pl.Series([1, 5, 3])
    >>> assert_series_equal(s1, s2)
    Traceback (most recent call last):
    ...
    AssertionError: Series are different (exact value mismatch)
    [left]: shape: (3,)
    Series: '' [i64]
    [
        1
        2
        3
    ]
    [right]: shape: (3,)
    Series: '' [i64]
    [
        1
        5
        3
    ]
    Tr#   N)r   r   _s)
r   r   r!   r$   r%   r&   r'   r(   r)   r   s
             r   assert_series_equalr,   (   s@    f tU+!-
r   c                  d}|rt        |       } t        |      }|st        | |      \  } }	 | j                  |      }t        | j
                  |j
                        r1	 t        | j                        |j                  |      ||||       yj                         sy|s4| j
                  j                         r|j
                  j                         s+t	        dd	| j                         |j                         
       t        | |       t        | |       t!        | ||||       y# t        $ r/}	t	        dd| j
                  |j
                  |	       Y d}	~	d}	~	wt        $ r}	t	        dd| ||	       Y d}	~	Ad}	~	ww xY w# t        $ r7}	t	        dd| j                         |j                         |	       Y d}	~	3d}	~	ww xY w)z0Assert that the values in both Series are equal.Tr   zincompatible data types)r   r   causeNzincompatible lengths)r   r   r&   r'   r(   r)   nested value mismatchzexact value mismatchr   r   )r'   r(   )_categorical_series_to_string_sort_series
ne_missingr   r   dtyper   _comparing_nested_floats"_assert_series_nested_values_equalfilterAssertionErrorto_listanyis_float _assert_series_null_values_match_assert_series_nan_values_match&_assert_series_values_within_tolerance)
r   r   r%   r&   r'   r(   r)   r   unequalexcs
             r   _assert_series_values_equalrA      s     ,T2-e4"4/e
//%(&  

EKK8	.[[)ll7+'#5"  ;;= $**--/u{{7K7K7M,4<<>	
 %T51#D%0*g  
%++	
 	
  
"	
 	

(  	!'\\^mmo 	s;   D* /F *	F3$EF)E??F	G,GGc                    	 | j                         } |j                         }| |fS # t        $ r}d}t        |      |d }~ww xY w)NzBcannot set `check_order=False` on Series with unsortable data type)sortr   	TypeError)r   r   r@   msgs       r   r2   r2      sL    &yy{

 ; ! &Rn#%&s    & 	A=Ac          
     n   d}t        | j                  |j                        r9t        | |      D ])  \  }}||t        dd||       t	        ||d||||       + y | j
                  j                         |j
                  j                         }
}	t        |	|
      D ]  \  }}t	        ||d||||        y )NTr   r/   )r%   r&   r'   r(   r)   )_comparing_listsr4   zipr   rA   structunnest)r   r   r&   r'   r(   r)   r   s1s2lsrss              r   r6   r6      s      

EKK0$& 	FBzRZ%h0GRP' '#5		  ##%u||':':'<B"bk 		FB' '#5		r   c                    d}| j                         |j                         k7  }|j                         r+t        dd| j                         |j                                y y )NTr   znull value mismatch)is_nullr:   r   r9   )r   r   r   null_value_mismatchs       r   r<   r<     sN    ,,.EMMO; +T\\^U]]_	
 !r   c                   d}t        | j                  |j                        sy | j                         |j                         k7  }|j                         r+t	        dd| j                         |j                                y y )NTr   znan value mismatch)_comparing_floatsr4   is_nanr:   r   r9   )r   r   r   nan_value_mismatchs       r   r=   r=     se    TZZ5%,,.8 LLNMMO		
  r   c                F    | j                         xr |j                         S N)r;   r0   s     r   rS   rS   +  s    ==?/u~~//r   c                >    | t         t        fv xr |t         t        fv S rW   )r	   r   r0   s     r   rG   rG   /  s    D%= ;UtUm%;;r   c                *    | t         k(  xr	 |t         k(  S rW   )r   r0   s     r   _comparing_structsrZ   3  s    6>-evo-r   c                    t        | |      st        | |      syt        t        t	        |       z        xr t        t        t	        |      z        S )NF)rG   rZ   boolr   r   r0   s     r   r5   r5   7  sI    T5)-?e-L}T223 }U++9 r   c               L   d}| j                  |      |j                  |      }}||z
  j                         }|||j                         z  z   }	||	k  |j                         z  ||k(  z  }
|
j                         s+t	        dd| j                         |j                                y y )NTr   zvalue mismatch)r7   abs	is_finiteallr   r9   )r   r   r?   r'   r(   r   left_unequalright_unequal
difference	tolerancewithin_tolerances              r   r>   r>   @  s     "&++g"6W8M-L.335Jtm//111I"i/=3J3J3LL% !LLNMMO		
 "r   c                `    | j                   }t        |      }||k7  r| j                  |      } | S )z?Cast a (possibly nested) Categorical Series to a String Series.)r4   "_categorical_dtype_to_string_dtypecast)sr4   noncat_dtypes      r   r1   r1   [  s0    GGE5e<LFF< Hr   c                   t        | t              r
t               S t        | t              r t	        | j
                        }t        |      S t        | t              r+t	        | j
                        }t        || j                        S t        | t              rB| j                  D ci c]"  }|j                  t	        |j                        $ }}t        |      S | S c c}w )zGChange a (possibly nested) Categorical data type to a String data type.)r   r   r
   r	   rg   innerr   sizer   fieldsnamer4   )r4   
inner_castfrn   s       r   rg   rg   d  s    %%x	E4	 7D
J	E5	!7D
Z,,	E6	" \\
 FF6qww??
 
 f~
s   $'Cc                   d}	t        | |       	 t        | ||||||||	       d}
t        |
      # t        $ r Y yw xY w)a  
    Assert that the left and right Series are **not** equal.

    This function is intended for use in unit tests.

    .. versionchanged:: 0.20.31
        The `check_dtype` parameter was renamed `check_dtypes`.

    Parameters
    ----------
    left
        The first Series to compare.
    right
        The second Series to compare.
    check_dtypes
        Requires data types to match.
    check_names
        Requires names to match.
    check_order
        Requires elements to appear in the same order.
    check_exact
        Requires float values to match exactly. If set to `False`, values are considered
        equal when within tolerance of each other (see `rtol` and `atol`).
        Only affects columns with a Float data type.
    rtol
        Relative tolerance for inexact checking, given as a fraction of the values in
        `right`.
    atol
        Absolute tolerance for inexact checking.
    categorical_as_str
        Cast categorical columns to string before comparing. Enabling this helps
        compare columns that do not share the same string cache.

    See Also
    --------
    assert_series_equal
    assert_frame_not_equal

    Examples
    --------
    >>> from polars.testing import assert_series_not_equal
    >>> s1 = pl.Series([1, 2, 3])
    >>> s2 = pl.Series([1, 2, 3])
    >>> assert_series_not_equal(s1, s2)
    Traceback (most recent call last):
    ...
    AssertionError: Series are equal (but are expected not to be)
    T)	r   r   r!   r$   r%   r&   r'   r(   r)   z-Series are equal (but are expected not to be)N)r   r,   r8   )r   r   r!   r$   r%   r&   r'   r(   r)   r   rE   s              r   assert_series_not_equalrs   x  sc    z tU+"%###1
	
 >S!!	  s   1 	==)r   r   r   r   returnr\   )r   r   r   r   r!   r\   r$   r\   r%   r\   r&   r\   r'   floatr(   ru   r)   r\   rt   None)r   r   r   r   r%   r\   r&   r\   r'   ru   r(   ru   r)   r\   rt   rv   )r   r   r   r   rt   ztuple[Series, Series])r   r   r   r   r&   r\   r'   ru   r(   ru   r)   r\   rt   rv   )r   r   r   r   rt   rv   )r   r   r   r   rt   r\   )r   r   r   r   r?   r   r'   ru   r(   ru   rt   rv   )ri   r   rt   r   )r4   r   rt   r   ).
__future__r   
contextlibtypingr   r   polars._utils.deprecationr   polars.datatypesr   r   r	   r
   r   r   polars.datatypes.groupr   polars.exceptionsr   r   r   polars.seriesr   polars.testing.asserts.utilsr   polarsr   suppressImportErrorpolars.polarsr   r   r,   rA   r2   r6   r<   r=   rS   rG   rZ   r5   r>   r1   rg   rs    r   r   <module>r      s   "  % A  0 M M   >Z% 545
 ]NIN
 $`
`` 	`
 ` ` ` ` ` ` 
` O`FQ
QQ 	Q
 Q Q Q Q 
Qh'
'' 	'
 ' ' ' 
'T

0<.



 

 
 
 

6( ]NIN
 $O"
O"O" 	O"
 O" O" O" O" O" O" 
O" OO"E5 5s   D))D2