Skip to content

Commit

Permalink
Add stub methods (#2218)
Browse files Browse the repository at this point in the history
  • Loading branch information
frances-h committed Sep 17, 2024
1 parent d6e3d76 commit 0d422b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sdv/multi_table/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ def _store_and_convert_original_cols(self, data):
data[table] = dataframe
return list_of_changed_tables

def _transform_helper(self, data):
"""Stub method for transforming data patterns."""
return data

def preprocess(self, data):
"""Transform the raw data to numerical space.
Expand All @@ -353,6 +357,7 @@ def preprocess(self, data):
"""
list_of_changed_tables = self._store_and_convert_original_cols(data)

data = self._transform_helper(data)
self.validate(data)
if self._fitted:
warnings.warn(
Expand Down Expand Up @@ -471,6 +476,10 @@ def reset_sampling(self):
def _sample(self, scale):
raise NotImplementedError()

def _reverse_transform_helper(self, sampled_data):
"""Stub method for reverse transforming data patterns."""
return sampled_data

def sample(self, scale=1.0):
"""Generate synthetic data for the entire dataset.
Expand All @@ -495,6 +504,7 @@ def sample(self, scale=1.0):

with self._set_temp_numpy_seed(), disable_single_table_logger():
sampled_data = self._sample(scale=scale)
sampled_data = self._reverse_transform_helper(sampled_data)

total_rows = 0
total_columns = 0
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/multi_table/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ def test_preprocess(self):
'id_upravna_enota': np.arange(10),
}),
}
instance._transform_helper = Mock(return_value=data)

synth_nesreca = Mock()
synth_oseba = Mock()
Expand All @@ -782,6 +783,7 @@ def test_preprocess(self):
'oseba': synth_oseba._preprocess.return_value,
'upravna_enota': synth_upravna_enota._preprocess.return_value,
}
instance._transform_helper.assert_called_once_with(data)
instance.validate.assert_called_once_with(data)
assert instance.metadata._get_all_foreign_keys.call_args_list == [
call('nesreca'),
Expand Down Expand Up @@ -1212,6 +1214,7 @@ def test_sample(self, mock_datetime, caplog):
'table2': pd.DataFrame({'id': [1, 2, 3], 'name': ['John', 'Johanna', 'Doe']}),
}
instance._sample = Mock(return_value=data)
instance._reverse_transform_helper = Mock(return_value=data)

synth_id = 'BaseMultiTableSynthesizer_1.0.0_92aff11e9a5649d1a280990d1231a5f5'
instance._synthesizer_id = synth_id
Expand All @@ -1222,6 +1225,7 @@ def test_sample(self, mock_datetime, caplog):

# Assert
instance._sample.assert_called_once_with(scale=1.5)
instance._reverse_transform_helper.assert_called_once_with(data)
assert caplog.messages[0] == str({
'EVENT': 'Sample',
'TIMESTAMP': '2024-04-19 16:20:10.037183',
Expand Down

0 comments on commit 0d422b8

Please sign in to comment.