summaryrefslogtreecommitdiff
path: root/numpy/random/tests/test_random.py
diff options
context:
space:
mode:
authorgfyoung <gfyoung17@gmail.com>2016-02-19 05:14:49 +0000
committergfyoung <gfyoung17@gmail.com>2016-02-19 06:16:11 +0000
commit4f91544af2a74bc2dcecfce5db05b015f26721e4 (patch)
tree79744f6d06eda3e6a7203d94e657cfd433af2df7 /numpy/random/tests/test_random.py
parent711b2a9ccfb54c09cdc483ee511035bda60f3f0b (diff)
downloadnumpy-4f91544af2a74bc2dcecfce5db05b015f26721e4.tar.gz
BUG: Make randint backwards compatible with pandas
The 'pandas' library expects Python integers to be returned, so this commit changes the API so that the default is 'np.int' which converts to native Python integer types when a singleton is being generated with this function. Closes gh-7284.
Diffstat (limited to 'numpy/random/tests/test_random.py')
-rw-r--r--numpy/random/tests/test_random.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
index fac287b3f..a07fa52f5 100644
--- a/numpy/random/tests/test_random.py
+++ b/numpy/random/tests/test_random.py
@@ -137,7 +137,7 @@ class TestRandint(TestCase):
rfunc = np.random.randint
# valid integer/boolean types
- itype = [np.bool, np.int8, np.uint8, np.int16, np.uint16,
+ itype = [np.bool_, np.int8, np.uint8, np.int16, np.uint16,
np.int32, np.uint32, np.int64, np.uint64]
def test_unsupported_type(self):
@@ -145,8 +145,8 @@ class TestRandint(TestCase):
def test_bounds_checking(self):
for dt in self.itype:
- lbnd = 0 if dt is np.bool else np.iinfo(dt).min
- ubnd = 2 if dt is np.bool else np.iinfo(dt).max + 1
+ lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min
+ ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1
assert_raises(ValueError, self.rfunc, lbnd - 1, ubnd, dtype=dt)
assert_raises(ValueError, self.rfunc, lbnd, ubnd + 1, dtype=dt)
assert_raises(ValueError, self.rfunc, ubnd, lbnd, dtype=dt)
@@ -154,8 +154,8 @@ class TestRandint(TestCase):
def test_rng_zero_and_extremes(self):
for dt in self.itype:
- lbnd = 0 if dt is np.bool else np.iinfo(dt).min
- ubnd = 2 if dt is np.bool else np.iinfo(dt).max + 1
+ lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min
+ ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1
tgt = ubnd - 1
assert_equal(self.rfunc(tgt, tgt + 1, size=1000, dtype=dt), tgt)
tgt = lbnd
@@ -211,11 +211,20 @@ class TestRandint(TestCase):
def test_respect_dtype_singleton(self):
# See gh-7203
for dt in self.itype:
+ lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min
+ ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1
+
+ sample = self.rfunc(lbnd, ubnd, dtype=dt)
+ self.assertEqual(sample.dtype, np.dtype(dt))
+
+ for dt in (np.bool, np.int, np.long):
lbnd = 0 if dt is np.bool else np.iinfo(dt).min
ubnd = 2 if dt is np.bool else np.iinfo(dt).max + 1
+ # gh-7284: Ensure that we get Python data types
sample = self.rfunc(lbnd, ubnd, dtype=dt)
- self.assertEqual(sample.dtype, np.dtype(dt))
+ self.assertFalse(hasattr(sample, 'dtype'))
+ self.assertEqual(type(sample), dt)
class TestRandomDist(TestCase):