summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2016-01-10 11:44:31 -0700
committerCharles Harris <charlesr.harris@gmail.com>2016-01-10 11:44:31 -0700
commit3a9c90cbfd6057e9f124f3d31b82f8c0ad22cd20 (patch)
tree38def9a3432b2f3a1653975a8edcc5cfbaa76437 /numpy
parent81793fc67d5f34cef91797cbc07e98a3b9a6e97a (diff)
parentb23ec897fcbf1a0279a599c1ba301a2b01c09c88 (diff)
downloadnumpy-3a9c90cbfd6057e9f124f3d31b82f8c0ad22cd20.tar.gz
Merge pull request #6931 from gfyoung/random_integers_deprecate
DEP: Deprecate random_integers
Diffstat (limited to 'numpy')
-rw-r--r--numpy/random/mtrand/mtrand.pyx12
-rw-r--r--numpy/random/tests/test_random.py16
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))