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

ScalarInequality and ScalarRange Can’t Use datetime64 as datatype #2217

Open
pvk-developer opened this issue Sep 10, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@pvk-developer
Copy link
Member

pvk-developer commented Sep 10, 2024

Description

When applying the ScalarInequality or ScalarRange constraint on a datetime64 column in a pd.DataFrame, it raises an InvalidConstraintsError. The error message indicates that the 'value' must be a datetime string in the correct format, even when a valid datetime string is provided. This prevents using datetime64 columns directly with the ScalarInequality constraint.

Steps to reproduce

from sdv.metadata import SingleTableMetadata
from sdv.single_table import GaussianCopulaSynthesizer

import pandas as pd
import numpy as np

data = {
    'object': pd.Series(['a', 'b', 'c'], dtype='object'),
    'string': pd.Series(['a', 'b', 'c'], dtype='string'),
    'datetime64': pd.Series(pd.date_range('2023-01-01', periods=3), dtype='datetime64[ns]'),
}
df = pd.DataFrame(data)

metadata = SingleTableMetadata()

metadata.add_column('object', sdtype='categorical')
metadata.add_column('string', sdtype='categorical')
metadata.add_column('datetime64', sdtype='datetime')

gcs = GaussianCopulaSynthesizer(metadata)

my_constraints = [
    {
        'constraint_class': 'ScalarInequality',
        'constraint_parameters': {
            'column_name': 'datetime64',
            'relation': '>=',
            'value':  '2023-01-01'
            }
    }
]

gcs.add_constraints(my_constraints)

File ~/Projects/sdv-dev/SDV/sdv/single_table/base.py:296, in BaseSynthesizer.add_constraints(self, constraints)
    291 if self._fitted:
    292     warnings.warn(
    293         "For these constraints to take effect, please refit the synthesizer using 'fit'."
    294     )
--> 296 self._data_processor.add_constraints(constraints)

File ~/Projects/sdv-dev/SDV/sdv/data_processing/data_processor.py:327, in DataProcessor.add_constraints(self, constraints)
    324         errors.append(reformated_errors)
    326 if errors:
--> 327     raise InvalidConstraintsError(errors)
    329 self._constraints_list.extend(validated_constraints)
    330 self._prepared_for_fitting = False

InvalidConstraintsError: The provided constraint is invalid:
'value' must be a datetime string of the right format.
@pvk-developer pvk-developer added the bug Something isn't working label Sep 10, 2024
@pvk-developer pvk-developer changed the title ScalarInequality Can’t Use datetime64 as datatype ScalarInequality and ScalarRange Can’t Use datetime64 as datatype Sep 10, 2024
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

No branches or pull requests

1 participant