Skip to content

Commit

Permalink
Providing locales to AnonymizedFaker with a function that uses the Ba…
Browse files Browse the repository at this point in the history
…seProvider crashes (#776)
  • Loading branch information
frances-h authored Mar 28, 2024
1 parent 2eaf2c5 commit 03b96e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rdt/transformers/pii/anonymizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def __init__(self, provider_name=None, function_name=None, function_kwargs=None,
self._faker_random_seed = None
self.locales = locales
self.faker = faker.Faker(self.locales)
if self.locales:
if self.provider_name != 'BaseProvider' and self.locales:
self._check_locales()

if missing_value_generation not in ['random', None]:
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/transformers/pii/test_anonymizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ def test_default_settings(self):
pd.testing.assert_frame_equal(transformed, expected_transformed)
assert len(reverse_transform['username']) == 5

def test_default_settings_with_locales(self):
"""End to end test with the default settings and locales of the ``AnonymizedFaker``."""
data = pd.DataFrame({
'id': [1, 2, 3, 4, 5],
'username': ['a', 'b', 'c', 'd', 'e']
})

instance = AnonymizedFaker(locales=['en_US', 'en_CA', 'es_ES'])
transformed = instance.fit_transform(data, 'username')

reverse_transform = instance.reverse_transform(transformed)
expected_transformed = pd.DataFrame({
'id': [1, 2, 3, 4, 5]
})

pd.testing.assert_frame_equal(transformed, expected_transformed)
assert len(reverse_transform['username']) == 5

def test_get_supported_sdtypes(self):
"""Test that the correct supported sdtypes are returned."""
# Run
Expand Down

0 comments on commit 03b96e9

Please sign in to comment.