data_algebra/util.py
def check_columns_appear_compatible(d_left, d_right, *, columns: Optional[Iterable[str]] = None
                                    ) -> Optional[Dict[str, Tuple[type, type]]]:
    """
    Check if columns have compatible types

    :param d_left: pandas dataframe to check
    :param d_right: pandas dataframe to check
    :param columns: columns to check, None means check all columns
    :return: None if compatible, else dictionary of mismatches
    """
    if columns is None:
        columns = [c for c in d_left.columns]
        assert set(d_left.columns) == set(d_right.columns)
    else:
        columns = [c for c in columns]
    assert len(set(columns) - set(d_left.columns)) == 0
    assert len(set(columns) - set(d_right.columns)) == 0
    left_types = data_algebra.util.guess_column_types(d_left, columns=columns)
    if (left_types is None) or (len(left_types) <= 0):
        return None
    right_types = data_algebra.util.guess_column_types(d_right, columns=columns)
    if (right_types is None) or (len(right_types) <= 0):
        return None
    mismatches = dict()
    for c in columns:
        if not compatible_types([left_types[c], right_types[c]]):
            mismatches[c] = (left_types[c], right_types[c])
    if len(mismatches) > 0:
        return mismatches
    return None

    Check if columns have compatible types

    :param d_left: pandas dataframe to check
    :param d_right: pandas dataframe to check
    :param columns: columns to check, None means check all columns
    :return: None if compatible, else dictionary of mismatches
    
Check if columns have compatible types
Check if columns have compatible types
def check_columns_appear_compatible(d_left, d_right, *, columns: Optional[Iterable[str]] = None
                                    ) -> Optional[Dict[str, Tuple[type, type]]]:
    if columns is None:
        columns = [c for c in d_left.columns]
        assert set(d_left.columns) == set(d_right.columns)
    else:
        columns = [c for c in columns]
    assert len(set(columns) - set(d_left.columns)) == 0
    assert len(set(columns) - set(d_right.columns)) == 0
    left_types = data_algebra.util.guess_column_types(d_left, columns=columns)
    if (left_types is None) or (len(left_types) <= 0):
        return None
    right_types = data_algebra.util.guess_column_types(d_right, columns=columns)
    if (right_types is None) or (len(right_types) <= 0):
        return None
    mismatches = dict()
    for c in columns:
        if not compatible_types([left_types[c], right_types[c]]):
            mismatches[c] = (left_types[c], right_types[c])
    if len(mismatches) > 0:
        return mismatches
    return None
def check_columns_appear_compatible ( d_left , d_right , * , columns : Optional [ Iterable [ str ] ] = None ) -> Optional [ Dict [ str , Tuple [ type , type ] ] ] : if columns is None : columns = [ c for c in d_left . columns ] assert set ( d_left . columns ) == set ( d_right . columns ) else : columns = [ c for c in columns ] assert len ( set ( columns ) - set ( d_left . columns ) ) == 0 assert len ( set ( columns ) - set ( d_right . columns ) ) == 0 left_types = data_algebra . util . guess_column_types ( d_left , columns = columns ) if ( left_types is None ) or ( len ( left_types ) <= 0 ) : return None right_types = data_algebra . util . guess_column_types ( d_right , columns = columns ) if ( right_types is None ) or ( len ( right_types ) <= 0 ) : return None mismatches = dict ( ) for c in columns : if not compatible_types ( [ left_types [ c ] , right_types [ c ] ] ) : mismatches [ c ] = ( left_types [ c ] , right_types [ c ] ) if len ( mismatches ) > 0 : return mismatches return None
Check if columns have compatible types
Check if columns have compatible types
"""
    Check if columns have compatible types

    :param d_left: pandas dataframe to check
    :param d_right: pandas dataframe to check
    :param columns: columns to check, None means check all columns
    :return: None if compatible, else dictionary of mismatches
    """
None if compatible, else dictionary of mismatches
None if compatible else dictionary of mismatches
d_left
pandas dataframe to check
pandas dataframe to check
d_right
pandas dataframe to check
pandas dataframe to check
columns
Optional[Iterable[str]]
columns to check, None means check all columns
columns to check None means check all columns