
    [i)              	         d dl mZ d dlmZmZ d dlmZmZ d dlm	Z	m
Z
 d dlmZmZ d dlmZ d dlmZmZ erd dlmZmZmZmZ d d	lmZmZ ej6                  ej8                  ej:                  ej<                  ej>                  ej@                  hZ!d
d
d
dddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ"	 	 	 	 	 	 	 	 ddZ#	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ$	 	 	 	 	 	 	 	 	 	 ddZ%y)    )annotations)TYPE_CHECKINGAny)Implementationqualified_type_name)	DataFrame	LazyFrameis_narwhals_dataframeis_narwhals_lazyframe)assert_series_equal)raise_assertion_errorraise_frame_assertion_error)ArrowIntoBackendPandasPolars)
DataFrameT
LazyFrameTTFgh㈵>g:0yE>N)check_row_ordercheck_column_ordercheck_dtypescheck_exactrel_tolabs_tolcategorical_as_strbackendc               @   d}
t        d | |fD              r8dt        t        |              dt        t        |             d}t        |      | j                  |j                  }}||k7  rt        d||       t        | ||	      \  }}t        ||||||||||
       y	)
uG  Assert that the left and right frames are equal.

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

    Warning:
        1. In the case of backends that do not guarantee the row order, such as DuckDB,
            Ibis, PySpark, and SQLFrame, `check_row_order` argument is ignored and the
            comparands are sorted by all the columns regardless.
        2. In the case of lazy backends a [`collect(...)`](lazyframe.md#narwhals.dataframe.LazyFrame.collect)
            operation is triggered.

    Arguments:
        left: The first DataFrame or LazyFrame to compare.
        right: The second DataFrame or LazyFrame to compare.
        check_row_order: Requires row order to match.

            This flag is ignored for backends that do not guarantee row order such as
            DuckDB, Ibis, PySpark, SQLFrame.
        check_column_order: Requires column order to match.
        check_dtypes: Requires data types to match.
        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. Fraction of 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.
        backend: Allows to specify which eager backend to collect to.
            Check out [`narwhals.LazyFrame.collect`](lazyframe.md#narwhals.dataframe.LazyFrame.collect)
            for more information.

    Examples:
        >>> import polars as pl
        >>> import narwhals as nw
        >>> from narwhals.testing import assert_frame_equal
        >>>
        >>> left_native = pl.LazyFrame({"a": [1, 2, 3]})
        >>> right_native = pl.LazyFrame({"a": [1, 5, 3]})
        >>> left = nw.from_native(left_native)
        >>> right = nw.from_native(right_native)
        >>> assert_frame_equal(left, right)  # doctest: +ELLIPSIS
        Traceback (most recent call last):
            ...
        AssertionError: DataFrames are different (value mismatch for column "a")
        [left]:
        ┌─────────────────┐
        | Narwhals Series |
        |-----------------|
        |shape: (3,)      |
        |Series: 'a' [i64]|
        |[                |
        |        1        |
        |        2        |
        |        3        |
        |]                |
        └─────────────────┘
        [right]:
        ┌─────────────────┐
        | Narwhals Series |
        |-----------------|
        |shape: (3,)      |
        |Series: 'a' [i64]|
        |[                |
        |        1        |
        |        5        |
        |        3        |
        |]                |
        └─────────────────┘
    Tc              3  N   K   | ]  }t        |      xs t        |         y w)Nr
   ).0objs     o/var/www/html/userprofiledev.eatanceapp.com/venv/lib/python3.12/site-packages/narwhals/testing/asserts/frame.py	<genexpr>z%assert_frame_equal.<locals>.<genexpr>r   s+       C #3'E+@+EF s   #%zOExpected `narwhals.DataFrame` or `narwhals.LazyFrame` instance, found:
[left]: z

[right]: z

Hint: Use `nw.from_native(obj, allow_series=False)` to convert each native object into a `narwhals.DataFrame` or `narwhals.LazyFrame` first.zimplementation mismatch)r   )
leftrightimplr   r   r   r   r   r   r   N)anyr   type	TypeErrorimplementationr   _check_correct_input_type_assert_dataframe_equal)r$   r%   r   r   r   r   r   r   r   r   __tracebackhide__msg	left_impl
right_impl
left_eagerright_eagers                   r"   assert_frame_equalr3      s    h 
 %= 
*4:67 8+DK89 :PP 	 n //1E1EzIJ#$=y*U7eWUJ'-!-    c                :   t        | t              rt        |t              r| |fS t        | t              r2t        |t              r"| j                  |      |j                  |      fS t	        ddt        |       j                  t        |      j                         y )Ninputszunexpected input types)r$   r%   )
isinstancer   r	   collectr   r(   __name__)r$   r%   r   s      r"   r+   r+      sy     $	"z%'CU{$	"z%'C||G$emmG&<<< $Z  5k""	r4   c               Z   t        | |||       t        |       t        |      }}
|
|k7  rt        d|
|       |
dk(  ry | j                  }|r|t        vrd|j                         D cg c]  \  }}|j                         r| }}}|sd}t        |      | j                  |      } |j                  |      }|j                         D ]9  }| j                  |      }|j                  |      }	 t        ||ddd||||		       ; y c c}}w # t        $ r t        d||d	| d
       Y aw xY w)N)r   r   zheight (row count) mismatchr   zJ`check_row_order=False` is not supported (yet) with only nested data type.FT)r   check_namescheck_orderr   r   r   r   zvalue mismatch for columnz "")detailr$   r%   detail_suffix)_check_schema_equallenr   schemaGUARANTEES_ROW_ORDERitems	is_nestedNotImplementedErrorsortnames
get_columnr   AssertionError)r$   r%   r&   r   r   r   r   r   r   r   left_len	right_lenleft_schemanamedtypesort_byr.   col_name_series_left_series_rights                       r"   r,   r,      sF     e,CU d)SZiH9#$A8YW1}++K-A!A
 ,7+<+<+>X+>KD%eooFW4+>X^C%c**yy!

7#%%'x0((2	"! '#5
	 ( Y2  	'2!# "8*A.		s   'D D.DD*)D*c               0   | j                   |j                   }}||k(  ry|j                         |j                         }}t        |      t        |      }	}t        |j	                  |	            x}
rt        d||	|
 d       t        |	j	                  |            x}rt        d||	| d       |r||k7  rt        d||       |rJ|j                         }|r|j                         n|D cg c]  }||   	 c}}||k7  rt        d||       yyyc c}w )	zCompares DataFrame schema based on specified criteria.

    Adapted from https://github.com/pola-rs/polars/blob/afdbf3056d1228cf493901e45f536b0905cec8ea/crates/polars-testing/src/asserts/utils.rs#L667-L698
    Nzin left, but not in right )r>   r$   r%   detail_prefixzin right, but not in leftz!columns are not in the same order)r>   r$   r%   zdtypes do not match)rB   rH   setsorted
differencer   dtypes)r$   r%   r   r   lschemarschemalnamesrnameslsetrsetleft_not_in_rightright_not_in_leftldtypesrQ   rdtypess                  r"   r@   r@      s7    {{ELLWG ']]_gmmoFFVc&k$D"4??4#8999#../q1		
 #4??4#8999#../q1		
 f.#6V6	
 .." " NN4:;F'(#F; 	 g',7'  
 <s   .D)r$   DataFrameT | LazyFrameTr%   re   r   boolr   rf   r   rf   r   rf   r   floatr   rg   r   rf   r   +IntoBackend[Polars | Pandas | Arrow] | NonereturnNone)r$   re   r%   re   r   rh   ri   z%tuple[DataFrame[Any], DataFrame[Any]])r$   r   r%   r   r&   r   r   rf   r   rf   r   rf   r   rf   r   rg   r   rg   r   rf   ri   rj   )
r$   r   r%   r   r   rf   r   rf   ri   rj   )&
__future__r   typingr   r   narwhals._utilsr   r   narwhals.dataframer   r	   narwhals.dependenciesr   r   narwhals.testing.asserts.seriesr   narwhals.testing.asserts.utilsr   r   narwhals._typingr   r   r   r   narwhals.typingr   r   PANDASMODINCUDFPYARROWPOLARSDASKrC   r3   r+   r,   r@    r4   r"   <module>r{      s   " % ? 3 N ?
 CC6   !#$;?t
!t"t 	t
 t t t t t t 9t 
tn
!" 9 +	(@
@@ @
 @ @ @ @ @ @ @ 
@F/
/'/:>/TX/	/r4   