dataprep/eda/diff/compute/multiple_df.py
def compare_multiple_df(
    df_list: List[dd.DataFrame], cfg: Config, dtype: Optional[DTypeDef]
) -> Intermediate:
    """
    Compute function for plot_diff([df...])

    Parameters
    ----------
    dfs
        Dataframe sequence to be compared.
    cfg
        Config instance
    dtype: str or DType or dict of str or dict of DType, default None
        Specify Data Types for designated column or all columns.
        E.g.  dtype = {"a": Continuous, "b": "Nominal"} or
        dtype = {"a": Continuous(), "b": "nominal"}
        or dtype = Continuous() or dtype = "Continuous" or dtype = Continuous()
    """
    # pylint: disable=too-many-branches, too-many-locals

    dfs = Dfs(df_list)
    dfs_cols = dfs.columns.apply("to_list").data

    labeled_cols = dict(zip(cfg.diff.label, dfs_cols))
    baseline: int = cfg.diff.baseline
    data: List[Any] = []
    aligned_dfs = dd.concat(df_list, axis=1)

    # OrderedDict for keeping the order
    uniq_cols = list(OrderedDict.fromkeys(sum(dfs_cols, [])))

    for col in uniq_cols:
        srs = Srs(aligned_dfs[col])
        col_dtype = srs.self_map(detect_dtype, known_dtype=dtype)
        if len(col_dtype) > 1:
            col_dtype = col_dtype[baseline]
        else:
            col_dtype = col_dtype[0]

        orig = [src for src, seq in labeled_cols.items() if col in seq]

        if is_dtype(col_dtype, Continuous()) and cfg.hist.enable:
            data.append((col, Continuous(), _cont_calcs(srs.apply("dropna"), cfg), orig))
        elif is_dtype(col_dtype, Nominal()) and cfg.bar.enable:
            srs = srs.apply("astype", "str")
            data.append((col, Nominal(), _nom_calcs(srs.apply("dropna"), cfg), orig))
        elif is_dtype(col_dtype, DateTime()) and cfg.line.enable:
            data.append(
                (col, DateTime(), dask.delayed(_calc_line_dt)(srs, col, cfg.line.unit), orig)
            )

    stats = calc_stats(dfs, cfg, dtype)
    stats, data = dask.compute(stats, data)
    plot_data: List[Tuple[str, DTypeDef, Any, List[str]]] = []

    for col, dtp, datum, orig in data:
        if is_dtype(dtp, Continuous()):
            if cfg.hist.enable:
                plot_data.append((col, dtp, datum["hist"], orig))
        elif is_dtype(dtp, Nominal()):
            if cfg.bar.enable:
                plot_data.append((col, dtp, (datum["bar"], datum["nuniq"]), orig))
        elif is_dtype(dtp, DateTime()):
            plot_data.append((col, dtp, dask.compute(*datum), orig))  # workaround
    return Intermediate(data=plot_data, stats=stats, visual_type="comparison_grid")

    Compute function for plot_diff([df...])

    Parameters
    ----------
    dfs
        Dataframe sequence to be compared.
    cfg
        Config instance
    dtype: str or DType or dict of str or dict of DType, default None
        Specify Data Types for designated column or all columns.
        E.g.  dtype = {"a": Continuous, "b": "Nominal"} or
        dtype = {"a": Continuous(), "b": "nominal"}
        or dtype = Continuous() or dtype = "Continuous" or dtype = Continuous()
    
Compute function for plot_diff([df...])
Parameters

dfs
Dataframe sequence to be compared.
cfg
Config instance
dtype: str or DType or dict of str or dict of DType, default None
Specify Data Types for designated column or all columns.
Compute function for plot_diff ( [ df ... ] ) Parameters dfs Dataframe sequence to be compared . cfg Config instance dtype : str or DType or dict of str or dict of DType default None Specify Data Types for designated column or all columns .
def compare_multiple_df(
    df_list: List[dd.DataFrame], cfg: Config, dtype: Optional[DTypeDef]
) -> Intermediate:
    dfs = Dfs(df_list)
    dfs_cols = dfs.columns.apply("to_list").data
    labeled_cols = dict(zip(cfg.diff.label, dfs_cols))
    baseline: int = cfg.diff.baseline
    data: List[Any] = []
    aligned_dfs = dd.concat(df_list, axis=1)
    uniq_cols = list(OrderedDict.fromkeys(sum(dfs_cols, [])))
    for col in uniq_cols:
        srs = Srs(aligned_dfs[col])
        col_dtype = srs.self_map(detect_dtype, known_dtype=dtype)
        if len(col_dtype) > 1:
            col_dtype = col_dtype[baseline]
        else:
            col_dtype = col_dtype[0]
        orig = [src for src, seq in labeled_cols.items() if col in seq]
        if is_dtype(col_dtype, Continuous()) and cfg.hist.enable:
            data.append((col, Continuous(), _cont_calcs(srs.apply("dropna"), cfg), orig))
        elif is_dtype(col_dtype, Nominal()) and cfg.bar.enable:
            srs = srs.apply("astype", "str")
            data.append((col, Nominal(), _nom_calcs(srs.apply("dropna"), cfg), orig))
        elif is_dtype(col_dtype, DateTime()) and cfg.line.enable:
            data.append(
                (col, DateTime(), dask.delayed(_calc_line_dt)(srs, col, cfg.line.unit), orig)
            )
    stats = calc_stats(dfs, cfg, dtype)
    stats, data = dask.compute(stats, data)
    plot_data: List[Tuple[str, DTypeDef, Any, List[str]]] = []
    for col, dtp, datum, orig in data:
        if is_dtype(dtp, Continuous()):
            if cfg.hist.enable:
                plot_data.append((col, dtp, datum["hist"], orig))
        elif is_dtype(dtp, Nominal()):
            if cfg.bar.enable:
                plot_data.append((col, dtp, (datum["bar"], datum["nuniq"]), orig))
        elif is_dtype(dtp, DateTime()):
            plot_data.append((col, dtp, dask.compute(*datum), orig))  
    return Intermediate(data=plot_data, stats=stats, visual_type="comparison_grid")
def compare_multiple_df ( df_list : List [ dd . DataFrame ] , cfg : Config , dtype : Optional [ DTypeDef ] ) -> Intermediate : dfs = Dfs ( df_list ) dfs_cols = dfs . columns . apply ( "to_list" ) . data labeled_cols = dict ( zip ( cfg . diff . label , dfs_cols ) ) baseline : int = cfg . diff . baseline data : List [ Any ] = [ ] aligned_dfs = dd . concat ( df_list , axis = 1 ) uniq_cols = list ( OrderedDict . fromkeys ( sum ( dfs_cols , [ ] ) ) ) for col in uniq_cols : srs = Srs ( aligned_dfs [ col ] ) col_dtype = srs . self_map ( detect_dtype , known_dtype = dtype ) if len ( col_dtype ) > 1 : col_dtype = col_dtype [ baseline ] else : col_dtype = col_dtype [ 0 ] orig = [ src for src , seq in labeled_cols . items ( ) if col in seq ] if is_dtype ( col_dtype , Continuous ( ) ) and cfg . hist . enable : data . append ( ( col , Continuous ( ) , _cont_calcs ( srs . apply ( "dropna" ) , cfg ) , orig ) ) elif is_dtype ( col_dtype , Nominal ( ) ) and cfg . bar . enable : srs = srs . apply ( "astype" , "str" ) data . append ( ( col , Nominal ( ) , _nom_calcs ( srs . apply ( "dropna" ) , cfg ) , orig ) ) elif is_dtype ( col_dtype , DateTime ( ) ) and cfg . line . enable : data . append ( ( col , DateTime ( ) , dask . delayed ( _calc_line_dt ) ( srs , col , cfg . line . unit ) , orig ) ) stats = calc_stats ( dfs , cfg , dtype ) stats , data = dask . compute ( stats , data ) plot_data : List [ Tuple [ str , DTypeDef , Any , List [ str ] ] ] = [ ] for col , dtp , datum , orig in data : if is_dtype ( dtp , Continuous ( ) ) : if cfg . hist . enable : plot_data . append ( ( col , dtp , datum [ "hist" ] , orig ) ) elif is_dtype ( dtp , Nominal ( ) ) : if cfg . bar . enable : plot_data . append ( ( col , dtp , ( datum [ "bar" ] , datum [ "nuniq" ] ) , orig ) ) elif is_dtype ( dtp , DateTime ( ) ) : plot_data . append ( ( col , dtp , dask . compute ( * datum ) , orig ) ) return Intermediate ( data = plot_data , stats = stats , visual_type = "comparison_grid" )
Compute function for plot_diff([df...])
Parameters
Compute function for plot_diff ( [ df ... ] ) Parameters
"""
    Compute function for plot_diff([df...])

    Parameters
    ----------
    dfs
        Dataframe sequence to be compared.
    cfg
        Config instance
    dtype: str or DType or dict of str or dict of DType, default None
        Specify Data Types for designated column or all columns.
        E.g.  dtype = {"a": Continuous, "b": "Nominal"} or
        dtype = {"a": Continuous(), "b": "nominal"}
        or dtype = Continuous() or dtype = "Continuous" or dtype = Continuous()
    """ # pylint: disable=too-many-branches, too-many-locals # OrderedDict for keeping the order # workaround
df_list
List[dd.DataFrame]
cfg
Config
dtype
Optional[DTypeDef]