Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f0e0776

Browse files
committed
MNT Use isinstance(..., float/numbers.Integral)
1 parent b966b44 commit f0e0776

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

sklearn/model_selection/_split.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1308,27 +1308,27 @@ def _validate_shuffle_split_init(test_size, train_size):
13081308
raise ValueError('test_size and train_size can not both be None')
13091309

13101310
if test_size is not None:
1311-
if np.asarray(test_size).dtype.kind == 'f':
1311+
if isintance(test_size, float):
13121312
if test_size >= 1.:
13131313
raise ValueError(
13141314
'test_size=%f should be smaller '
13151315
'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):
13171317
# int values are checked during split based on the input
13181318
raise ValueError("Invalid value for test_size: %r" % test_size)
13191319

13201320
if train_size is not None:
1321-
if np.asarray(train_size).dtype.kind == 'f':
1321+
if isinstance(train_size, float):
13221322
if train_size >= 1.:
13231323
raise ValueError("train_size=%f should be smaller "
13241324
"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
13261326
(train_size + test_size) > 1.):
13271327
raise ValueError('The sum of test_size and train_size = %f, '
13281328
'should be smaller than 1.0. Reduce '
13291329
'test_size and/or train_size.' %
13301330
(train_size + test_size))
1331-
elif np.asarray(train_size).dtype.kind != 'i':
1331+
elif isinstance(train_size, numbers.Integral):
13321332
# int values are checked during split based on the input
13331333
raise ValueError("Invalid value for train_size: %r" % train_size)
13341334

@@ -1338,24 +1338,24 @@ def _validate_shuffle_split(n_samples, test_size, train_size):
13381338
Validation helper to check if the test/test sizes are meaningful wrt to the
13391339
size of the data (n_samples)
13401340
"""
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
13421342
test_size >= n_samples):
13431343
raise ValueError('test_size=%d should be smaller than the number of '
13441344
'samples %d' % (test_size, n_samples))
13451345

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
13471347
train_size >= n_samples):
13481348
raise ValueError("train_size=%d should be smaller than the number of"
13491349
" samples %d" % (train_size, n_samples))
13501350

1351-
if np.asarray(test_size).dtype.kind == 'f':
1351+
if isinstance(test_size, float):
13521352
n_test = ceil(test_size * n_samples)
1353-
elif np.asarray(test_size).dtype.kind == 'i':
1353+
elif isinstance(test_size, numbers.Integral):
13541354
n_test = float(test_size)
13551355

13561356
if train_size is None:
13571357
n_train = n_samples - n_test
1358-
elif np.asarray(train_size).dtype.kind == 'f':
1358+
elif isinstance(train_size, float):
13591359
n_train = floor(train_size * n_samples)
13601360
else:
13611361
n_train = float(train_size)

0 commit comments

Comments
 (0)