diff options
author | gfyoung <gfyoung@mit.edu> | 2016-01-03 15:22:40 -0800 |
---|---|---|
committer | gfyoung <gfyoung@mit.edu> | 2016-01-10 18:33:41 +0000 |
commit | b23ec897fcbf1a0279a599c1ba301a2b01c09c88 (patch) | |
tree | 38def9a3432b2f3a1653975a8edcc5cfbaa76437 /numpy/random | |
parent | 81793fc67d5f34cef91797cbc07e98a3b9a6e97a (diff) | |
download | numpy-b23ec897fcbf1a0279a599c1ba301a2b01c09c88.tar.gz |
DEP: Deprecate random_integers
Diffstat (limited to 'numpy/random')
-rw-r--r-- | numpy/random/mtrand/mtrand.pyx | 12 | ||||
-rw-r--r-- | numpy/random/tests/test_random.py | 16 |
2 files changed, 28 insertions, 0 deletions
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx index 3a4e132ec..ff8171d45 100644 --- a/numpy/random/mtrand/mtrand.pyx +++ b/numpy/random/mtrand/mtrand.pyx @@ -1683,6 +1683,10 @@ cdef class RandomState: type translates to the C long type used by Python 2 for "short" integers and its precision is platform dependent. + This function has been deprecated. Use randint instead. + + .. deprecated:: 1.11.0 + Parameters ---------- low : int @@ -1748,9 +1752,17 @@ cdef class RandomState: """ if high is None: + warnings.warn(("This function is deprecated. Please call " + "randint(1, {low} + 1) instead".format(low=low)), + DeprecationWarning) high = low low = 1 + else: + warnings.warn(("This function is deprecated. Please call " + "randint({low}, {high} + 1) instead".format( + low=low, high=high)), DeprecationWarning) + return self.randint(low, high + 1, size=size, dtype='l') diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py index a6783fe8f..37c1876bf 100644 --- a/numpy/random/tests/test_random.py +++ b/numpy/random/tests/test_random.py @@ -7,6 +7,8 @@ from numpy.testing import ( from numpy import random from numpy.compat import asbytes import sys +import warnings + class TestSeed(TestCase): def test_scalar(self): @@ -255,6 +257,20 @@ class TestRandomDist(TestCase): desired = np.iinfo('l').max np.testing.assert_equal(actual, desired) + def test_random_integers_deprecated(self): + with warnings.catch_warnings(): + warnings.simplefilter("error", DeprecationWarning) + + # DeprecationWarning raised with high == None + assert_raises(DeprecationWarning, + np.random.random_integers, + np.iinfo('l').max) + + # DeprecationWarning raised with high != None + assert_raises(DeprecationWarning, + np.random.random_integers, + np.iinfo('l').max, np.iinfo('l').max) + def test_random_sample(self): np.random.seed(self.seed) actual = np.random.random_sample((3, 2)) |