Skip to content

Commit ece6cc6

Browse files
fixed bug in LOO encoder reported in #353
1 parent 4a48107 commit ece6cc6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

category_encoders/leave_one_out.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ def transform_leave_one_out(self, X, y, mapping=None):
243243
is_unknown_value = X[col].isin(unseen_values.dropna().astype(object))
244244

245245
if X[col].dtype.name == 'category': # Pandas 0.24 tries hard to preserve categorical data type
246-
X[col] = X[col].astype(str)
246+
index_dtype = X[col].dtype.categories.dtype
247+
X[col] = X[col].astype(index_dtype)
247248

248249
if self.handle_unknown == 'error' and is_unknown_value.any():
249250
raise ValueError('Columns to be encoded can not contain new values')

0 commit comments

Comments
 (0)