Skip to content

[MNT] Eliminate global np.random.seed calls to prevent global state mutation. #1039

Description

@krsatyamthakur-droid

I found some np.random.seed() calls in a few regressors that are currently mutating the global NumPy state. This is generally bad practice for library code because it can cause sneaky side effects in a user's environment and makes it hard to get reproducible results when running things in parallel.

We should clean these up and switch to proper local random state management using check_random_state.

Impacted files:

  • skpro/regression/bootstrap.py: Line 113
  • skpro/regression/enbpi.py: Line 163
  • skpro/regression/ensemble/_bagging.py: Line 133
  • skpro/regression/mdn.py: Line 441

Proposed fix:

  • Remove the np.random.seed(...) calls.
  • Use sklearn.utils.check_random_state to handle the random_state parameter locally.
  • For mdn.py and _bagging.py, we'll need to add the check_random_state initialization to store a local RNG.
  • Ensure any sampling or noise logic uses that local RNG instead of the global np.random module.

bootstrap.py and enbpi.py already have a self._random_state object initialized, so there we just need to delete the global seed line.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    maintenanceContinuous integration, unit testing & package distribution

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions