Skip to content

Commit

Permalink
integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Palazzo committed Aug 23, 2024
1 parent 0f7f0d7 commit da309d0
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/integration/constraints/test_tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,40 @@ def test_fixed_combinations_with_nans():
data.drop_duplicates(ignore_index=True),
check_like=True,
)


def test_fixedincrements_with_nullable_pandas_dtypes():
"""Test that FixedIncrements constraint works with nullable pandas dtypes."""
# Setup
data = pd.DataFrame({
'UInt8': pd.Series([1, pd.NA, 3], dtype='UInt8') * 10,
'UInt16': pd.Series([1, pd.NA, 4], dtype='UInt16') * 10,
'UInt32': pd.Series([1, pd.NA, 5], dtype='UInt32') * 10,
'UInt64': pd.Series([1, pd.NA, 6], dtype='UInt64') * 10,
})
metadata = SingleTableMetadata().load_from_dict({
'columns': {
'UInt8': {'sdtype': 'numerical', 'computer_representation': 'UInt8'},
'UInt16': {'sdtype': 'numerical', 'computer_representation': 'UInt16'},
'UInt32': {'sdtype': 'numerical', 'computer_representation': 'UInt32'},
'UInt64': {'sdtype': 'numerical', 'computer_representation': 'UInt64'},
}
})
gcs = GaussianCopulaSynthesizer(metadata)
my_constraints = [
{
'constraint_class': 'FixedIncrements',
'constraint_parameters': {'column_name': column, 'increment_value': 10},
}
for column in data.columns
]
gcs.add_constraints(my_constraints)

# Run
gcs.fit(data)
synthetic_data = gcs.sample(10)

# Assert
synthetic_data.dtypes.to_dict() == data.dtypes.to_dict()
for column in data.columns:
assert np.all(synthetic_data[column] % 10 == 0)

0 comments on commit da309d0

Please sign in to comment.