Skip to content

Commit

Permalink
Can't set address columns after fitting (#1662)
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Palazzo authored Nov 6, 2023
1 parent fe10f11 commit e956111
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sdv/data_processing/data_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ def set_address_transformer(self, column_names, anonymization_level):
transformer = self._get_address_transformer(anonymization_level)
transformer._validate_sdtypes(columns_to_sdtypes)

if self._prepared_for_fitting:
self.update_transformers({column_names: transformer})

self.grouped_columns_to_transformers[column_names] = transformer

def get_model_kwargs(self, model_name):
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/data_processing/test_data_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,35 @@ def test__set_address_transformer(self):
transformer._validate_sdtypes.assert_called_once_with(columns_to_sdtypes)
assert dp.grouped_columns_to_transformers == {columns: transformer}

def test__set_address_transformer_prepared_for_fitting_true(self):
"""Test the ``set_address_transformer`` method when ``_prepared_for_fitting`` is True."""
# Setup
metadata = SingleTableMetadata().load_from_dict({
'columns': {
'country_column': {'sdtype': 'country_code'},
'city_column': {'sdtype': 'city'},
}
})
dp = DataProcessor(metadata)
transformer = Mock()
transformer._validate_sdtypes = Mock()
columns_to_sdtypes = {'country_column': 'country_code', 'city_column': 'city'}
dp._get_address_transformer = Mock(return_value=transformer)
columns = ('country_column', 'city_column')
dp.update_transformers = Mock()
dp._prepared_for_fitting = True

# Run
dp.set_address_transformer(columns, 'full')

# Assert
dp.update_transformers.assert_called_once_with(
{('country_column', 'city_column'): transformer}
)
dp._get_address_transformer.assert_called_once_with('full')
transformer._validate_sdtypes.assert_called_once_with(columns_to_sdtypes)
assert dp.grouped_columns_to_transformers == {columns: transformer}

def test_filter_valid(self):
"""Test that we are calling the ``filter_valid`` of each constraint over the data."""
# Setup
Expand Down

0 comments on commit e956111

Please sign in to comment.