diff options
author | Ross Barnowski <rossbar@berkeley.edu> | 2021-09-12 13:38:04 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-12 14:38:04 -0400 |
commit | 4d1b8ecc9396fd9cea3fe8e65c4dcb400f6c8b26 (patch) | |
tree | 6d5aa4cec587a1bd70245f2b83560f422f981471 /networkx/utils/decorators.py | |
parent | fea134b710ef2e9636428a868022e1aae6937e78 (diff) | |
download | networkx-4d1b8ecc9396fd9cea3fe8e65c4dcb400f6c8b26.tar.gz |
Deprecate `random_state` decorator (#5055)
* Reorganize aliases and deprecate random_state.
* Rm internal uses of random_state.
* Update tests.
Rm tests or rename to use np_random_state.
* Update reference guide.
* Update deprecations.rst.
* Remove preserve_random_state from refguide.
* Add deprecation to release notes.
Diffstat (limited to 'networkx/utils/decorators.py')
-rw-r--r-- | networkx/utils/decorators.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/networkx/utils/decorators.py b/networkx/utils/decorators.py index a9dc032a..cab7ad54 100644 --- a/networkx/utils/decorators.py +++ b/networkx/utils/decorators.py @@ -2,7 +2,6 @@ from collections import defaultdict from os.path import splitext from contextlib import contextmanager from pathlib import Path -import warnings import networkx as nx from networkx.utils import create_random_state, create_py_random_state @@ -285,6 +284,8 @@ def preserve_random_state(func): ----- If numpy.random is not importable, the state is not saved or restored. """ + import warnings + msg = "preserve_random_state is deprecated and will be removed in 3.0." warnings.warn(msg, DeprecationWarning) @@ -310,7 +311,7 @@ def preserve_random_state(func): return func -def random_state(random_state_argument): +def np_random_state(random_state_argument): """Decorator to generate a `numpy.random.RandomState` instance. The decorator processes the argument indicated by `random_state_argument` @@ -354,7 +355,25 @@ def random_state(random_state_argument): return argmap(create_random_state, random_state_argument) -np_random_state = random_state +def random_state(random_state_argument): + """Decorator to generate a `numpy.random.RandomState` instance. + + .. deprecated:: 2.7 + + This function is a deprecated alias for `np_random_state` and will be + removed in version 3.0. Use np_random_state instead. + """ + import warnings + + warnings.warn( + ( + "`random_state` is a deprecated alias for `np_random_state`\n" + "and will be removed in version 3.0. Use `np_random_state` instead." + ), + DeprecationWarning, + stacklevel=2, + ) + return np_random_state(random_state_argument) def py_random_state(random_state_argument): |