Skip to content

Commit 3085bc5

Browse files
committed
Update error message
1 parent 5e5e3c8 commit 3085bc5

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

sdmetrics/reports/multi_table/base_multi_table_report.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,17 @@ def _validate_relationships(self, real_data, synthetic_data, metadata):
4848
parent_key = rel['parent_primary_key']
4949
child = rel['child_table_name']
5050
child_key = rel['child_foreign_key']
51+
parent_key_str = f"'{parent_key}'" if isinstance(parent_key, str) else str(parent_key)
52+
child_key_str = f"'{child_key}'" if isinstance(child_key, str) else str(child_key)
5153
parent_primary_key = _cast_to_iterable(parent_key)
5254
child_foreign_key = _cast_to_iterable(child_key)
55+
5356
if len(parent_primary_key) != len(child_foreign_key):
5457
error_msg = (
5558
f"The '{parent}' table and '{child}' table cannot be merged "
5659
'for computing the cardinality. Please make sure the number of columns '
57-
f'in the primary key ({len(parent_primary_key)}) matches the number of '
58-
f'columns in the foreign key ({len(child_foreign_key)}).'
60+
f'in the primary key ({parent_key_str}) matches the number of '
61+
f'columns in the foreign key ({child_key_str}).'
5962
)
6063
raise ValueError(error_msg)
6164
parent_dtypes = real_data[rel['parent_table_name']][parent_primary_key].dtypes
@@ -64,17 +67,11 @@ def _validate_relationships(self, real_data, synthetic_data, metadata):
6467
if (parent_dtype == 'object' and child_dtype != 'object') or (
6568
parent_dtype != 'object' and child_dtype == 'object'
6669
):
67-
parent_key_str = (
68-
parent_key if isinstance(parent_key, str) else "', '".join(parent_key)
69-
)
70-
child_key_str = (
71-
child_key if isinstance(child_key, str) else "', '".join(child_key)
72-
)
7370
error_msg = (
7471
f"The '{parent}' table and '{child}' table cannot be merged "
7572
'for computing the cardinality. Please make sure the primary key'
76-
f" in '{parent}' ('{parent_key_str}') and the foreign key in '{child}'"
77-
f" ('{child_key_str}') have the same data types."
73+
f" in '{parent}' ({parent_key_str}) and the foreign key in '{child}'"
74+
f' ({child_key_str}) have the same data types.'
7875
)
7976
raise ValueError(error_msg)
8077

tests/unit/reports/multi_table/test_base_multi_table_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def test__validate_relationships_num_key_cols_mismatch(self):
130130
expected_error_message = re.escape(
131131
"The 'Table_1' table and 'Table_2' table cannot be merged for computing"
132132
' the cardinality. Please make sure the number of columns'
133-
' in the primary key (2) matches the number of'
134-
' columns in the foreign key (1).'
133+
" in the primary key (['col1', 'col2']) matches the number of"
134+
" columns in the foreign key ('col2')."
135135
)
136136
with pytest.raises(ValueError, match=expected_error_message):
137137
report._validate_relationships(real_data, synthetic_data, metadata)

0 commit comments

Comments
 (0)