Accept numpy integers as train_size / test_size in train_test_split - #8442
Open
LeSingh1 wants to merge 1 commit into
Open
Accept numpy integers as train_size / test_size in train_test_split#8442LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
`Dataset.train_test_split()` decides between "number of rows" and "fraction"
with `isinstance(test_size, int)` / `isinstance(test_size, float)`, and rejects
anything else:
ds.train_test_split(test_size=np.int64(2))
# ValueError: Invalid value for test_size: 2 of type <class 'numpy.int64'>
numpy floats are subclasses of `float` so they already work, but numpy integers
are not subclasses of `int`, which makes the behaviour inconsistent for values
that come out of the same numpy computation.
Convert numpy integers to `int` before the checks.
LeSingh1
force-pushed
the
fix-tts-numpy-int
branch
from
August 9, 2026 02:20
0bb6a46 to
8ce7e3f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dataset.train_test_split()usesisinstance(..., int)/isinstance(..., float)to tell "a number of rows" from "a fraction", and rejects everything else:numpy floats are subclasses of
float, so they already work. numpy integers are not subclasses ofint, so they don't:The asymmetry is accidental, and the error is confusing because the printed value (
2) looks perfectly valid. numpy integers turn up naturally —np.floor(0.2 * len(ds)).astype(int), a value read out of a numpy array, a pandas.nunique(), etc.sklearn.model_selection.train_test_split, which this API is modelled on, accepts them.This PR converts numpy integers to
intbefore the checks, leaving the int/float semantics untouched.Added
tests/test_arrow_dataset.py::test_train_test_split_with_numpy_integer_sizes, parametrized overint32,int64anduint8, covering bothtest_sizeandtrain_size. All three fail onmain.