diff --git a/sdmetrics/reports/multi_table/_properties/cardinality.py b/sdmetrics/reports/multi_table/_properties/cardinality.py index 6601e359..e3e1726f 100644 --- a/sdmetrics/reports/multi_table/_properties/cardinality.py +++ b/sdmetrics/reports/multi_table/_properties/cardinality.py @@ -33,7 +33,7 @@ def _generate_details(self, real_data, synthetic_data, metadata, progress_bar=No float: The average score for the property for all the individual metric scores computed. """ - child_tables, parent_tables = [], [] + child_tables, parent_tables, child_foreign_key = [], [], [] metric_names, scores, error_messages = [], [], [] for relation in metadata.get('relationships', []): relationships_metadata = {'relationships': [relation]} @@ -53,6 +53,7 @@ def _generate_details(self, real_data, synthetic_data, metadata, progress_bar=No child_tables.append(relation['child_table_name']) parent_tables.append(relation['parent_table_name']) + child_foreign_key.append(relation['child_foreign_key']) metric_names.append('CardinalityShapeSimilarity') scores.append(relation_score) error_messages.append(error_message) @@ -60,43 +61,12 @@ def _generate_details(self, real_data, synthetic_data, metadata, progress_bar=No self.details = pd.DataFrame({ 'Child Table': child_tables, 'Parent Table': parent_tables, + 'Foreign Key': child_foreign_key, 'Metric': metric_names, 'Score': scores, 'Error': error_messages, }) - def _get_details_for_table_name(self, table_name): - """Return the details for the given table name. - - Args: - table_name (str): - Table name to get the details for. - - Returns: - pandas.DataFrame: - The details for the given table name. - """ - is_child = self.details['Child Table'] == table_name - is_parent = self.details['Parent Table'] == table_name - return self.details[is_child | is_parent].copy() - - def get_details(self, table_name=None): - """Return the details for the property. - - Args: - table_name (str): - Table name to get the details for. - Defaults to ``None``. - - Returns: - pandas.DataFrame: - The details for the property. - """ - if table_name is None: - return self.details.copy() - - return self._get_details_for_table_name(table_name) - def _get_table_relationships_plot(self, table_name): """Get the table relationships plot from the parent child relationship scores for a table. @@ -107,9 +77,12 @@ def _get_table_relationships_plot(self, table_name): Returns: plotly.graph_objects._figure.Figure """ - plot_data = self._get_details_for_table_name(table_name).copy() + plot_data = self.get_details(table_name).copy() column_name = 'Child → Parent Relationship' - plot_data[column_name] = plot_data['Child Table'] + ' → ' + plot_data['Parent Table'] + plot_data[column_name] = ( + plot_data['Child Table'] + ' (' + plot_data['Foreign Key'] + ') → ' + + plot_data['Parent Table'] + ) plot_data = plot_data.drop(['Child Table', 'Parent Table'], axis=1) average_score = round(plot_data['Score'].mean(), 2)