data_algebra/test_util.py
def equivalent_frames(
    a,
    b,
    *,
    float_tol: float = 1e-8,
    check_column_order: bool = False,
    cols_case_sensitive: bool = False,
    check_row_order: bool = False,
    local_data_model=None,
) -> bool:
    """return False if the frames are equivalent (up to column re-ordering and possible row-reordering).
    Ignores indexing."""
    # leave in extra checks as this is usually used by test code
    if local_data_model is None:
        local_data_model = data_algebra.default_data_model
    assert isinstance(a, local_data_model.pd.DataFrame)
    assert isinstance(b, local_data_model.pd.DataFrame)
    if a.shape != b.shape:
        return False
    if a.shape[1] < 1:
        return True
    a = a.reset_index(drop=True, inplace=False)
    b = b.reset_index(drop=True, inplace=False)
    if not cols_case_sensitive:
        a.columns = [c.lower() for c in a.columns]
        a = a.reset_index(drop=True)
        b.columns = [c.lower() for c in b.columns]
        b = b.reset_index(drop=True)
    a_columns = [c for c in a.columns]
    b_columns = [c for c in b.columns]
    if set(a_columns) != set(b_columns):
        return False
    if check_column_order:
        if not numpy.all([a.columns[i] == b.columns[i] for i in range(a.shape[0])]):
            return False
    else:
        # re-order b into a's column order
        b = b[a_columns]
        b = b.reset_index(drop=True)
    for c in a_columns:
        if local_data_model.can_convert_col_to_numeric(
            a[c]
        ) != local_data_model.can_convert_col_to_numeric(b[c]):
            return False
    if a.shape[0] < 1:
        return True
    if not check_row_order:
        a = a.sort_values(by=a_columns)
        a = a.reset_index(drop=True)
        b = b.sort_values(by=a_columns)
        b = b.reset_index(drop=True)
    for c in a_columns:
        ca = a[c]
        cb = b[c]
        if (ca is None) != (cb is None):
            return False
        if ca is not None:
            if len(ca) != len(cb):
                return False
            ca_null = ca.isnull()
            cb_null = cb.isnull()
            if (ca_null is None) != (cb_null is None):
                return False
            if not numpy.all(ca_null == cb_null):
                return False
            if not numpy.all(ca_null):
                ca = ca[ca_null == False]
                cb = cb[cb_null == False]
                if local_data_model.can_convert_col_to_numeric(a[c]):
                    ca = numpy.asarray(ca, dtype=float)
                    cb = numpy.asarray(cb, dtype=float)
                    dif = numpy.abs(ca - cb) / numpy.maximum(numpy.maximum(ca, cb), 1)
                    if numpy.max(dif) > float_tol:
                        return False
                else:
                    if not numpy.all(ca == cb):
                        return False
    return True
return False if the frames are equivalent (up to column re-ordering and possible row-reordering).
    Ignores indexing.
return False if the frames are equivalent (up to column re-ordering and possible row-reordering).
Ignores indexing.
return False if the frames are equivalent ( up to column re - ordering and possible row - reordering ) . Ignores indexing .
def equivalent_frames(
    a,
    b,
    *,
    float_tol: float = 1e-8,
    check_column_order: bool = False,
    cols_case_sensitive: bool = False,
    check_row_order: bool = False,
    local_data_model=None,
) -> bool:
    if local_data_model is None:
        local_data_model = data_algebra.default_data_model
    assert isinstance(a, local_data_model.pd.DataFrame)
    assert isinstance(b, local_data_model.pd.DataFrame)
    if a.shape != b.shape:
        return False
    if a.shape[1] < 1:
        return True
    a = a.reset_index(drop=True, inplace=False)
    b = b.reset_index(drop=True, inplace=False)
    if not cols_case_sensitive:
        a.columns = [c.lower() for c in a.columns]
        a = a.reset_index(drop=True)
        b.columns = [c.lower() for c in b.columns]
        b = b.reset_index(drop=True)
    a_columns = [c for c in a.columns]
    b_columns = [c for c in b.columns]
    if set(a_columns) != set(b_columns):
        return False
    if check_column_order:
        if not numpy.all([a.columns[i] == b.columns[i] for i in range(a.shape[0])]):
            return False
    else:
        b = b[a_columns]
        b = b.reset_index(drop=True)
    for c in a_columns:
        if local_data_model.can_convert_col_to_numeric(
            a[c]
        ) != local_data_model.can_convert_col_to_numeric(b[c]):
            return False
    if a.shape[0] < 1:
        return True
    if not check_row_order:
        a = a.sort_values(by=a_columns)
        a = a.reset_index(drop=True)
        b = b.sort_values(by=a_columns)
        b = b.reset_index(drop=True)
    for c in a_columns:
        ca = a[c]
        cb = b[c]
        if (ca is None) != (cb is None):
            return False
        if ca is not None:
            if len(ca) != len(cb):
                return False
            ca_null = ca.isnull()
            cb_null = cb.isnull()
            if (ca_null is None) != (cb_null is None):
                return False
            if not numpy.all(ca_null == cb_null):
                return False
            if not numpy.all(ca_null):
                ca = ca[ca_null == False]
                cb = cb[cb_null == False]
                if local_data_model.can_convert_col_to_numeric(a[c]):
                    ca = numpy.asarray(ca, dtype=float)
                    cb = numpy.asarray(cb, dtype=float)
                    dif = numpy.abs(ca - cb) / numpy.maximum(numpy.maximum(ca, cb), 1)
                    if numpy.max(dif) > float_tol:
                        return False
                else:
                    if not numpy.all(ca == cb):
                        return False
    return True
def equivalent_frames ( a , b , * , float_tol : float = 1e-8 , check_column_order : bool = False , cols_case_sensitive : bool = False , check_row_order : bool = False , local_data_model = None , ) -> bool : if local_data_model is None : local_data_model = data_algebra . default_data_model assert isinstance ( a , local_data_model . pd . DataFrame ) assert isinstance ( b , local_data_model . pd . DataFrame ) if a . shape != b . shape : return False if a . shape [ 1 ] < 1 : return True a = a . reset_index ( drop = True , inplace = False ) b = b . reset_index ( drop = True , inplace = False ) if not cols_case_sensitive : a . columns = [ c . lower ( ) for c in a . columns ] a = a . reset_index ( drop = True ) b . columns = [ c . lower ( ) for c in b . columns ] b = b . reset_index ( drop = True ) a_columns = [ c for c in a . columns ] b_columns = [ c for c in b . columns ] if set ( a_columns ) != set ( b_columns ) : return False if check_column_order : if not numpy . all ( [ a . columns [ i ] == b . columns [ i ] for i in range ( a . shape [ 0 ] ) ] ) : return False else : b = b [ a_columns ] b = b . reset_index ( drop = True ) for c in a_columns : if local_data_model . can_convert_col_to_numeric ( a [ c ] ) != local_data_model . can_convert_col_to_numeric ( b [ c ] ) : return False if a . shape [ 0 ] < 1 : return True if not check_row_order : a = a . sort_values ( by = a_columns ) a = a . reset_index ( drop = True ) b = b . sort_values ( by = a_columns ) b = b . reset_index ( drop = True ) for c in a_columns : ca = a [ c ] cb = b [ c ] if ( ca is None ) != ( cb is None ) : return False if ca is not None : if len ( ca ) != len ( cb ) : return False ca_null = ca . isnull ( ) cb_null = cb . isnull ( ) if ( ca_null is None ) != ( cb_null is None ) : return False if not numpy . all ( ca_null == cb_null ) : return False if not numpy . all ( ca_null ) : ca = ca [ ca_null == False ] cb = cb [ cb_null == False ] if local_data_model . can_convert_col_to_numeric ( a [ c ] ) : ca = numpy . asarray ( ca , dtype = float ) cb = numpy . asarray ( cb , dtype = float ) dif = numpy . abs ( ca - cb ) / numpy . maximum ( numpy . maximum ( ca , cb ) , 1 ) if numpy . max ( dif ) > float_tol : return False else : if not numpy . all ( ca == cb ) : return False return True
return False if the frames are equivalent (up to column re-ordering and possible row-reordering).
return False if the frames are equivalent ( up to column re - ordering and possible row - reordering ) .
"""return False if the frames are equivalent (up to column re-ordering and possible row-reordering).
    Ignores indexing.""" # leave in extra checks as this is usually used by test code # re-order b into a's column order
a
b
float_tol
float
check_column_order
bool
cols_case_sensitive
bool
check_row_order
bool
local_data_model