@@ -48,8 +48,7 @@ def train_test_split_weights(df, weights=None, test_size=0.25, train_size=None,
4848 if weights is None :
4949 if test_size == 0 or train_size == 0 :
5050 raise ValueError (
51- "test_size={0} or train_size={1} cannot be null (1)."
52- "" .format (test_size , train_size ))
51+ f"test_size={ test_size } or train_size={ train_size } cannot be null (1)." )
5352 return train_test_split (df , test_size = test_size ,
5453 train_size = train_size ,
5554 random_state = random_state )
@@ -69,8 +68,7 @@ def train_test_split_weights(df, weights=None, test_size=0.25, train_size=None,
6968 test_size = 1 - p
7069 if p is None or min (test_size , p ) <= 0 :
7170 raise ValueError (
72- "test_size={0} or train_size={1} cannot be null (2)."
73- "" .format (test_size , train_size ))
71+ f"test_size={ test_size } or train_size={ train_size } cannot be null (2)." )
7472 ratio = test_size / p
7573
7674 if random_state is None :
@@ -330,11 +328,9 @@ def do_connex_components(dfrows, local_groups, kb, sib):
330328 grsum = dfids [[name , one ]].groupby (name , as_index = False ).sum ()
331329 if fLOG :
332330 for g in groups :
333- fLOG ("[train_test_connex_split] #nb in '{0}': {1}" .format (
334- g , len (set (dfids [g ]))))
331+ fLOG (f"[train_test_connex_split] #nb in '{ g } ': { len (set (dfids [g ]))} " )
335332 fLOG (
336- "[train_test_connex_split] #connex {0}/{1}" .format (
337- grsum .shape [0 ], dfids .shape [0 ]))
333+ f"[train_test_connex_split] #connex { grsum .shape [0 ]} /{ dfids .shape [0 ]} " )
338334 if grsum .shape [0 ] <= 1 :
339335 raise ValueError ( # pragma: no cover
340336 "Every element is in the same connected components." )
@@ -358,10 +354,9 @@ def do_connex_components(dfrows, local_groups, kb, sib):
358354 "={2}/{3}" .format (k , v , cum , len (elements )))
359355
360356 # Most important component
361- fLOG ('[train_test_connex_split] first row of the biggest component '
362- '{0}' .format (maxc ))
357+ fLOG (f'[train_test_connex_split] first row of the biggest component { maxc } ' )
363358 tdf = dfids [dfids [name ] == maxc [0 ]]
364- fLOG ('[train_test_connex_split] \n {0}' . format ( tdf .head (n = 10 )) )
359+ fLOG (f '[train_test_connex_split] \n { tdf .head (n = 10 )} ' )
365360
366361 # Splits.
367362 train , test = train_test_split_weights (
@@ -457,8 +452,7 @@ def train_test_apart_stratify(df, group, test_size=0.25, train_size=None,
457452 test_size = 1 - p
458453 if p is None or min (test_size , p ) <= 0 :
459454 raise ValueError ( # pragma: no cover
460- "test_size={0} or train_size={1} cannot be null" .format (
461- test_size , train_size ))
455+ f"test_size={ test_size } or train_size={ train_size } cannot be null" )
462456
463457 couples = df [[group , stratify ]].itertuples (name = None , index = False )
464458 hist = Counter (df [stratify ])
0 commit comments