Skip to content

Commit 41217ce

Browse files
committed
Moved X.columns check into base encoder
1 parent 52bbb3c commit 41217ce

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

category_encoders/target_encoder.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ def _check_dict_key_tuples(self, d):
165165

166166
def _fit(self, X, y, **kwargs):
167167
if isinstance(self.hierarchy, dict):
168-
if not set(self.cols).issubset(X.columns):
169-
raise ValueError('X does not contain the columns listed in cols')
170168
X_hier = pd.DataFrame()
171169
for switch in self.hierarchy:
172170
if switch in self.cols:

category_encoders/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ def fit(self, X, y=None, **kwargs):
295295
self._dim = X.shape[1]
296296
self._get_fit_columns(X)
297297

298+
if not set(self.cols).issubset(X.columns):
299+
raise ValueError('X does not contain the columns listed in cols')
300+
298301
if self.handle_missing == 'error':
299302
if X[self.cols].isnull().any().any():
300303
raise ValueError('Columns to be encoded can not contain null')

0 commit comments

Comments
 (0)