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

Allow empty tables to be fitted using fit_processed_data #1526

Merged
merged 3 commits into from
Aug 2, 2023
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
4 changes: 3 additions & 1 deletion sdv/single_table/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,9 @@ def fit_processed_data(self, processed_data):
processed_data (pandas.DataFrame):
The transformed data used to fit the model to.
"""
self._fit(processed_data)
if not processed_data.empty:
self._fit(processed_data)

self._fitted = True
self._fitted_date = datetime.datetime.today().strftime('%Y-%m-%d')
self._fitted_sdv_version = pkg_resources.get_distribution('sdv').version
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/multi_table/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,21 @@ def test_fit_processed_data(self):
instance._model_tables.assert_called_once_with(instance._augment_tables.return_value)
assert instance._fitted

def test_fit_processed_data_empty_table(self):
"""Test attributes are properly set when data is empty and that _fit is not called."""
# Setup
instance = Mock()
data = pd.DataFrame()

# Run
BaseMultiTableSynthesizer.fit_processed_data(instance, data)

# Assert
Copy link
Member

Choose a reason for hiding this comment

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

could we assert that instance._fit has not been called ?

instance._fit.assert_not_called()
assert instance._fitted
assert instance._fitted_date
assert instance._fitted_sdv_version

def test_fit(self):
"""Test that ``fit`` calls ``preprocess`` and then ``fit_processed_data``."""
# Setup
Expand Down