Skip to content

Commit

Permalink
Better error message when passing an SDV Metadata object (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Palazzo authored Jul 30, 2024
1 parent 9d5f503 commit 2bed20d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion sdmetrics/reports/base_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ def generate(self, real_data, synthetic_data, metadata, verbose=True):
Whether or not to print report summary and progress.
"""
if not isinstance(metadata, dict):
raise TypeError('The provided metadata is not a dictionary.')
raise TypeError(
f"Expected a dictionary but received a '{type(metadata).__name__}' instead."
" For SDV metadata objects, please use the 'to_dict' function to convert it to a dictionary."
)

self._validate(real_data, synthetic_data, metadata)
self.convert_datetimes(real_data, synthetic_data, metadata)
Expand Down
4 changes: 3 additions & 1 deletion sdmetrics/reports/multi_table/base_multi_table_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ def generate(self, real_data, synthetic_data, metadata, verbose=True):
verbose (bool):
Whether or not to print report summary and progress.
"""
results = super().generate(real_data, synthetic_data, metadata, verbose)
self.table_names = list(metadata.get('tables', {}).keys())
return super().generate(real_data, synthetic_data, metadata, verbose)

return results

def _check_table_names(self, table_name):
if table_name not in self.table_names:
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/reports/test_base_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ def test_generate_metadata_not_dict(self):
metadata = 'metadata'

# Run and Assert
expected_message = 'The provided metadata is not a dictionary.'
expected_message = (
"Expected a dictionary but received a 'str' instead. For SDV metadata objects, "
"please use the 'to_dict' function to convert it to a dictionary."
)
with pytest.raises(TypeError, match=expected_message):
base_report.generate(real_data, synthetic_data, metadata, verbose=False)

Expand Down

0 comments on commit 2bed20d

Please sign in to comment.