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

DataGenerator - templates containing square brackets treated as entities to be replaced #64

Closed
melmatlis opened this issue Dec 20, 2022 · 3 comments
Labels
question Further information is requested

Comments

@melmatlis
Copy link
Collaborator

Templates which contain square brackets fail on generating new fake data. Square brackets are converted to curly brackets to be treated as entities i.e -> "{{entity}}". Method _prep_templates responsible for the replacement.
Is this the desired behavior?

How to reproduce the error:


from faker import Faker
fake = RecordsFaker(fake_data_df, local="en_US")
data_generator = PresidioDataGenerator(
    custom_faker=fake, lower_case_ratio=0
)

provider_list = [HospitalProvider, IpAddressProvider,NationalityProvider,  AgeProvider, AddressProviderNew, PhoneNumberProviderNew, OrganizationProvider]
for provider in provider_list:
    fake.add_provider(provider)

template = "My name is {{name}} and I [travel] to the factory"


fake_records = data_generator.generate_fake_data(
    templates=[template], n_samples=1
)
list(fake_records)

Returns:

AttributeError: Failed to generate fake data based on template "My name is {{name}} and I {{travel}} to the factory".You might ?need to add a new Faker provider! Unknown formatter 'travel'

@melmatlis melmatlis added the question Further information is requested label Dec 20, 2022
@omri374
Copy link
Contributor

omri374 commented Dec 26, 2022

It is by design (as the previous version used square brackets and we wanted to have some backward compatibility, but I don't see an issue with removing this, especially if it causes issues with generated templates.

@omri374
Copy link
Contributor

omri374 commented Dec 26, 2022

Reference in code:

@melmatlis
Copy link
Collaborator Author

Solved by #65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants