
    Lpj+                       % S SK Jr  S SKJr  S SKJrJr  S SKJr  S SK	J
r
  S SKJrJrJrJrJrJr  S SKJr  S SKJr  \(       a.  S S	KJr  S S
KJr  S SKJr  S SKJrJr  \\\   \\   /S4   rS\S'   SSSSSSSS.                   SS jjr           SS jr!SS jr"                S S jr#          S!S jr$            S"S jr%            S#S jr&        S$S jr'g)%    )annotations)partial)TYPE_CHECKINGAny)qualified_type_nameis_narwhals_series)ArrayBooleanCategoricalListStringStruct)
new_series)raise_series_assertion_error)Callable)	TypeAlias)Series)IntoSeriesTSeriesTNr   CheckFnTFgh㈵>g:0yE>check_dtypescheck_namescheck_ordercheck_exactrel_tolabs_tolcategorical_as_strc          
        Sn	[        S X4 5       5      (       a8  S[        [        U 5      5       S[        [        U5      5       S3n
[        U
5      e[	        XX#S9  U(       dK  U R
                  R                  5       (       a  Sn
[        U
5      eU R                  5       UR                  5       p[        X5      u  pU(       d  U R
                  R                  5       (       d  [        UUUUUUUS9  g
[        XXgS	9  g
)un  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  B   #    U  H  n[        U5      (       + v   M     g 7f)Nr   ).0objs     [/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/narwhals/testing/asserts/series.py	<genexpr>&assert_series_equal.<locals>.<genexpr>U   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DlT::!!UC%c**iik5::<e.t;I$**--//%#1	
 	")Z    c               `   U R                   UR                   pTXE:w  a  [        SXE5        [        U 5      [        U5      pvXg:w  a  [        SXg5        U R                  UR                  pU(       a  X:w  a  [        SX5        U R                  UR                  pU(       a  X:w  a  [        SX5        ggg)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*   w   s     !//1E1Ez$%>	Vd)SZi$%6L"jj%++
1$%5zO IIuzzzy.$_iL /{r:   c                   U R                  5       UR                  5       p2U R                  5       UR                  5       pTX#:w  d  XE:g  R                  5       (       a  [        SX#5        U R	                  U) 5      UR	                  U) 5      4$ )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/      su    (,(95;K;K;M%&*llnemmoO*~/P.U.U.W.W$!?	
 ;;'6F)GGGr:   c                  U R                   nU R                  UR                  pUR                  5       (       a  U R                  USSSS9) n
GO[	        U[
        [        45      (       aU  [	        U	[
        [        45      (       a:  X:X  a5  [        [        USSUUUUS9n[        XXUS9  [        SS/[        5       US9n
O[	        U[        5      (       aJ  [	        U	[        5      (       a5  [        [        SSSUUUUS9n[        XXUS9  [        SS/[        5       US9n
ON[	        U[        5      (       a5  [	        U	[        5      (       a   [        XUS	9n[        SU/[        5       US9n
OX:g  n
U
R!                  5       (       a  [#        S
X5        gg)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%++  "]]5!QSW]XX:t}--*[5RV-2X2X

#%#1	
 	jQ&rE7')YW	J	'	'J{F,K,K#1	
 	d:XN&rE7')YW	J	,	,K1U1U (,>

 'GIy
 !M$%;TI r:   c                   U R                  XUSS9) nUR                  5       (       a,  [        SU R                  U5      UR                  U5      5        gg)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_     D '   $)KK)*LL*+	
 r:   c                    U R                   n [        XSS9 H4  u  pgU" [        SXbR                  US9[        SXsR                  US95        M6     g ! [         a    [        SX5         g f = f)NTstrictrS   )valuesr+   rT   znested value mismatch)r<   zipr   innerAssertionErrorr   )r7   r8   rC   rD   rR   implleft_val	right_vals           r$   rY   rY      sv     ##DU#&yT#JH2h6F6FPTU2i7H7HRVW $K
  U$%<iTUs   AA A*)A*c                ,    [        UR                  UR                  SS9 HT  u  pVU" U R                  R                  UR                  5      UR                  R                  UR                  5      5        MV     g ! [
         a    [        SX5         g f = f)NTra   rU   )rd   fieldsstructfieldr>   rf   r   )r7   r8   rC   rD   rR   
left_fieldright_fields          r$   rZ   rZ      s    	T'*{11$(
#J   &&z7!!''(8(89(
  T$%;YSTs   A7A: :BBc                   U(       a1  U R                  [        5       5      UR                  [        5       5      p X:g  R                  5       $ ! [         a  nSn[	        U5      UeSnAff = f)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'   	Exceptionrf   )r7   r8   r   excr6   s        r$   r[   r[     s]      )vx 8*//&(:S:+',,.. +JS!s*+s   A 
A)A$$A))r3   Series[IntoSeriesT]r4   rt   r   boolr   ru   r   ru   r   ru   r   floatr   rv   r   ru   returnNone)
r3   r   r4   r   r   ru   r   ru   rw   rx   )r3   r   r4   r   rw   ztuple[SeriesT, SeriesT])r3   r   r4   r   r   ru   r   ru   r   rv   r   rv   r   ru   rw   rx   )
r3   r   r4   r   r   rv   r   rv   rw   rx   )r7   r   r8   r   rC   List | ArrayrD   ry   rR   r   rw   rx   )r7   r   r8   r   rC   r   rD   r   rR   r   rw   rx   )r7   r   r8   r   r   ru   rw   ru   )(
__future__r   	functoolsr   typingr   r   narwhals._utilsr   narwhals.dependenciesr	   narwhals.dtypesr
   r   r   r   r   r   narwhals.functionsr   narwhals.testing.asserts.utilsr   collections.abcr   r   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0++$++DH+	+r:   