Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion syndiffix/stitcher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Tuple
from typing import Any, Dict, List, Tuple

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -81,3 +81,19 @@ def stitch(df_left: pd.DataFrame, df_right: pd.DataFrame, shared: bool = True) -
col_names = [col_names_all[col_id] for col_id in columns]
data = [[tup[0] for tup in row] for row in microdata]
return pd.DataFrame(data, columns=col_names)


def get_cluster(syn: Synthesizer) -> Dict[str, List[Any]]:
# Returns a friendly representation of the cluster (column names instead of IDs)
cluster: Dict[str, List[Any]] = {"initial": [], "derived": []}
for col_id in syn.clusters.initial_cluster:
cluster["initial"].append(syn.forest.columns[col_id])
for owner, cols1, cols2 in syn.clusters.derived_clusters:
cluster["derived"].append(
{
"stitch_style": owner,
"stitch_columns": [syn.forest.columns[col_id] for col_id in cols1],
"new_columns": [syn.forest.columns[col_id] for col_id in cols2],
}
)
return cluster
Loading