kearnz / autoimpute

Python package for Imputation Methods
MIT License
237 stars 19 forks source link

Transform fails if all column values are missing #85

Open attekei opened 1 year ago

attekei commented 1 year ago

I have an imputer which has already been fitted. I use it later for imputing missing data before doing classification. The issue is that if e.g. I only impute a single row, it can have missing data. Calling imputer.transform(single_row_df) then fails because some columns don't have any values.

I can make it work by adding one completely defined dummy row, and dropping it after imputation. Here's how I do it in the code:

def impute(self, features):
    # First two columns are floats, rest are booleans
    features.loc[len(features)] = 2 * [0] + (features.shape[1] - 2) * [True]
    X = self.imputer.transform(features)
    return X.iloc[:-1]

This solution naturally isn't optimal.

Thanks btw for the great work with the library!