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

NewRowSynthesis fails with category data type #397

Open
pvk-developer opened this issue Jul 21, 2023 · 0 comments · May be fixed by #458
Open

NewRowSynthesis fails with category data type #397

pvk-developer opened this issue Jul 21, 2023 · 0 comments · May be fixed by #458
Labels
bug Something isn't working

Comments

@pvk-developer
Copy link
Member

Environment Details

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

  • SDMetrics version: 0.10.1
  • Python version: Any
  • Operating System: Any

Error Description

When running DiagnosticReport or NewRowSynthesis by itself, we get the following error if a categorical column in the real_data is represented as category or something different than object.

pandas.errors.UndefinedVariableError: name <value> is not defined

Steps to reproduce

In order to reproduce this, we can use category as data type in the real_data, here is a short example in order to reproduce it:

from sdmetrics.demos import load_single_table_demo
from sdmetrics.single_table import NewRowSynthesis

real_data, synthetic_data, metadata = load_single_table_demo()
real_data['gender'] = real_data['gender'].astype('category')

NewRowSynthesis.compute_breakdown(real_data, synthetic_data, metadata)

.................
File ~/.virtualenvs/SDMetrics/lib/python3.8/site-packages/pandas/core/computation/scope.py:246, in Scope.resolve(self, key, is_local)
    244     return self.temps[key]
    245 except KeyError as err:
--> 246     raise UndefinedVariableError(key, is_local) from err

UndefinedVariableError: name 'F' is not defined

Additional context

This bug occurs because of the following if else statement:

if real_data[field].dtype == 'O':
field_filter = f'`{field}` == {repr(row[field])}'
else:
field_filter = f'`{field}` == {row[field]}'

In order to fix this we have to accurately detect the data type and use the proper representation of the object.

@pvk-developer pvk-developer added the bug Something isn't working label Jul 21, 2023
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.

1 participant