
    q-Phi#              	         d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ  ed	d
d          ddddddddd)d            Zd*d Zd+d#Zd,d&Z ed	d
d          ddddddddd)d'            Zd(S )-    )annotations)cast)deprecate_renamed_parameter)	DataFrame)InvalidOperationError)	LazyFrame)_assert_series_values_equal)raise_assertion_errorcheck_dtypecheck_dtypesz0.20.31)versionTFgh㈵>g:0yE>)check_row_ordercheck_column_orderr   check_exactrtolatolcategorical_as_strleftDataFrame | LazyFramerightr   boolr   r   r   floatr   r   returnNonec          
        d}	t          | |          }
|
rdnd}t          | ||||           |
r(|                                 |                                }} t          t          |           t          t          |          }} | j        |j        k    rt          |d| j        |j                   |st          | |          \  } }| j        D ]}| 	                    |          |	                    |          }}	 t          ||d||||           D# t          $ rE}t          |d||                                |                                |           Y d	}~d	}~ww xY wd	S )
a  
    Assert that the left and right frame are equal.

    Raises a detailed `AssertionError` if the frames 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 DataFrame or LazyFrame to compare.
    right
        The second DataFrame or LazyFrame to compare.
    check_row_order
        Requires row order to match.
    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 `rtol` and `atol`).
        Only affects columns with a Float data type.
    rtol
        Relative tolerance for inexact checking. Fraction of 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

    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_frame_equal
    >>> df1 = pl.DataFrame({"a": [1, 2, 3]})
    >>> df2 = pl.DataFrame({"a": [1, 5, 3]})
    >>> assert_frame_equal(df1, df2)
    Traceback (most recent call last):
    ...
    AssertionError: DataFrames are different (value mismatch for column 'a')
    [left]:  [1, 2, 3]
    [right]: [1, 5, 3]
    T
LazyFrames
DataFrames)r   r   objectsznumber of rows does not match)check_orderr   r   r   r   zvalue mismatch for column )causeN)_assert_correct_input_type_assert_frame_schema_equalcollectr   r   heightr
   _sort_dataframescolumns
get_columnr	   AssertionErrorto_list)r   r   r   r   r   r   r   r   r   __tracebackhide__lazyr   cs_lefts_rightexcs                   \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/testing/asserts/frame.pyassert_frame_equalr1      s   L %dE22D"4llG-!     6llnnemmooey$''i)?)?%D{el""4dk5<	
 	
 	
  4&tU33e\  //!,,e.>.>q.A.A	' '#5      	 	 	!2Q22  !!        	 s   6D
E;EEc                &   d}t          | t                    rt          |t                    rdS t          | t                    rt          |t                    rdS t          ddt	          |           j        t	          |          j                   d S )NTFinputszunexpected input types)
isinstancer   r   r
   type__name__)r   r   r*   s      r0   r!   r!      s     $	"" 

z%'C'C 

u	D)	$	$ 
E9)E)E 
t$JJKK 		
 	
 	
 	
 	
    r   strc               t   d}|                                  |                                 ck    rd S                                                                 k    r^fdD             x}r d|d|d d          d}t          |          fdD             }d|d|d d          d	}t          |          |r8t                    t                    }
}	|	|
k    rd
}t	          |||	|
           |r<t                    t                    }}|s||k    rd}t	          ||||           d S d S d S )NTc                    g | ]}|v|	S  r;   ).0r,   right_schemas     r0   
<listcomp>z._assert_frame_schema_equal.<locals>.<listcomp>   s#    NNNA8M8Ma8M8M8Mr7   zcolumns z	 in left z, but not in rightc                    g | ]}|v|	S r;   r;   )r<   r,   left_schemas     r0   r>   z._assert_frame_schema_equal.<locals>.<listcomp>   s#    NNNA+9M9Ma9M9M9Mr7   z
 in right z, but not in leftz!columns are not in the same orderzdtypes do not match)collect_schemakeysr(   listr
   dict)r   r   r   r   r   r*   left_not_rightmsgright_not_leftleft_columnsright_columnsdetailleft_schema_dictright_schema_dictrA   r=   s                 @@r0   r"   r"      s     $ 3 3 5 5u7K7K7M7MK l"" \..0000NNNNNNNN> 	&X^XXXXXC %%%NNNNNNNNX^XX"XXXC %%% P&*;&7&7l9K9Km=((8F!'6<OOO X.2;.?.?lASAS+ 	X!15F!F!F*F!'63CEVWWWWW	X X!F!Fr7   r   tuple[DataFrame, DataFrame]c                    | j         }	 |                     |          } |                    |          }n$# t          $ r}d}t          |          |d }~ww xY w| |fS )NzCcannot set `check_row_order=False` on frame with unsortable columns)r&   sortr   	TypeError)r   r   byr/   rG   s        r0   r%   r%      sl    	B&yy}}

2  & & &Snn#%& ;s   *4 
AAAc                   d}	t          | |          }
	 t          | ||||||||	  	         |
rdnd}| d}t          |          # t          $ r Y dS w xY w)a  
    Assert that the left and right frame 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 DataFrame or LazyFrame to compare.
    right
        The second DataFrame or LazyFrame to compare.
    check_row_order
        Requires row order to match.
    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 `rtol` and `atol`).
        Only affects columns with a Float data type.
    rtol
        Relative tolerance for inexact checking. Fraction of 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

    Examples
    --------
    >>> from polars.testing import assert_frame_not_equal
    >>> df1 = pl.DataFrame({"a": [1, 2, 3]})
    >>> df2 = pl.DataFrame({"a": [1, 2, 3]})
    >>> assert_frame_not_equal(df1, df2)
    Traceback (most recent call last):
    ...
    AssertionError: DataFrames are equal (but are expected not to be)
    T)	r   r   r   r   r   r   r   r   r   r   r   z' are equal (but are expected not to be)N)r!   r1   r(   )r   r   r   r   r   r   r   r   r   r*   r+   r   rG   s                r0   assert_frame_not_equalrT      s    x %dE22D"1+%#1
	
 
	
 
	
 
	
 #'8,,LAAAS!!!    s   A 
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   r8   r   r   )r   r   r   r   r   rN   )
__future__r   typingr   polars._utils.deprecationr   polars.dataframer   polars.exceptionsr   polars.lazyframer   polars.testing.asserts.seriesr	   polars.testing.asserts.utilsr
   r1   r!   r"   r%   rT   r;   r7   r0   <module>r]      s   " " " " " "       A A A A A A & & & & & & 3 3 3 3 3 3 & & & & & & E E E E E E > > > > > > ]NINNN
 !#$q q q q q ONqh
 
 
 
$$X $X $X $XN    ]NINNN
 !#$O" O" O" O" O" ONO" O" O"r7   