CTGAN icon indicating copy to clipboard operation
CTGAN copied to clipboard

FutureWarning in data_transformer with pandas 1.5.0

Open AndresAlgaba opened this issue 3 years ago • 0 comments

Environment Details

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

  • CTGAN version: master branch
  • Python version: 3.9
  • Operating System: Windows

Error Description

With pandas version >=1.5.0, I get the following FutureWarning when sampling:

ctgan\data_transformer.py:188: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)` data.iloc[:, 1] = np.argmax(column_data[:, 1:], axis=1)

It is caused by the _inverse_transform_continuous method.

I will submit a PR as it seems to be a simple fix.

Steps to reproduce

Just running the example:

from ctgan import CTGAN
from ctgan import load_demo

data = load_demo()

# Names of the columns that are discrete
discrete_columns = [
    'workclass',
    'education',
    'marital-status',
    'occupation',
    'relationship',
    'race',
    'sex',
    'native-country',
    'income'
]

ctgan = CTGAN(epochs=10)
ctgan.fit(data, discrete_columns)

# Synthetic copy
samples = ctgan.sample(1000)

AndresAlgaba avatar Oct 02 '22 09:10 AndresAlgaba