Repository navigation
Conversation
set_seed() only accepted Python ints, so NumPy integer scalars (from rng.integers(), np.arange() or a pandas column) raised "seed must be a non-negative integer", both directly and as an estimator's random_state. Accept any numbers.Integral and convert it to int before seeding, and store TabularDataModule.random_state as an int for torch.Generator. Fixes #535
int() also turned 1.5 into 1 and "7" into 7, which used to fail. Only Python and NumPy integers are converted now. The set_seed comment names the call that actually rejects NumPy integers (random.seed), and the parametrized seed tests get readable ids. Refs #535
This branch has not been deployed
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.
Fixes #535
Problem
set_seed()validated seeds withisinstance(seed, int), so NumPy integer scalars raisedValueError: seed must be a non-negative integer. These come fromrng.integers(...),np.arange(...)or a pandas column. The check failed both for direct calls and forrandom_state=np.int64(...)on any estimator.TabularDataModulealso passedrandom_statestraight totorch.Generator.manual_seed(), which needs a Pythonint.Fix
deeptab/core/reproducibility.py:set_seed()accepts any non-negativenumbers.Integraland converts it withint()before seeding Python, NumPy and torch. Non-integers (1.0,"7",np.float64) are still rejected. The numpydoc mentions NumPy integer scalars.deeptab/data/datamodule.py:TabularDataModulestoresrandom_stateas a Pythonint(orNone). Python and NumPy integers are converted, and the parameter is annotatedint | np.integer | None; floats and strings raiseTypeErrorinstead of being truncated byint().Tests
In
tests/core/test_random_state.py:TestSetSeedPrimitives::test_numpy_integer_seed_matches_python_int[int64|uint32|int32]: the same torch draws as the equivalent Pythonint.TestSetSeedPrimitives::test_non_integer_seed_is_still_rejected[float|str|float64]test_datamodule_rejects_non_integer_random_state[float|str]andtest_datamodule_converts_numpy_integer_random_statetest_estimator_accepts_numpy_integer_random_state: anMLPRegressorwithrandom_state=np.int64(...)gives the same predictions as with the Pythonint.The NumPy-integer tests fail on
mainand pass with this change.Docs
The
set_seeddocstring and theTabularDataModulerandom_stateparameter are updated. No page changes needed.Checks
just test: 3246 passed, 46 skipped, 28 xfailed; coverage 91.29%just docs: build succeeded (warnings treated as errors)just check: all hooks passed (ruff, prettier, pyright)