Skip to content

Commit aed0fb2

Browse files
changes after review
1 parent bbe2bb7 commit aed0fb2

File tree

8 files changed

+13
-21
lines changed

8 files changed

+13
-21
lines changed

category_encoders/cat_boost.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,8 @@ def __init__(self, verbose=0, cols=None, drop_invariant=False, return_df=True,
105105
def _fit(self, X, y, **kwargs):
106106
X = X.copy(deep=True)
107107

108-
if self.cols is None:
109-
cols = X.columns.values
110-
else:
111-
cols = self.cols
112-
113108
self._mean = y.mean()
114-
self.mapping = {col: self._fit_column_map(X[col], y) for col in cols}
109+
self.mapping = {col: self._fit_column_map(X[col], y) for col in self.cols}
115110

116111
def _transform(self, X, y=None):
117112
random_state_ = check_random_state(self.random_state)

category_encoders/count.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,16 @@ def _fit(self, X, y=None, **kwargs):
139139
return self
140140

141141
def _transform(self, X):
142-
"""Perform the transform count encoding."""
143142
for col in self.cols:
144-
X[col] = X[col].fillna(value=np.nan)
143+
# Treat None as np.nan
144+
X[col] = pd.Series([el if el is not None else np.NaN for el in X[col]], index=X[col].index)
145+
if self.handle_missing == "value":
146+
if not util.is_category(X[col].dtype):
147+
X[col] = X[col].fillna(np.nan)
145148

146149
if self._min_group_size is not None:
147150
if col in self._min_group_categories.keys():
148-
X[col] = (
149-
X[col].map(self._min_group_categories[col])
150-
.fillna(X[col])
151-
)
151+
X[col] = X[col].map(self._min_group_categories[col]).fillna(X[col])
152152

153153
X[col] = X[col].astype(object).map(self.mapping[col])
154154
if isinstance(self._handle_unknown[col], (int, np.integer)):
@@ -164,7 +164,6 @@ def _transform(self, X):
164164
self._handle_unknown[col] == 'error'
165165
and X[col].isnull().any()
166166
):
167-
168167
raise ValueError(f'Missing data found in column {col} at transform time.')
169168
return X
170169

category_encoders/target_encoder.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,11 @@ def __init__(self, verbose=0, cols=None, drop_invariant=False, return_df=True, h
8989
self.ordinal_encoder = None
9090
self.min_samples_leaf = min_samples_leaf
9191
if min_samples_leaf == 1:
92-
self.smoothing = float(
93-
smoothing) # Make smoothing a float so that python 2 does not treat as integer division
9492
warnings.warn("Default parameter min_samples_leaf will change in version 2.6."
9593
"See https://github.com/scikit-learn-contrib/category_encoders/issues/327",
9694
category=FutureWarning)
9795
self.smoothing = smoothing
98-
if min_samples_leaf == 1.0:
96+
if smoothing == 1.0:
9997
warnings.warn("Default parameter smoothing will change in version 2.6."
10098
"See https://github.com/scikit-learn-contrib/category_encoders/issues/327",
10199
category=FutureWarning)

docs/source/catboost.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CatBoost Encoder
2-
==============
2+
================
33

44
.. autoclass:: category_encoders.cat_boost.CatBoostEncoder
55
:members:

docs/source/jamesstein.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
James-Stein Encoder
2-
==============
2+
===================
33

44
.. autoclass:: category_encoders.james_stein.JamesSteinEncoder
55
:members:

docs/source/quantile.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Quantile Encoder
2-
==============
2+
================
33

44
.. autoclass:: category_encoders.quantile_encoder.QuantileEncoder
55
:members:

docs/source/summary.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Summary Encoder
2-
==============
2+
===============
33

44
.. autoclass:: category_encoders.quantile_encoder.SummaryEncoder
55
:members:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ scipy>=1.0.0
44
statsmodels>=0.9.0
55
pandas>=1.0.5
66
patsy>=0.5.1
7-
unittest2
7+
unittest2

0 commit comments

Comments
 (0)