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

Conditioning on the constraint column of the ColumnFormula constraint #506

Closed
fealho opened this issue Jul 12, 2021 · 0 comments · Fixed by #542
Closed

Conditioning on the constraint column of the ColumnFormula constraint #506

fealho opened this issue Jul 12, 2021 · 0 comments · Fixed by #542
Assignees
Labels
bug Something isn't working
Milestone

Comments

@fealho
Copy link
Member

fealho commented Jul 12, 2021

Conditioning on the constraint column when using the ColumnFormula constraint causes the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/var/folders/3p/f4b70gn5165464cqyvg157qw0000gn/T/ipykernel_42215/2787579389.py in <module>
----> 1 samples = model.sample(10, conditions={'b': 1})
      2 samples

~/Desktop/SDV/sdv/tabular/base.py in sample(self, num_rows, max_retries, max_rows_multiplier, conditions, float_rtol, graceful_reject_sampling)
    471             else:
    472                 transformed_conditions_in_group = transformed_conditions.loc[condition_indices]
--> 473                 transformed_groups = transformed_conditions_in_group.groupby(transformed_columns)
    474                 for transformed_group, transformed_dataframe in transformed_groups:
    475                     if not isinstance(transformed_group, tuple):

~/opt/anaconda3/envs/test/lib/python3.8/site-packages/pandas/core/frame.py in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, observed, dropna)
   6513         axis = self._get_axis_number(axis)
   6514 
-> 6515         return DataFrameGroupBy(
   6516             obj=self,
   6517             keys=by,

~/opt/anaconda3/envs/test/lib/python3.8/site-packages/pandas/core/groupby/groupby.py in __init__(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, observed, mutated, dropna)
    523             from pandas.core.groupby.grouper import get_grouper
    524 
--> 525             grouper, exclusions, obj = get_grouper(
    526                 obj,
    527                 keys,

~/opt/anaconda3/envs/test/lib/python3.8/site-packages/pandas/core/groupby/grouper.py in get_grouper(obj, key, axis, level, sort, observed, mutated, validate, dropna)
    819 
    820     if len(groupings) == 0 and len(obj):
--> 821         raise ValueError("No group keys passed!")
    822     elif len(groupings) == 0:
    823         groupings.append(Grouping(Index([], dtype="int"), np.array([], dtype=np.intp)))

ValueError: No group keys passed!

Code to reproduce it:

import pandas as pd
from sdv.constraints import *
from sdv.tabular import *

ones = [1 for i in range(10)]
data = pd.DataFrame({
    'a': ones,
    'b': ones,
    'c': ones
})

def formula(data):
    return data['a']

constraint = ColumnFormula(
    column='b',
    formula=formula
)

model = GaussianCopula(constraints=[constraint])
model.fit(data)
samples = model.sample(10, conditions={'b': 1})
samples
@fealho fealho added bug Something isn't working pending review labels Jul 12, 2021
@katxiao katxiao self-assigned this Aug 2, 2021
@csala csala added this to the 0.12.0 milestone Aug 12, 2021
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