
    q-Ph3              	         d dl m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 d6dZ eddd          ddddddddd7d"            Zd8d#Zd9d%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>d1Z&d?d3Z' eddd          ddddddddd7d4            Z(d5S )@    )annotations)TYPE_CHECKINGAny)deprecate_renamed_parameter)ArrayCategoricalListStringStructunpack_dtypes)FLOAT_DTYPES)ComputeErrorInvalidOperationError
ShapeError)Series)raise_assertion_error)DataTypeleftr   rightreturnboolc                    d}t          | t                    rt          |t                    s6t          ddt          |           j        t          |          j                   dS )NTinputszunexpected input types)
isinstancer   r   type__name__)r   r   __tracebackhide__s      ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/testing/asserts/series.py_assert_correct_input_typer      sb    tV$$ 
E6)B)B 
$JJKK 		
 	
 	
 4    check_dtypecheck_dtypesz0.20.31)versionTFgh㈵>g:0yE>)r"   check_namescheck_ordercheck_exactrtolatolcategorical_as_strr   r$   r%   r&   r'   floatr(   r)   Nonec          	        d}	t          | |           |                                 |                                k    r6t          dd|                                 |                                           |r,| j        |j        k    rt          dd| j        |j                   |r,| j        |j        k    rt          dd| j        |j                   t          | ||||||           dS )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]:  [1, 2, 3]
    [right]: [1, 5, 3]
    Tr   zlength mismatchzname mismatchzdtype mismatchr%   r&   r'   r(   r)   N)r   lenr   namedtype_assert_series_values_equal)
r   r   r"   r$   r%   r&   r'   r(   r)   r   s
             r   assert_series_equalr2   $   s    N tU+++xxzzUYY[[  h(9488::uyy{{SSS PtyEJ..hEJOOO S
ek11h(8$*ekRRR-     r    c                  d}|rt          |           } t          |          }|st          | |          \  } }	 |                     |          }n[# t          $ r(}	t	          dd| j        |j        |	           Y d}	~	n.d}	~	wt          $ r}	t	          dd| ||	           Y d}	~	nd}	~	ww xY wt          | j        |j                  r	 t          | 	                    |          |	                    |          ||||           dS # t          $ rB}	t	          dd|                                 |                                |	           Y d}	~	nd}	~	ww xY w|                                sdS |s2| j                                        r|j                                        s7t	          dd	|                                 |                                
           t          | |           t          | |           t!          | ||||           dS )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   r0   r   _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   r1   r1      s      5,T22-e44 0"4//e
//%(( 
 
 
%+	
 	
 	
 	
 	
 	
 	
 	
 	
  
 
 
"	
 	
 	
 	
 	
 	
 	
 	
 	

  
EK88 	.[[))ll7++'#5   " F  	 	 	!'\\^^mmoo        	 ;;==   
$*--// 
u{7K7K7M7M 
,4<<>>	
 	
 	
 	
 %T5111#D%000*     s;   A 
B'A<<B'	B""B';D 
E8E		Etuple[Series, Series]c                    	 |                                  } |                                 }n$# t          $ r}d}t          |          |d }~ww xY w| |fS )NzBcannot set `check_order=False` on Series with unsortable data type)sortr   	TypeError)r   r   rE   msgs       r   r8   r8      sa    &yy{{

  & & &Rnn#%& ;s   (+ 
AAAc          
        d}t          | j        |j                  rDt          | |          D ]1\  }}||t          dd||           t	          ||d||||           2d S | j                                        |j                                        }
}	t          |	|
          D ]\  }}t	          ||d||||           d S )NTr   r5   r-   )_comparing_listsr0   zipr   r1   structunnest)r   r   r&   r'   r(   r)   r   s1s2lsrss              r   r;   r;      s     
EK00 $&& 	 	FBzRZ%h0GRPPP' '#5    		 	  ##%%u|':':'<'<B"bkk 		 		FB' '#5    		 		r    c                    d}|                                  |                                 k    }|                                r8t          dd|                                 |                                           d S d S )NTr   znull value mismatch)is_nullr?   r   r>   )r   r   r   null_value_mismatchs       r   rA   rA     sw    ,,..EMMOO;   
+T\\^^U]]__	
 	
 	
 	
 	

 
r    c                .   d}t          | j        |j                  sd S |                                 |                                k    }|                                r8t	          dd|                                 |                                           d S d S )NTr   znan value mismatch)_comparing_floatsr0   is_nanr?   r   r>   )r   r   r   nan_value_mismatchs       r   rB   rB     s    TZ55 %,,..8 
 LLNNMMOO		
 	
 	
 	
 	

 
r    r   c                R    |                                  o|                                 S N)r@   r6   s     r   rX   rX   "  s    ==??/u~~///r    c                B    | t           t          fv o|t           t          fv S r\   )r	   r   r6   s     r   rL   rL   &  s    D%= ;UtUm%;;r    c                .    | t           k    o
|t           k    S r\   )r   r6   s     r   _comparing_structsr_   *  s    6>-evo-r    c                    t          | |          st          | |          sdS t          t          t	          |           z            o#t          t          t	          |          z            S )NF)rL   r_   r   r   r   r6   s     r   r:   r:   .  si    T5)) -?e-L-L u}T22233 }U+++9 9 r    rD   c                  d}|                      |          |                     |          }}||z
                                  }|||                                z  z   }	||	k    |                                z  ||k    z  }
|
                                s8t	          dd|                                 |                                           d S d S )NTr   zvalue mismatch)r<   abs	is_finiteallr   r>   )r   r   rD   r'   r(   r   left_unequalright_unequal
difference	tolerancewithin_tolerances              r   rC   rC   7  s     "&++g"6"6W8M8M-L.3355Jtm//1111I"i/=3J3J3L3LL% !! 
LLNNMMOO		
 	
 	
 	
 	

 
r    sc                h    | j         }t          |          }||k    r|                     |          } | S )z?Cast a (possibly nested) Categorical Series to a String Series.)r0   "_categorical_dtype_to_string_dtypecast)rj   r0   noncat_dtypes      r   r7   r7   R  s7    GE5e<<LFF<  Hr    r0   c                   t          | t                    rt                      S t          | t                    r#t	          | j                  }t          |          S t          | t                    r)t	          | j                  }t          || j                  S t          | t                    r d | j	        D             }t          |          S | S )zGChange a (possibly nested) Categorical data type to a String data type.c                B    i | ]}|j         t          |j                  S  )r/   rl   r0   ).0fs     r   
<dictcomp>z6_categorical_dtype_to_string_dtype.<locals>.<dictcomp>f  s7     
 
 
 F6qw??
 
 
r    )
r   r   r
   r	   rl   innerr   sizer   fields)r0   
inner_castrw   s      r   rl   rl   [  s    %%% xx	E4	 	  7DD
J	E5	!	! 
7DD
Z,,,	E6	"	" 
 
\
 
 
 f~~r    c                   d}	t          | |           	 t          | ||||||||	  	         d}
t          |
          # t          $ r Y dS 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   r2   r=   )r   r   r"   r$   r%   r&   r'   r(   r)   r   rJ   s              r   assert_series_not_equalrz   o  s    z tU+++"%###1
	
 
	
 
	
 
	
 >S!!!	    s   = 
A
AN)r   r   r   r   r   r   )r   r   r   r   r"   r   r$   r   r%   r   r&   r   r'   r*   r(   r*   r)   r   r   r+   )r   r   r   r   r%   r   r&   r   r'   r*   r(   r*   r)   r   r   r+   )r   r   r   r   r   rF   )r   r   r   r   r&   r   r'   r*   r(   r*   r)   r   r   r+   )r   r   r   r   r   r+   )r   r   r   r   r   r   )r   r   r   r   rD   r   r'   r*   r(   r*   r   r+   )rj   r   r   r   )r0   r   r   r   ))
__future__r   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   r   r2   r1   r8   r;   rA   rB   rX   rL   r_   r:   rC   r7   rl   rz   rq   r    r   <module>r      s   " " " " " " % % % % % % % % A A A A A A                0 / / / / / M M M M M M M M M M             > > > > > >  
 
 
 
 ]NINNN
 $[ [ [ [ [ ON[|Q Q Q Qh   ' ' ' 'T
 
 
 

 
 
 
0 0 0 0< < < <. . . .   
 
 
 
6      ( ]NINNN
 $O" O" O" O" O" ONO" O" O"r    