Skip to content

Commit b461123

Browse files
Merge pull request #354 from PaulWestenthanner/fix/issue_353
fixed bug in LOO encoder reported in #353
2 parents 12e2048 + bb0f884 commit b461123

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-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')

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
sphinx>=3.0
12
sphinx_rtd_theme
23
numpydoc
34
numpy>=1.14.0

0 commit comments

Comments
 (0)