Skip to content

Commit

Permalink
Allow empty tables to be fitted using fit_processed_data (#1526)
Browse files Browse the repository at this point in the history
* Update preprocess_data

* Fix lint

* Update test
  • Loading branch information
fealho authored Aug 2, 2023
1 parent 02667ef commit 1534b2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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
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

0 comments on commit 1534b2f

Please sign in to comment.