
    /_in+                       U d dl mZ d dlmZ d dlmZmZ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 er(d d	lmZ d d
lmZ d dlmZmZ eee   ee   gdf   Zde 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(y)$    )annotations)partial)TYPE_CHECKINGAnyCallable)qualified_type_name
zip_strictis_narwhals_series)ArrayBooleanCategoricalListStringStruct)
new_series)raise_series_assertion_error)	TypeAlias)Series)IntoSeriesTSeriesTNr   CheckFnTFgh㈵>g:0yE>check_dtypescheck_namescheck_ordercheck_exactrel_tolabs_tolcategorical_as_strc          	        d}	t        d | |fD              r8dt        t        |              dt        t        |             d}
t        |
      t	        | |||       |sG| j
                  j                         rd}
t        |
      | j                         |j                         }} t        | |      \  }}|s| j
                  j                         st        |||||||       y
t        ||||	       y
)u"  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.

    Arguments:
        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 `rel_tol` and
            `abs_tol`). Only affects columns with a Float data type.
        rel_tol: Relative tolerance for inexact checking, given as a fraction of the
            values in `right`.
        abs_tol: 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.

    Examples:
        >>> import pandas as pd
        >>> import narwhals as nw
        >>> from narwhals.testing import assert_series_equal
        >>> s1 = nw.from_native(pd.Series([1, 2, 3]), series_only=True)
        >>> s2 = nw.from_native(pd.Series([1, 5, 3]), series_only=True)
        >>> assert_series_equal(s1, s2)  # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        AssertionError: Series are different (exact value mismatch)
        [left]:
        ┌───────────────┐
        |Narwhals Series|
        |---------------|
        | 0    1        |
        | 1    2        |
        | 2    3        |
        | dtype: int64  |
        └───────────────┘
        [right]:
        ┌───────────────┐
        |Narwhals Series|
        |---------------|
        | 0    1        |
        | 1    5        |
        | 2    3        |
        | dtype: int64  |
        └───────────────┘
    Tc              3  4   K   | ]  }t        |         y w)Nr
   ).0objs     ^/var/www/html/land_sniper/venv/lib/python3.12/site-packages/narwhals/testing/asserts/series.py	<genexpr>z&assert_series_equal.<locals>.<genexpr>T   s     
@3!#&&
@s   z4Expected `narwhals.Series` instance, found:
[left]: z

[right]: zp

Hint: Use `nw.from_native(obj, series_only=True) to convert each native object into a `narwhals.Series` first.)r   r   zA`check_order=False` is not supported (yet) with nested data type.)r   r   r   r   r    )r   r   N)anyr   type	TypeError_check_metadatadtype	is_nestedNotImplementedErrorsort_check_null_valuesis_float_check_exact_values_check_approximate_values)leftrightr   r   r   r   r   r   r    __tracebackhide__msg	left_vals
right_valss                r%   assert_series_equalr9      s    z 

@4-
@@*4:67 8+DK89 :55 	 nD%lT::!UC%c**iik5::<e.tU;Iz$**--/%#1	
 	")ZRYZ    c               \   | j                   |j                   }}||k7  rt        d||       t        |       t        |      }}||k7  rt        d||       | j                  |j                  }	}|r||	k7  rt        d||	       | j                  |j                  }}
|r|
|k7  rt        d|
|       yyy)zECheck metadata information: implementation, length, dtype, and names.zimplementation mismatchzlength mismatchzdtype mismatchzname mismatchN)implementationr   lenr+   name)r3   r4   r   r   	left_impl
right_implleft_len	right_len
left_dtyperight_dtype	left_name
right_names               r%   r*   r*   v   s     !//1E1EzIJ$%>	:Vd)SZiH9$%6)L"jj%++J
k1$%5z;O IIuzzzIyJ.$_iL /{r:   c                   | j                         |j                         }}| j                         |j                         }}||k7  s||k7  j                         rt        d||       | j	                  |       |j	                  |       fS )z8Check null value consistency and return non-null values.znull value mismatch)
null_countis_nullr'   r   filter)r3   r4   left_null_countright_null_countleft_null_maskright_null_masks         r%   r/   r/      s~    (,(95;K;K;M%O&*llnemmoON**~/P.U.U.W$!?4D	
 ;;'6F)GGGr:   c          
        | j                   }| j                  |j                  }	}|j                         r| j                  |ddd       }
nt	        |t
        t        f      r[t	        |	t
        t        f      rE||	k(  r@t        t        |dd||||      }t        | |||	|       t        ddgt               |      }
nt	        |t              rPt	        |	t              r@t        t        ddd||||      }t        | |||	|       t        ddgt               |      }
nLt	        |t              r7t	        |	t              r't        | ||	      }t        d|gt               |      }
n| |k7  }
|
j!                         rt#        d
| |       yy)z2Check exact value equality for various data types.r   Tr   r   
nans_equalFr   )check_fn )r+   backend)r    exact value mismatchN)r<   r+   
is_numericis_close
isinstancer   r   r   r9   _check_list_liker   r   r   _check_structr   _check_categoricalr'   r   )r3   r4   r   r   r   r   r    r?   rC   rD   is_not_equal_maskrR   
_not_equals                r%   r1   r1      s    ##I"jj%++J  "]]5!QSW]XX:t}-*[5RV-2X

#%#1	
 	uj+Q&rE7')YW	J	'J{F,K#1	
 	dE:{XN&rE7')YW	J	,K1U (%,>

 'GIy
 !EM$%;T5I r:   c                   | j                  |||d       }|j                         r,t        d| j                  |      |j                  |             yy)z0Check approximate value equality with tolerance.TrP   zvalues not within toleranceN)rW   r'   r   rJ   )r3   r4   r   r   is_not_close_masks        r%   r2   r2      s^     wD '   $)KK)*LL*+	
 r:   c           
         | j                   }	 t        | |      D ]<  \  }} |t        d||j                  |      t        d||j                  |             > y # t        $ r t        d| |       Y y w xY w)NrS   )valuesr+   rT   znested value mismatch)r<   r	   r   innerAssertionErrorr   )r7   r8   rC   rD   rR   implleft_val	right_vals           r%   rY   rY      s     ##DU#-i#D 	Hi2hj6F6FPTU2i{7H7HRVW	
  U$%<iTUs   AA A32A3c                ,   	 t        |j                  |j                        D ]T  \  }} || j                  j                  |j                        |j                  j                  |j                               V y # t
        $ r t        d| |       Y y w xY w)NrU   )r	   fieldsstructfieldr>   rc   r   )r7   r8   rC   rD   rR   
left_fieldright_fields          r%   rZ   rZ      s    T'1*2C2C[EWEW'X 	#J  &&z7!!''(8(89	
  T$%;Y
STs   A7A: :BBc                   |r2| j                  t                     |j                  t                     }} 	 | |k7  j                         S # t        $ r}d}t	        |      |d}~ww xY w)zTry to compare if any element of categorical series' differ.

    Inability to compare means that the encoding is different, and an exception is raised.
    z:Cannot compare categoricals coming from different sources.N)castr   r'   	Exceptionrc   )r7   r8   r    excr6   s        r%   r[   r[     sa      )vx 8*//&(:S:	+Z',,.. +JS!s*+s   A	 		A%A  A%)r3   Series[IntoSeriesT]r4   rq   r   boolr   rr   r   rr   r   rr   r   floatr   rs   r    rr   returnNone)
r3   r   r4   r   r   rr   r   rr   rt   ru   )r3   r   r4   r   rt   ztuple[SeriesT, SeriesT])r3   r   r4   r   r   rr   r   rr   r   rs   r   rs   r    rr   rt   ru   )
r3   r   r4   r   r   rs   r   rs   rt   ru   )r7   r   r8   r   rC   List | ArrayrD   rv   rR   r   rt   ru   )r7   r   r8   r   rC   r   rD   r   rR   r   rt   ru   )r7   r   r8   r   r    rr   rt   rr   ))
__future__r   	functoolsr   typingr   r   r   narwhals._utilsr   r	   narwhals.dependenciesr   narwhals.dtypesr   r   r   r   r   r   narwhals.functionsr   narwhals.testing.asserts.utilsr   typing_extensionsr   narwhals.seriesr   narwhals.typingr   r   r   __annotations__r9   r*   r/   r1   r2   rY   rZ   r[    r:   r%   <module>r      sQ   "  / / ; 4 M M ) G+&4!6#;s"<d"BCGYC $^[
^[^[ 	^[
 ^[ ^[ ^[ ^[ ^[ ^[ 
^[BM
M!M48MGKM	M*
H>J
>J>J 	>J
 >J >J >J >J 
>JB


!
/4
?D
	
 UUU U 	U
 U 
U*TTT T 	T
 T 
T,++$++DH+	+r:   