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

Error in Setting IDGenerator for Primary Key columns #1862

Closed
pvk-developer opened this issue Mar 21, 2024 · 0 comments · Fixed by #1892
Closed

Error in Setting IDGenerator for Primary Key columns #1862

pvk-developer opened this issue Mar 21, 2024 · 0 comments · Fixed by #1892
Assignees
Labels
bug Something isn't working
Milestone

Comments

@pvk-developer
Copy link
Member

pvk-developer commented Mar 21, 2024

Environment Details

Please indicate the following details about the environment in which you found the bug:

  • SDV version: 1.10
  • Python version: any
  • Operating System: any

Error Description

When trying to set an IDGenerator for a primary key we get an error saying that only AnonymizedFaker or RegexGenerator can be used however we do see this generator being used in some of our datasets when it comes to primary keys.

SynthesizerInputError: Invalid transformer 'IDGenerator' for a primary or alternate key 'user_id'. Please use 'AnonymizedFaker' or 'RegexGenerator' instead.

Steps to reproduce

import pandas as pd
from sdv.metadata import SingleTableMetadata
from sdv.single_table import GaussianCopulaSynthesizer
from rdt.transformers import IDGenerator

data = pd.DataFrame({
    'user_id': list(range(4)),
    'user_cat': ['a', 'b','c', 'd']
})

stm = SingleTableMetadata()
stm.detect_from_dataframe(data)
stm.update_column('user_id', sdtype='id')
stm.set_primary_key('user_id')

gc = GaussianCopulaSynthesizer(stm)
custom_id = IDGenerator(starting_value=5)
gc.auto_assign_transformers(data)

gc.update_transformers({'user_id': custom_id})

---------------------------------------------------------------------------
SynthesizerInputError                     Traceback (most recent call last)
Cell In[38], line 1
----> 1 gc.update_transformers({'user_id': custom_id})

File ~/Projects/sdv-dev/SDV/sdv/single_table/base.py:215, in BaseSynthesizer.update_transformers(self, column_name_to_transformer)
    213 self._validate_transformers(column_name_to_transformer)
    214 self._warn_for_update_transformers(column_name_to_transformer)
--> 215 self._data_processor.update_transformers(column_name_to_transformer)
    216 if self._fitted:
    217     msg = 'For this change to take effect, please refit the synthesizer using `fit`.'

File ~/Projects/sdv-dev/SDV/sdv/data_processing/data_processor.py:640, in DataProcessor.update_transformers(self, column_name_to_transformer)
    638 for column, transformer in column_name_to_transformer.items():
    639     if column in self._keys and not type(transformer) in (AnonymizedFaker, RegexGenerator):
--> 640         raise SynthesizerInputError(
    641             f"Invalid transformer '{transformer.__class__.__name__}' for a primary "
    642             f"or alternate key '{column}'. Please use 'AnonymizedFaker' or "
    643             "'RegexGenerator' instead."
    644         )
    646 with warnings.catch_warnings():
    647     warnings.filterwarnings('ignore', module='rdt.hyper_transformer')

SynthesizerInputError: Invalid transformer 'IDGenerator' for a primary or alternate key 'user_id'. Please use 'AnonymizedFaker' or 'RegexGenerator' instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants