L in+UddlmZddlmZddlmZmZmZddlm Z m Z ddl m Z ddl mZmZmZmZmZmZddlmZddlmZer(dd lmZdd lmZdd lmZmZeeeeegd fZd e d<dddddddd ddZ! ddZ"ddZ# ddZ$ d dZ% d!dZ& d"dZ' d#dZ(y )$) annotations)partial) TYPE_CHECKINGAnyCallable)qualified_type_name zip_strictis_narwhals_series)ArrayBoolean CategoricalListStringStruct) new_series)raise_series_assertion_error) TypeAlias)Series) IntoSeriesTSeriesTNrCheckFnTFgh㈵>g:0yE> check_dtypes check_names check_order check_exactrel_tolabs_tolcategorical_as_strc d} td||fDr8dtt|dtt|d} t| t |||||sG|j j r d} t| |j|j}}t||\} } |s|j jst| | |||||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 | └───────────────┘ Tc34K|]}t| yw)Nr ).0objs e/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/narwhals/testing/asserts/series.py z&assert_series_equal..Ts @3!#& & @sz4Expected `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.)rrzA`check_order=False` is not supported (yet) with nested data type.)rrrrr )rrN) anyrtype TypeError_check_metadatadtype is_nestedNotImplementedErrorsort_check_null_valuesis_float_check_exact_values_check_approximate_values) leftrightrrrrrrr __tracebackhide__msg left_vals right_valss r%assert_series_equalr9sz @4- @@ *4:678+DK89:5 5 nD%l T  ::   !UC%c* *iik5:: :Vd)SZiH9$%6)L"jj%++ J k1$%5z;O IIuzzzIyJ.$_iL/{r:c|j|j}}|j|j}}||k7s||k7jr td|||j ||j |fS)z8Check null value consistency and return non-null values.znull value mismatch) null_countis_nullr'rfilter)r3r4left_null_countright_null_countleft_null_maskright_null_masks r%r/r/s~(,(95;K;K;M%O&*llnemmoON**~/P.U.U.W$ !?4D  ;; '6F)G GGr:c |j}|j|j} }|jr|j|ddd} nt |t t fr[t | t t frE|| k(r@tt|dd||||} t|||| | tddgt|} nt |trPt | tr@ttddd||||} t|||| | tddgt|} nLt |tr7t | tr't||| } td| gt|} n||k7} | j!rt#d ||y y ) z2Check exact value equality for various data types.rTrr nans_equalFr)check_fn)r+backend)r exact value mismatchN)r<r+ is_numericis_close isinstancer rrr9_check_list_likerr r _check_structr_check_categoricalr'r) r3r4rrrrr r?rCrDis_not_equal_maskrR _not_equals r%r1r1s##I"jj%++ J"]]5!QSW]XX:t}-*[5RV-2X  # %#1   uj+Q&rE7')YW J 'J{F,K #1   dE:{XN&rE7')YW J ,K1U( %,> '  GIy !EM$%;T5Ir:c|j|||d}|jr,td|j||j|yy)z0Check approximate value equality with tolerance.TrPzvalues not within toleranceN)rWr'rrJ)r3r4rris_not_close_masks r%r2r2s^ wD'$ ) KK) * LL* + r:c |j} t||D]<\}}|td||j|td||j|>y#t$rt d||YywxYw)NrS)valuesr+rTznested value mismatch)r<r rinnerAssertionErrorr)r7r8rCrDrRimplleft_val right_vals r%rYrYs  # #DU#-i#D  Hi 2hj6F6FPTU2i{7H7HRVW   U$%rcr)r7r8rCrDrR left_field right_fields r%rZrZsT'1*2C2C[EWEW'X  #J   &&z7!!'' (8(89   T$%;Y STsA7A::BBc|r2|jt|jt}} ||k7jS#t$r}d}t ||d}~wwxYw)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)castrr' Exceptionrc)r7r8r excr6s r%r[r[sa )vx 8*//&(:S: +Z',,.. +JS!s*+sA A%A  A%)r3Series[IntoSeriesT]r4rqrboolrrrrrrrrrrfloatrrsr rrreturnNone) r3rr4rrrrrrrrtru)r3rr4rrtztuple[SeriesT, SeriesT])r3rr4rrrrrrrrrsrrsr rrrtru) r3rr4rrrsrrsrtru) r7rr8rrC List | ArrayrDrvrRrrtru) r7rr8rrCrrDrrRrrtru)r7rr8rr rrrtrr)) __future__r functoolsrtypingrrrnarwhals._utilsrr narwhals.dependenciesr narwhals.dtypesr r rrrrnarwhals.functionsrnarwhals.testing.asserts.utilsrtyping_extensionsrnarwhals.seriesrnarwhals.typingrrr__annotations__r9r*r/r1r2rYrZr[r:r%rsQ"//;4MM)G+&4!6#;s "J >J >J >J  >J  >J>J>J >JB    !  /4  ?D     UUUU U  U  U*TTTT T  T  T,++$++DH+ +r: