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

Remove input error on null foreign keys from BaseMultiTableSynthesizer.fit #2077

Merged
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
2 changes: 0 additions & 2 deletions sdv/multi_table/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from sdv import version
from sdv._utils import (
_validate_foreign_keys_not_null,
check_sdv_versions_and_warn,
check_synthesizer_version,
generate_synthesizer_id,
Expand Down Expand Up @@ -448,7 +447,6 @@ def fit(self, data):
})

check_synthesizer_version(self, is_fit_method=True, compare_operator=operator.lt)
_validate_foreign_keys_not_null(self.metadata, data)
self._check_metadata_updated()
self._fitted = False
processed_data = self.preprocess(data)
Expand Down
13 changes: 2 additions & 11 deletions tests/integration/multi_table/test_hma.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ def test_metadata_updated_warning_detect(self):
assert len(record) == 1

def test_null_foreign_keys(self):
"""Test that the synthesizer crashes when there are null foreign keys."""
"""Test that the synthesizer does not crash when there are null foreign keys."""
# Setup
metadata = MultiTableMetadata()
metadata.add_table('parent_table')
Expand Down Expand Up @@ -1370,16 +1370,7 @@ def test_null_foreign_keys(self):
metadata.validate_data(data)

# Run and Assert
err_msg = re.escape(
'The data contains null values in foreign key columns. This feature is currently '
'unsupported. Please remove null values to fit the synthesizer.\n'
'\n'
'Affected columns:\n'
"Table 'child_table1', column(s) ['fk']\n"
"Table 'child_table2', column(s) ['fk1', 'fk2']\n"
)
with pytest.raises(SynthesizerInputError, match=err_msg):
synthesizer.fit(data)
synthesizer.fit(data)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When HMA is updated to support null foreign keys we should add more assertions here



parametrization = [
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/multi_table/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,8 +981,7 @@ def test_fit_processed_data_raises_version_error(self):
instance._check_metadata_updated.assert_not_called()

@patch('sdv.multi_table.base.datetime')
@patch('sdv.multi_table.base._validate_foreign_keys_not_null')
def test_fit(self, mock_validate_foreign_keys_not_null, mock_datetime, caplog):
def test_fit(self, mock_datetime, caplog):
"""Test that it calls the appropriate methods."""
# Setup
mock_datetime.datetime.now.return_value = '2024-04-19 16:20:10.037183'
Expand All @@ -1002,7 +1001,6 @@ def test_fit(self, mock_validate_foreign_keys_not_null, mock_datetime, caplog):
BaseMultiTableSynthesizer.fit(instance, data)

# Assert
mock_validate_foreign_keys_not_null.assert_called_once_with(instance.metadata, data)
instance.preprocess.assert_called_once_with(data)
instance.fit_processed_data.assert_called_once_with(instance.preprocess.return_value)
instance._check_metadata_updated.assert_called_once()
Expand Down
Loading