Skip to content

Commit

Permalink
Allow for disjointed tables
Browse files Browse the repository at this point in the history
  • Loading branch information
lajohn4747 committed Jun 5, 2024
1 parent 3871c2a commit ef8cca9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 45 deletions.
7 changes: 0 additions & 7 deletions sdv/metadata/multi_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,6 @@ def _detect_relationships(self):
primary_key,
sdtype=original_foreign_key_sdtype)
continue
try:
self._validate_all_tables_connected(self._get_parent_map(), self._get_child_map())
except InvalidMetadataError as invalid_error:
warning_msg = (
f'Could not automatically add relationships for all tables. {str(invalid_error)}'
)
warnings.warn(warning_msg)

def detect_table_from_dataframe(self, table_name, data):
"""Detect the metadata for a table from a dataframe.
Expand Down
38 changes: 0 additions & 38 deletions tests/unit/metadata/test_multi_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2319,44 +2319,6 @@ def test__detect_relationships(self):
assert instance.relationships == expected_relationships
assert instance.tables['sessions'].columns['user_id']['sdtype'] == 'id'

@patch('sdv.metadata.multi_table.warnings')
def test__detect_relationships_disconnected_warning(self, warnings_mock):
"""Test that ``_detect_relationships`` warns about tables it could not connect."""
# Setup
parent_table = Mock()
parent_table.primary_key = 'id'
parent_table.columns = {
'id': {'sdtype': 'id'},
'user_name': {'sdtype': 'categorical'},
'transactions': {'sdtype': 'numerical'},
}

child_table = SingleTableMetadata()
child_table.primary_key = 'session_id'
child_table.columns = {
'user_id': {'sdtype': 'categorical'},
'session_id': {'sdtype': 'numerical'},
'timestamp': {'sdtype': 'datetime'},
}

instance = MultiTableMetadata()
instance.tables = {
'users': parent_table,
'sessions': child_table,
}

# Run
instance._detect_relationships()

# Assert
expected_warning = (
'Could not automatically add relationships for all tables. The relationships in '
"the dataset are disjointed. Tables ['users', 'sessions'] are not connected to "
'any of the other tables.'
)
warnings_mock.warn.assert_called_once_with(expected_warning)
assert instance.relationships == []

def test__detect_relationships_circular(self):
"""Test that relationships that invalidate the metadata are not added."""
# Setup
Expand Down

0 comments on commit ef8cca9

Please sign in to comment.