Skip to content

Commit f39a4ae

Browse files
authored
Merge pull request #107 from bashtage/sync-upstream
CLN: Sync with upstream NumPy
2 parents a8ac5f4 + 3ad8cab commit f39a4ae

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

randomstate/tests/test_numpy_mt19937.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_size(self):
8282
(2, 2, 2))
8383

8484
assert_raises(TypeError, mt19937.multinomial, 1, p,
85-
np.float(1))
85+
float(1))
8686

8787

8888
class TestSetState(TestCase):
@@ -139,25 +139,25 @@ class TestRandint(TestCase):
139139
rfunc = random.randint
140140

141141
# valid integer/boolean types
142-
itype = [np.bool_, np.int8, np.uint8, np.int16, np.uint16,
142+
itype = [bool, np.int8, np.uint8, np.int16, np.uint16,
143143
np.int32, np.uint32, np.int64, np.uint64]
144144

145145
def test_unsupported_type(self):
146-
assert_raises(TypeError, self.rfunc, 1, dtype=np.float)
146+
assert_raises(TypeError, self.rfunc, 1, dtype=float)
147147

148148
def test_bounds_checking(self):
149149
for dt in self.itype:
150-
lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min
151-
ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1
150+
lbnd = 0 if dt is bool else np.iinfo(dt).min
151+
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
152152
assert_raises(ValueError, self.rfunc, lbnd - 1, ubnd, dtype=dt)
153153
assert_raises(ValueError, self.rfunc, lbnd, ubnd + 1, dtype=dt)
154154
assert_raises(ValueError, self.rfunc, ubnd, lbnd, dtype=dt)
155155
assert_raises(ValueError, self.rfunc, 1, 0, dtype=dt)
156156

157157
def test_rng_zero_and_extremes(self):
158158
for dt in self.itype:
159-
lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min
160-
ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1
159+
lbnd = 0 if dt is bool else np.iinfo(dt).min
160+
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
161161

162162
tgt = ubnd - 1
163163
assert_equal(self.rfunc(tgt, tgt + 1, size=1000, dtype=dt), tgt)
@@ -172,8 +172,8 @@ def test_full_range(self):
172172
# Test for ticket #1690
173173

174174
for dt in self.itype:
175-
lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min
176-
ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1
175+
lbnd = 0 if dt is bool else np.iinfo(dt).min
176+
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
177177

178178
try:
179179
self.rfunc(lbnd, ubnd, dtype=dt)
@@ -192,15 +192,15 @@ def test_in_bounds_fuzz(self):
192192
assert_(vals.max() < ubnd)
193193
assert_(vals.min() >= 2)
194194

195-
vals = self.rfunc(0, 2, size=2 ** 16, dtype=np.bool_)
195+
vals = self.rfunc(0, 2, size=2 ** 16, dtype=bool)
196196

197197
assert_(vals.max() < 2)
198198
assert_(vals.min() >= 0)
199199

200200
def test_repeatability(self):
201201
import hashlib
202202
# We use a md5 hash of generated sequences of 1000 samples
203-
# in the range [0, 6) for all but np.bool, where the range
203+
# in the range [0, 6) for all but bool, where the range
204204
# is [0, 2). Hashes are for little endian numbers.
205205
tgt = {'bool': '7dd3170d7aa461d201a65f8bcf3944b0',
206206
'int16': '1b7741b80964bb190c50d541dca1cac1',
@@ -226,9 +226,9 @@ def test_repeatability(self):
226226

227227
# bools do not depend on endianess
228228
mt19937.seed(1234)
229-
val = self.rfunc(0, 2, size=1000, dtype=np.bool).view(np.int8)
229+
val = self.rfunc(0, 2, size=1000, dtype=bool).view(np.int8)
230230
res = hashlib.md5(val).hexdigest()
231-
assert_(tgt[np.dtype(np.bool).name] == res)
231+
assert_(tgt[np.dtype(bool).name] == res)
232232

233233
def test_int64_uint64_corner_case(self):
234234
# When stored in Numpy arrays, `lbnd` is casted
@@ -256,15 +256,16 @@ def test_int64_uint64_corner_case(self):
256256
def test_respect_dtype_singleton(self):
257257
# See gh-7203
258258
for dt in self.itype:
259-
lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min
260-
ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1
259+
lbnd = 0 if dt is bool else np.iinfo(dt).min
260+
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
261+
dt = np.bool_ if dt is bool else dt
261262

262263
sample = self.rfunc(lbnd, ubnd, dtype=dt)
263-
self.assertEqual(sample.dtype, np.dtype(dt))
264+
self.assertEqual(sample.dtype, dt)
264265

265-
for dt in (np.bool, np.int, np.long):
266-
lbnd = 0 if dt is np.bool else np.iinfo(dt).min
267-
ubnd = 2 if dt is np.bool else np.iinfo(dt).max + 1
266+
for dt in (bool, int, np.long):
267+
lbnd = 0 if dt is bool else np.iinfo(dt).min
268+
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
268269

269270
# gh-7284: Ensure that we get Python data types
270271
sample = self.rfunc(lbnd, ubnd, dtype=dt)
@@ -523,7 +524,7 @@ def test_dirichlet_size(self):
523524
assert_equal(mt19937.dirichlet(p, (2, 2)).shape, (2, 2, 2))
524525
assert_equal(mt19937.dirichlet(p, np.array((2, 2))).shape, (2, 2, 2))
525526

526-
assert_raises(TypeError, mt19937.dirichlet, p, np.float(1))
527+
assert_raises(TypeError, mt19937.dirichlet, p, float(1))
527528

528529
def test_exponential(self):
529530
mt19937.seed(self.seed)
@@ -1583,7 +1584,7 @@ def test_two_arg_funcs(self):
15831584

15841585
# TODO: Uncomment once randint can broadcast arguments
15851586
# def test_randint(self):
1586-
# itype = [np.bool, np.int8, np.uint8, np.int16, np.uint16,
1587+
# itype = [bool, np.int8, np.uint8, np.int16, np.uint16,
15871588
# np.int32, np.uint32, np.int64, np.uint64]
15881589
# func = mt19937.randint
15891590
# high = np.array([1])

0 commit comments

Comments
 (0)