@@ -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 ]]
0 commit comments