Skip to content

Commit d120937

Browse files
Merge pull request #356 from PaulWestenthanner/fix/issue332
Fix/issue332
2 parents b461123 + 394b431 commit d120937

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
'Programming Language :: Python :: 3',
2626
],
2727
keywords='python data science machine learning pandas sklearn',
28-
packages=find_packages(exclude=['tests*']),
28+
packages=find_packages(include=['category_encoders']),
2929
include_package_data=True,
3030
author='Will McGinnis',
3131
install_requires=[

tests/test_leave_one_out.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,23 @@ def test_HandleUnknownValue_HaveUnknownInTest_ExpectMean(self):
116116
obtained = ce_leave.transform(test, test_target)
117117

118118
self.assertEqual([1.0, .6], list(obtained['color']))
119+
120+
def test_leave_one_out_categorical(self):
121+
"""
122+
test that if the input is a pd.Categorical the output is the same as for string columns
123+
:return:
124+
"""
125+
df = pd.DataFrame({
126+
'color_str': ["a", "a", "a", "b", "b", "b"],
127+
'color_num_cat': pd.Categorical([1.0, 1.0, 1.0, 2.0, 2.0, 2.0]),
128+
'color_str_cat': pd.Categorical(["a", "a", "a", "b", "b", "b"]),
129+
'outcome': [1, 0, 0, 1, 0, 1]})
130+
131+
X = df.drop('outcome', axis=1)
132+
y = df["outcome"]
133+
134+
ce_leave = encoders.LeaveOneOutEncoder()
135+
obtained = ce_leave.fit_transform(X, y)
136+
137+
for col in obtained.columns:
138+
self.assertEqual([0.0, 0.5, 0.5, 0.5, 1.0, 0.5], list(obtained[col]))

0 commit comments

Comments
 (0)