@@ -1308,27 +1308,27 @@ def _validate_shuffle_split_init(test_size, train_size):
1308
1308
raise ValueError ('test_size and train_size can not both be None' )
1309
1309
1310
1310
if test_size is not None :
1311
- if np . asarray (test_size ). dtype . kind == 'f' :
1311
+ if isintance (test_size , float ) :
1312
1312
if test_size >= 1. :
1313
1313
raise ValueError (
1314
1314
'test_size=%f should be smaller '
1315
1315
'than 1.0 or be an integer' % test_size )
1316
- elif np . asarray (test_size ). dtype . kind != 'i' :
1316
+ elif instance (test_size , numbers . Integral ) :
1317
1317
# int values are checked during split based on the input
1318
1318
raise ValueError ("Invalid value for test_size: %r" % test_size )
1319
1319
1320
1320
if train_size is not None :
1321
- if np . asarray (train_size ). dtype . kind == 'f' :
1321
+ if isinstance (train_size , float ) :
1322
1322
if train_size >= 1. :
1323
1323
raise ValueError ("train_size=%f should be smaller "
1324
1324
"than 1.0 or be an integer" % train_size )
1325
- elif (np . asarray (test_size ). dtype . kind == 'f' and
1325
+ elif (isinstance (test_size , float ) and
1326
1326
(train_size + test_size ) > 1. ):
1327
1327
raise ValueError ('The sum of test_size and train_size = %f, '
1328
1328
'should be smaller than 1.0. Reduce '
1329
1329
'test_size and/or train_size.' %
1330
1330
(train_size + test_size ))
1331
- elif np . asarray (train_size ). dtype . kind != 'i' :
1331
+ elif isinstance (train_size , numbers . Integral ) :
1332
1332
# int values are checked during split based on the input
1333
1333
raise ValueError ("Invalid value for train_size: %r" % train_size )
1334
1334
@@ -1338,24 +1338,24 @@ def _validate_shuffle_split(n_samples, test_size, train_size):
1338
1338
Validation helper to check if the test/test sizes are meaningful wrt to the
1339
1339
size of the data (n_samples)
1340
1340
"""
1341
- if (test_size is not None and np . asarray (test_size ). dtype . kind == 'i' and
1341
+ if (test_size is not None and isinstance (test_size , numbers . Integral ) and
1342
1342
test_size >= n_samples ):
1343
1343
raise ValueError ('test_size=%d should be smaller than the number of '
1344
1344
'samples %d' % (test_size , n_samples ))
1345
1345
1346
- if (train_size is not None and np . asarray (train_size ). dtype . kind == 'i' and
1346
+ if (train_size is not None and isinstance (train_size , numbers . Integral ) and
1347
1347
train_size >= n_samples ):
1348
1348
raise ValueError ("train_size=%d should be smaller than the number of"
1349
1349
" samples %d" % (train_size , n_samples ))
1350
1350
1351
- if np . asarray (test_size ). dtype . kind == 'f' :
1351
+ if isinstance (test_size , float ) :
1352
1352
n_test = ceil (test_size * n_samples )
1353
- elif np . asarray (test_size ). dtype . kind == 'i' :
1353
+ elif isinstance (test_size , numbers . Integral ) :
1354
1354
n_test = float (test_size )
1355
1355
1356
1356
if train_size is None :
1357
1357
n_train = n_samples - n_test
1358
- elif np . asarray (train_size ). dtype . kind == 'f' :
1358
+ elif isinstance (train_size , float ) :
1359
1359
n_train = floor (train_size * n_samples )
1360
1360
else :
1361
1361
n_train = float (train_size )
0 commit comments