Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message when passing an SDV Metadata object #614

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
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
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
Loading