Skip to content

Commit 3f462a8

Browse files
committed
fixes #114
1 parent 0e8f669 commit 3f462a8

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

category_encoders/leave_one_out.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ def fit(self, X, y, **kwargs):
112112

113113
# first check the type
114114
X = convert_input(X)
115-
y = pd.Series(y, name='target')
115+
if isinstance(y, pd.DataFrame):
116+
y = y.iloc[:,0]
117+
else:
118+
y = pd.Series(y, name='target')
116119
if X.shape[0] != y.shape[0]:
117120
raise ValueError("The length of X is " + str(X.shape[0]) + " but length of y is " + str(y.shape[0]) + ".")
118121

@@ -171,7 +174,10 @@ def transform(self, X, y=None):
171174

172175
# if we are encoding the training data, we have to check the target
173176
if y is not None:
174-
y = pd.Series(y, name='target')
177+
if isinstance(y, pd.DataFrame):
178+
y = y.iloc[:, 0]
179+
else:
180+
y = pd.Series(y, name='target')
175181
if X.shape[0] != y.shape[0]:
176182
raise ValueError("The length of X is " + str(X.shape[0]) + " but length of y is " + str(y.shape[0]) + ".")
177183

category_encoders/target_encoder.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ def fit(self, X, y, **kwargs):
104104

105105
# first check the type
106106
X = convert_input(X)
107-
y = pd.Series(y, name='target')
107+
if isinstance(y, pd.DataFrame):
108+
y = y.iloc[:,0]
109+
else:
110+
y = pd.Series(y, name='target')
108111
if X.shape[0] != y.shape[0]:
109112
raise ValueError("The length of X is " + str(X.shape[0]) + " but length of y is " + str(y.shape[0]) + ".")
110113

@@ -158,7 +161,10 @@ def transform(self, X, y=None):
158161

159162
# if we are encoding the training data, we have to check the target
160163
if y is not None:
161-
y = pd.Series(y, name='target')
164+
if isinstance(y, pd.DataFrame):
165+
y = y.iloc[:, 0]
166+
else:
167+
y = pd.Series(y, name='target')
162168
if X.shape[0] != y.shape[0]:
163169
raise ValueError("The length of X is " + str(X.shape[0]) + " but length of y is " + str(y.shape[0]) + ".")
164170

category_encoders/woe.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ def fit(self, X, y, **kwargs):
113113

114114
# Unite parameters into pandas types
115115
X = convert_input(X)
116-
y = pd.Series(y, name='target')
116+
if isinstance(y, pd.DataFrame):
117+
y = y.iloc[:,0]
118+
else:
119+
y = pd.Series(y, name='target')
117120

118121
# The lengths must be equal
119122
if X.shape[0] != y.shape[0]:
@@ -181,7 +184,10 @@ def transform(self, X, y=None):
181184

182185
# If we are encoding the training data, we have to check the target
183186
if y is not None:
184-
y = pd.Series(y, name='target')
187+
if isinstance(y, pd.DataFrame):
188+
y = y.iloc[:, 0]
189+
else:
190+
y = pd.Series(y, name='target')
185191
if X.shape[0] != y.shape[0]:
186192
raise ValueError("The length of X is " + str(X.shape[0]) + " but length of y is " + str(y.shape[0]) + ".")
187193

0 commit comments

Comments
 (0)