@@ -175,8 +175,7 @@ def fit(self, X, y=None, **kwargs):
175
175
[self .feature_names .remove (x ) for x in self .drop_cols ]
176
176
except KeyError as e :
177
177
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 } " )
180
179
181
180
return self
182
181
@@ -228,7 +227,7 @@ def transform(self, X, override_return_df=False):
228
227
229
228
# then make sure that it is the right size
230
229
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 } ' )
232
231
233
232
if not list (self .cols ):
234
233
return self .X
@@ -299,7 +298,7 @@ def _transform(self, X, override_return_df=False):
299
298
300
299
# then make sure that it is the right size
301
300
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 } ' )
303
302
304
303
if not list (self .cols ):
305
304
return X
@@ -350,18 +349,9 @@ def hashing_trick(X_in, hashing_method='md5', N=2, cols=None, make_copy=False):
350
349
for Large Scale Multitask Learning. Proc. ICML.
351
350
352
351
"""
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 ])} ]" )
365
355
366
356
if make_copy :
367
357
X = X_in .copy (deep = True )
@@ -383,7 +373,7 @@ def hash_fn(x):
383
373
tmp [int (hasher .hexdigest (), 16 ) % N ] += 1
384
374
return pd .Series (tmp , index = new_cols )
385
375
386
- new_cols = ['col_%d' % d for d in range (N )]
376
+ new_cols = [f 'col_{ d } ' for d in range (N )]
387
377
388
378
X_cat = X .loc [:, cols ]
389
379
X_num = X .loc [:, [x for x in X .columns .values if x not in cols ]]
0 commit comments