Skip to content

Commit 4b04556

Browse files
authored
Merge branch 'master' into dirchelet-check
2 parents 1567a8e + f39a4ae commit 4b04556

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

randomstate/tests/test_numpy_mt19937.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_size(self):
8585
(2, 2, 2))
8686

8787
assert_raises(TypeError, mt19937.multinomial, 1, p,
88-
np.float(1))
88+
float(1))
8989

9090

9191
class TestSetState(TestCase):
@@ -141,25 +141,25 @@ class TestRandint(TestCase):
141141
rfunc = random.randint
142142

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

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

150150
def test_bounds_checking(self):
151151
for dt in self.itype:
152-
lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min
153-
ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1
152+
lbnd = 0 if dt is bool else np.iinfo(dt).min
153+
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
154154
assert_raises(ValueError, self.rfunc, lbnd - 1, ubnd, dtype=dt)
155155
assert_raises(ValueError, self.rfunc, lbnd, ubnd + 1, dtype=dt)
156156
assert_raises(ValueError, self.rfunc, ubnd, lbnd, dtype=dt)
157157
assert_raises(ValueError, self.rfunc, 1, 0, dtype=dt)
158158

159159
def test_rng_zero_and_extremes(self):
160160
for dt in self.itype:
161-
lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min
162-
ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1
161+
lbnd = 0 if dt is bool else np.iinfo(dt).min
162+
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
163163

164164
tgt = ubnd - 1
165165
assert_equal(self.rfunc(tgt, tgt + 1, size=1000, dtype=dt), tgt)
@@ -174,8 +174,8 @@ def test_full_range(self):
174174
# Test for ticket #1690
175175

176176
for dt in self.itype:
177-
lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min
178-
ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1
177+
lbnd = 0 if dt is bool else np.iinfo(dt).min
178+
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
179179

180180
try:
181181
self.rfunc(lbnd, ubnd, dtype=dt)
@@ -194,15 +194,15 @@ def test_in_bounds_fuzz(self):
194194
assert_(vals.max() < ubnd)
195195
assert_(vals.min() >= 2)
196196

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

199199
assert_(vals.max() < 2)
200200
assert_(vals.min() >= 0)
201201

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

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

235235
def test_int64_uint64_corner_case(self):
236236
# When stored in Numpy arrays, `lbnd` is casted
@@ -258,15 +258,16 @@ def test_int64_uint64_corner_case(self):
258258
def test_respect_dtype_singleton(self):
259259
# See gh-7203
260260
for dt in self.itype:
261-
lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min
262-
ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1
261+
lbnd = 0 if dt is bool else np.iinfo(dt).min
262+
ubnd = 2 if dt is bool else np.iinfo(dt).max + 1
263+
dt = np.bool_ if dt is bool else dt
263264

264265
sample = self.rfunc(lbnd, ubnd, dtype=dt)
265-
self.assertEqual(sample.dtype, np.dtype(dt))
266+
self.assertEqual(sample.dtype, dt)
266267

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

271272
# gh-7284: Ensure that we get Python data types
272273
sample = self.rfunc(lbnd, ubnd, dtype=dt)
@@ -527,7 +528,7 @@ def test_dirichlet_size(self):
527528
assert_equal(mt19937.dirichlet(p, (2, 2)).shape, (2, 2, 2))
528529
assert_equal(mt19937.dirichlet(p, np.array((2, 2))).shape, (2, 2, 2))
529530

530-
assert_raises(TypeError, mt19937.dirichlet, p, np.float(1))
531+
assert_raises(TypeError, mt19937.dirichlet, p, float(1))
531532

532533
def test_exponential(self):
533534
mt19937.seed(self.seed)

0 commit comments

Comments
 (0)