Skip to content

Commit

Permalink
Raise a proper value error message when the metadata is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
pvk-developer committed Oct 8, 2024
1 parent 3e19a2e commit 361fefc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sdv/metadata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ def _convert_to_single_table(self):
return next(iter(self.tables.values()), SingleTableMetadata())

def _handle_table_name(self, table_name):
if len(self.tables) == 0:
raise ValueError(
'The metadata object is currently empty. To populate it, please use either '
"'detect_from_dataframe' or 'detect_from_dataframes'."
)
if table_name is None:
if len(self.tables) == 1:
table_name = next(iter(self.tables))
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/metadata/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,3 +692,16 @@ def test_update_methods(self, method, args):
# Assert
metadata._handle_table_name.assert_called_once_with('table_name')
mock_super_method.assert_called_once_with('table_name', *args)

def test__handle_table_name_with_empty_tables(self):
"""Test that the proper `ValueError` is raised when there are no `tables`."""
# Setup
instance = Metadata()

# Run and Assert
error_msg = (
'The metadata object is currently empty. To populate it, please use either '
"'detect_from_dataframe' or 'detect_from_dataframes'."
)
with pytest.raises(ValueError, match=error_msg):
instance._handle_table_name(None)

0 comments on commit 361fefc

Please sign in to comment.