
    Lpj)              	         S SK Jr  S SKJrJr  S SKJrJr  S SKJ	r	J
r
  S SKJrJr  S SKJr  S SKJrJr  \(       a  S SKJrJrJrJr  S S	KJrJr  \R6                  \R8                  \R:                  \R<                  \R>                  \R@                  1r!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%g)    )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               4   Sn
[        S X4 5       5      (       a8  S[        [        U 5      5       S[        [        U5      5       S3n[        U5      eU R                  UR                  pX:w  a  [        SX5        [        XU	S9u  p[        UUUUUUUUUUS9
  g	)
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  f   #    U  H'  n[        U5      =(       d    [        U5      (       + v   M)     g 7f)Nr
   ).0objs     Z/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/narwhals/testing/asserts/frame.py	<genexpr>%assert_frame_equal.<locals>.<genexpr>r   s-       C #3'E+@+EFF s   /1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_equalr4      s    h 
 =  
*4:67 8+DK89 :PP 	 n //1E1Ez#$=yU7WUJ'-!-    c                Z   [        U [        5      (       a  [        U[        5      (       a  X4$ [        U [        5      (       a7  [        U[        5      (       a"  U R                  U5      UR                  U5      4$ [	        SS[        U 5      R                  [        U5      R                  S9  g )Ninputszunexpected input types)r%   r&   )
isinstancer   r	   collectr   r)   __name__)r%   r&   r   s      r"   r,   r,      s     $	""z%'C'C{$	""z%'C'C||G$emmG&<<< $Z  5k""	r5   c               r   [        XXTS9  [        U 5      [        U5      pX:w  a  [        SX5        U
S:X  a  g U R                  nU(       a
  U[        ;  aq  UR                  5        VVs/ s H  u  pUR                  5       (       a  M  UPM      nnnU(       d  Sn[        U5      eU R                  U5      n UR                  U5      nUR                  5        H7  nU R                  U5      nUR                  U5      n [        UUSSSUUUU	S9	  M9     g s  snnf ! [         a    [        SUUS	U S
3S9   M_  f = f)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-      s9     , d)SZi#$A8W1}++K-A!A
 ,7+<+<+>X+>KDeooFW4+>X^C%c**yy!

7#%%'x0((2	"! '#5
	 ( Y2  	'2!# "8*A.		s   (DD<DD65D6c               D   U R                   UR                   pTXE:X  a  gUR                  5       UR                  5       pv[        U5      [        U5      p[        UR	                  U	5      5      =n
(       a  [        SUU	U
 S3S9  [        U	R	                  U5      5      =n(       a  [        SUU	U S3S9  U(       a  Xg:w  a
  [        SXgS9  U(       aM  U(       a  UR                  5       OU Vs/ s H  oU   PM	     snnUR                  5       =o:w  a  [        SXS9  gggs  snf )	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)rC   rI   setsorted
differencer   dtypes)r%   r&   r   r   lschemarschemalnamesrnameslsetrsetleft_not_in_rightright_not_in_leftrR   rdtypesldtypess                  r"   rA   rA      s%    {{ELLW ]]_gmmoFVc&k$"4??4#8999#../q1		
 #4??4#8999#../q1		
 f.#6V	
  " NN4:;F(#F; 	 ~~''G3',7 4  <s   *D)r%   DataFrameT | LazyFrameTr&   rf   r   boolr   rg   r   rg   r   rg   r   floatr   rh   r   rg   r   +IntoBackend[Polars | Pandas | Arrow] | NonereturnNone)r%   rf   r&   rf   r   ri   rj   z%tuple[DataFrame[Any], DataFrame[Any]])r%   r   r&   r   r'   r   r   rg   r   rg   r   rg   r   rg   r   rh   r   rh   r   rg   rj   rk   )
r%   r   r&   r   r   rg   r   rg   rj   rk   )&
__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DASKrD   r4   r,   r-   rA    r5   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.	.r5   