Skip to content

Commit a18cb64

Browse files
Merge pull request #360 from PaulWestenthanner/feature/tox
Upgrade versions
2 parents 3ae3710 + ddb8a2e commit a18cb64

28 files changed

+153
-172
lines changed

.github/workflows/test-suite.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
python-version: ['3.5', '3.6', '3.7', '3.8', '3.9', '3.10']
18+
python-version: ['3.7', '3.8', '3.9', '3.10']
1919

2020
steps:
2121
- uses: actions/checkout@v2

category_encoders/backward_difference.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ def fit(self, X, y=None, **kwargs):
167167
[self.feature_names.remove(x) for x in self.drop_cols]
168168
except KeyError as e:
169169
if self.verbose > 0:
170-
print("Could not remove column from feature names."
171-
"Not found in generated cols.\n{}".format(e))
170+
print(f"Could not remove column from feature names. Not found in generated cols.\n{e}")
172171

173172
return self
174173

@@ -200,7 +199,7 @@ def transform(self, X, override_return_df=False):
200199

201200
# then make sure that it is the right size
202201
if X.shape[1] != self._dim:
203-
raise ValueError('Unexpected input dimension %d, expected %d' % (X.shape[1], self._dim, ))
202+
raise ValueError(f'Unexpected input dimension {X.shape[1]}, expected {self._dim}')
204203

205204
if not list(self.cols):
206205
return X
@@ -236,7 +235,7 @@ def fit_backward_difference_coding(col, values, handle_missing, handle_unknown):
236235

237236
backwards_difference_matrix = Diff().code_without_intercept(values_to_encode)
238237
df = pd.DataFrame(data=backwards_difference_matrix.matrix, index=values_to_encode,
239-
columns=[str(col) + '_%d' % (i, ) for i in range(len(backwards_difference_matrix.column_suffixes))])
238+
columns=[f"{col}_{i}" for i in range(len(backwards_difference_matrix.column_suffixes))])
240239

241240
if handle_unknown == 'return_nan':
242241
df.loc[-1] = np.nan

category_encoders/basen.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ def fit(self, X, y=None, **kwargs):
174174
[self.feature_names.remove(x) for x in self.drop_cols]
175175
except KeyError as e:
176176
if self.verbose > 0:
177-
print("Could not remove column from feature names."
178-
"Not found in generated cols.\n{}".format(e))
177+
print(f"Could not remove column from feature names. Not found in generated cols.\n{e}")
179178

180179
return self
181180

@@ -194,7 +193,7 @@ def fit_base_n_encoding(self, X):
194193

195194
digits = self.calc_required_digits(values)
196195
X_unique = pd.DataFrame(index=values,
197-
columns=[str(col) + '_%d' % x for x in range(digits)],
196+
columns=[f"{col}_{x}" for x in range(digits)],
198197
data=np.array([self.col_transform(x, digits) for x in range(1, len(values) + 1)]))
199198

200199
if self.handle_unknown == 'return_nan':
@@ -239,7 +238,7 @@ def transform(self, X, override_return_df=False):
239238

240239
# then make sure that it is the right size
241240
if X.shape[1] != self._dim:
242-
raise ValueError('Unexpected input dimension %d, expected %d' % (X.shape[1], self._dim,))
241+
raise ValueError(f'Unexpected input dimension {X.shape[1]}, expected {self._dim}')
243242

244243
if not list(self.cols):
245244
return X
@@ -290,10 +289,10 @@ def inverse_transform(self, X_in):
290289
# make sure that it is the right size
291290
if X.shape[1] != self._dim:
292291
if self.drop_invariant:
293-
raise ValueError("Unexpected input dimension %d, the attribute drop_invariant should "
294-
"be False when transforming the data" % (X.shape[1],))
292+
raise ValueError(f"Unexpected input dimension {X.shape[1]}, the attribute drop_invariant should "
293+
"be False when transforming the data")
295294
else:
296-
raise ValueError('Unexpected input dimension %d, expected %d' % (X.shape[1], self._dim,))
295+
raise ValueError(f'Unexpected input dimension {X.shape[1]}, expected {self._dim}')
297296

298297
if not list(self.cols):
299298
return X if self.return_df else X.values

category_encoders/cat_boost.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ def fit(self, X, y, **kwargs):
161161
[self.feature_names.remove(x) for x in self.drop_cols]
162162
except KeyError as e:
163163
if self.verbose > 0:
164-
print("Could not remove column from feature names."
165-
"Not found in generated cols.\n{}".format(e))
164+
print(f"Could not remove column from feature names. Not found in generated cols.\n{e}")
166165

167166
return self
168167

@@ -198,7 +197,7 @@ def transform(self, X, y=None, override_return_df=False):
198197

199198
# then make sure that it is the right size
200199
if X.shape[1] != self._dim:
201-
raise ValueError('Unexpected input dimension %d, expected %d' % (X.shape[1], self._dim,))
200+
raise ValueError(f'Unexpected input dimension {X.shape[1]}, expected {self._dim}')
202201

203202
if not list(self.cols):
204203
return X

category_encoders/count.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ def fit(self, X, y=None, **kwargs):
186186
[self.feature_names.remove(x) for x in self.drop_cols]
187187
except KeyError as e:
188188
if self.verbose > 0:
189-
print("Could not remove column from feature names."
190-
"Not found in generated cols.\n{}".format(e))
189+
print(f"Could not remove column from feature names. Not found in generated cols.\n{e}")
191190

192191
return self
193192

@@ -290,11 +289,7 @@ def _transform_count_encode(self, X_in, y):
290289
self._handle_unknown[col] == 'error'
291290
and X[col].isnull().any()
292291
):
293-
294-
raise ValueError(
295-
'Missing data found in column %s at transform time.'
296-
% (col,)
297-
)
292+
raise ValueError(f'Missing data found in column {col} at transform time.')
298293

299294
return X, self.mapping
300295

category_encoders/glmm.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ def fit(self, X, y, **kwargs):
172172
[self.feature_names.remove(x) for x in self.drop_cols]
173173
except KeyError as e:
174174
if self.verbose > 0:
175-
print("Could not remove column from feature names."
176-
"Not found in generated cols.\n{}".format(e))
175+
print(f"Could not remove column from feature names. Not found in generated cols.\n{e}")
177176
return self
178177

179178
def transform(self, X, y=None, override_return_df=False):
@@ -209,7 +208,7 @@ def transform(self, X, y=None, override_return_df=False):
209208

210209
# Then make sure that it is the right size
211210
if X.shape[1] != self._dim:
212-
raise ValueError('Unexpected input dimension %d, expected %d' % (X.shape[1], self._dim,))
211+
raise ValueError(f'Unexpected input dimension {X.shape[1]}, expected {self._dim}')
213212

214213
if not list(self.cols):
215214
return X

category_encoders/hashing.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ def fit(self, X, y=None, **kwargs):
175175
[self.feature_names.remove(x) for x in self.drop_cols]
176176
except KeyError as e:
177177
if self.verbose > 0:
178-
print("Could not remove column from feature names."
179-
"Not found in generated cols.\n{}".format(e))
178+
print(f"Could not remove column from feature names. Not found in generated cols.\n{e}")
180179

181180
return self
182181

@@ -228,7 +227,7 @@ def transform(self, X, override_return_df=False):
228227

229228
# then make sure that it is the right size
230229
if self.X.shape[1] != self._dim:
231-
raise ValueError('Unexpected input dimension %d, expected %d' % (self.X.shape[1], self._dim, ))
230+
raise ValueError(f'Unexpected input dimension {self.X.shape[1]}, expected {self._dim}')
232231

233232
if not list(self.cols):
234233
return self.X
@@ -299,7 +298,7 @@ def _transform(self, X, override_return_df=False):
299298

300299
# then make sure that it is the right size
301300
if X.shape[1] != self._dim:
302-
raise ValueError('Unexpected input dimension %d, expected %d' % (X.shape[1], self._dim, ))
301+
raise ValueError(f'Unexpected input dimension {X.shape[1]}, expected {self._dim}')
303302

304303
if not list(self.cols):
305304
return X
@@ -350,18 +349,9 @@ def hashing_trick(X_in, hashing_method='md5', N=2, cols=None, make_copy=False):
350349
for Large Scale Multitask Learning. Proc. ICML.
351350
352351
"""
353-
354-
try:
355-
if hashing_method not in hashlib.algorithms_available:
356-
raise ValueError('Hashing Method: %s Not Available. Please use one from: [%s]' % (
357-
hashing_method,
358-
', '.join([str(x) for x in hashlib.algorithms_available])
359-
))
360-
except Exception as e:
361-
try:
362-
_ = hashlib.new(hashing_method)
363-
except Exception as e:
364-
raise ValueError('Hashing Method: %s Not Found.')
352+
if hashing_method not in hashlib.algorithms_available:
353+
raise ValueError(f"Hashing Method: {hashing_method} not Available. "
354+
f"Please use one from: [{', '.join([str(x) for x in hashlib.algorithms_available])}]")
365355

366356
if make_copy:
367357
X = X_in.copy(deep=True)
@@ -383,7 +373,7 @@ def hash_fn(x):
383373
tmp[int(hasher.hexdigest(), 16) % N] += 1
384374
return pd.Series(tmp, index=new_cols)
385375

386-
new_cols = ['col_%d' % d for d in range(N)]
376+
new_cols = [f'col_{d}' for d in range(N)]
387377

388378
X_cat = X.loc[:, cols]
389379
X_num = X.loc[:, [x for x in X.columns.values if x not in cols]]

category_encoders/helmert.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ def fit(self, X, y=None, **kwargs):
164164
[self.feature_names.remove(x) for x in self.drop_cols]
165165
except KeyError as e:
166166
if self.verbose > 0:
167-
print("Could not remove column from feature names."
168-
"Not found in generated cols.\n{}".format(e))
167+
print(f"Could not remove column from feature names. Not found in generated cols.\n{e}")
169168

170169
return self
171170

@@ -197,7 +196,7 @@ def transform(self, X, override_return_df=False):
197196

198197
# then make sure that it is the right size
199198
if X.shape[1] != self._dim:
200-
raise ValueError('Unexpected input dimension %d, expected %d' % (X.shape[1], self._dim, ))
199+
raise ValueError(f'Unexpected input dimension {X.shape[1]}, expected {self._dim}')
201200

202201
if not list(self.cols):
203202
return X
@@ -233,8 +232,7 @@ def fit_helmert_coding(col, values, handle_missing, handle_unknown):
233232

234233
helmert_contrast_matrix = Helmert().code_without_intercept(values_to_encode)
235234
df = pd.DataFrame(data=helmert_contrast_matrix.matrix, index=values_to_encode,
236-
columns=[str(col) + '_%d' % (i,) for i in
237-
range(len(helmert_contrast_matrix.column_suffixes))])
235+
columns=[f"{col}_{i}" for i in range(len(helmert_contrast_matrix.column_suffixes))])
238236

239237
if handle_unknown == 'return_nan':
240238
df.loc[-1] = np.nan

category_encoders/james_stein.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ def fit(self, X, y, **kwargs):
235235
[self.feature_names.remove(x) for x in self.drop_cols]
236236
except KeyError as e:
237237
if self.verbose > 0:
238-
print("Could not remove column from feature names."
239-
"Not found in generated cols.\n{}".format(e))
238+
print(f"Could not remove column from feature names. Not found in generated cols.\n{e}")
240239
return self
241240

242241
def transform(self, X, y=None, override_return_df=False):
@@ -272,7 +271,7 @@ def transform(self, X, y=None, override_return_df=False):
272271

273272
# Then make sure that it is the right size
274273
if X.shape[1] != self._dim:
275-
raise ValueError('Unexpected input dimension %d, expected %d' % (X.shape[1], self._dim,))
274+
raise ValueError(f'Unexpected input dimension {X.shape[1]}, expected {self._dim}')
276275

277276
if not list(self.cols):
278277
return X

category_encoders/leave_one_out.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ def fit(self, X, y, **kwargs):
146146
[self.feature_names.remove(x) for x in self.drop_cols]
147147
except KeyError as e:
148148
if self.verbose > 0:
149-
print("Could not remove column from feature names."
150-
"Not found in generated cols.\n{}".format(e))
149+
print(f"Could not remove column from feature names. Not found in generated cols.\n{e}")
151150

152151
return self
153152

@@ -185,7 +184,7 @@ def transform(self, X, y=None, override_return_df=False):
185184

186185
# then make sure that it is the right size
187186
if X.shape[1] != self._dim:
188-
raise ValueError('Unexpected input dimension %d, expected %d' % (X.shape[1], self._dim,))
187+
raise ValueError(f'Unexpected input dimension {X.shape[1]}, expected {self._dim}')
189188

190189
if not list(self.cols):
191190
return X

0 commit comments

Comments
 (0)