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

Add the dummy context column to metadata and not to extra_context_column #2019

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdv/sequential/par.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ def update_transformers(self, column_name_to_transformer):

def _fit_context_model(self, transformed):
LOGGER.debug(f'Fitting context synthesizer {self._context_synthesizer.__class__.__name__}')
context_metadata: SingleTableMetadata = self._get_context_metadata()
if self.context_columns or self._extra_context_columns:
context_cols = (
self._sequence_key + self.context_columns +
Expand All @@ -250,9 +251,8 @@ def _fit_context_model(self, transformed):
# Add constant column to allow modeling
constant_column = str(uuid.uuid4())
context[constant_column] = 0
self._extra_context_columns[constant_column] = {'sdtype': 'numerical'}
context_metadata.add_column(constant_column, sdtype='numerical')

context_metadata = self._get_context_metadata()
self._context_synthesizer = GaussianCopulaSynthesizer(
context_metadata,
enforce_min_max_values=self._context_synthesizer.enforce_min_max_values,
Expand Down
33 changes: 33 additions & 0 deletions tests/integration/sequential/test_par.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,36 @@ def test_par_subset_of_data_simplified():

# Assert
assert not pd.isna(synthetic_data['date']).any()


def test_par_missing_sequence_index():
"""Test if PAR Synthesizer can run without a sequence key"""
# Setup
metadata_dict = {
'columns': {
'value': {
'sdtype': 'numerical'
},
'e_id': {
'sdtype': 'id'
}
},
'METADATA_SPEC_VERSION': 'SINGLE_TABLE_V1',
'sequence_key': 'e_id'
}

metadata = SingleTableMetadata().load_from_dict(metadata_dict)

data = pd.DataFrame({
'value': [10, 20, 30],
'e_id': [1, 2, 3]
})

# Run
synthesizer = PARSynthesizer(metadata)
synthesizer.fit(data)
sampled = synthesizer.sample(num_sequences=3)

# Assert
assert sampled.shape == data.shape
assert (sampled.dtypes == data.dtypes).all()
Loading