@@ -82,7 +82,7 @@ def test_size(self):
82
82
(2 , 2 , 2 ))
83
83
84
84
assert_raises (TypeError , mt19937 .multinomial , 1 , p ,
85
- np . float (1 ))
85
+ float (1 ))
86
86
87
87
88
88
class TestSetState (TestCase ):
@@ -139,25 +139,25 @@ class TestRandint(TestCase):
139
139
rfunc = random .randint
140
140
141
141
# 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 ,
143
143
np .int32 , np .uint32 , np .int64 , np .uint64 ]
144
144
145
145
def test_unsupported_type (self ):
146
- assert_raises (TypeError , self .rfunc , 1 , dtype = np . float )
146
+ assert_raises (TypeError , self .rfunc , 1 , dtype = float )
147
147
148
148
def test_bounds_checking (self ):
149
149
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
152
152
assert_raises (ValueError , self .rfunc , lbnd - 1 , ubnd , dtype = dt )
153
153
assert_raises (ValueError , self .rfunc , lbnd , ubnd + 1 , dtype = dt )
154
154
assert_raises (ValueError , self .rfunc , ubnd , lbnd , dtype = dt )
155
155
assert_raises (ValueError , self .rfunc , 1 , 0 , dtype = dt )
156
156
157
157
def test_rng_zero_and_extremes (self ):
158
158
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
161
161
162
162
tgt = ubnd - 1
163
163
assert_equal (self .rfunc (tgt , tgt + 1 , size = 1000 , dtype = dt ), tgt )
@@ -172,8 +172,8 @@ def test_full_range(self):
172
172
# Test for ticket #1690
173
173
174
174
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
177
177
178
178
try :
179
179
self .rfunc (lbnd , ubnd , dtype = dt )
@@ -192,15 +192,15 @@ def test_in_bounds_fuzz(self):
192
192
assert_ (vals .max () < ubnd )
193
193
assert_ (vals .min () >= 2 )
194
194
195
- vals = self .rfunc (0 , 2 , size = 2 ** 16 , dtype = np . bool_ )
195
+ vals = self .rfunc (0 , 2 , size = 2 ** 16 , dtype = bool )
196
196
197
197
assert_ (vals .max () < 2 )
198
198
assert_ (vals .min () >= 0 )
199
199
200
200
def test_repeatability (self ):
201
201
import hashlib
202
202
# 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
204
204
# is [0, 2). Hashes are for little endian numbers.
205
205
tgt = {'bool' : '7dd3170d7aa461d201a65f8bcf3944b0' ,
206
206
'int16' : '1b7741b80964bb190c50d541dca1cac1' ,
@@ -226,9 +226,9 @@ def test_repeatability(self):
226
226
227
227
# bools do not depend on endianess
228
228
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 )
230
230
res = hashlib .md5 (val ).hexdigest ()
231
- assert_ (tgt [np .dtype (np . bool ).name ] == res )
231
+ assert_ (tgt [np .dtype (bool ).name ] == res )
232
232
233
233
def test_int64_uint64_corner_case (self ):
234
234
# When stored in Numpy arrays, `lbnd` is casted
@@ -256,15 +256,16 @@ def test_int64_uint64_corner_case(self):
256
256
def test_respect_dtype_singleton (self ):
257
257
# See gh-7203
258
258
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
261
262
262
263
sample = self .rfunc (lbnd , ubnd , dtype = dt )
263
- self .assertEqual (sample .dtype , np . dtype ( dt ) )
264
+ self .assertEqual (sample .dtype , dt )
264
265
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
268
269
269
270
# gh-7284: Ensure that we get Python data types
270
271
sample = self .rfunc (lbnd , ubnd , dtype = dt )
@@ -523,7 +524,7 @@ def test_dirichlet_size(self):
523
524
assert_equal (mt19937 .dirichlet (p , (2 , 2 )).shape , (2 , 2 , 2 ))
524
525
assert_equal (mt19937 .dirichlet (p , np .array ((2 , 2 ))).shape , (2 , 2 , 2 ))
525
526
526
- assert_raises (TypeError , mt19937 .dirichlet , p , np . float (1 ))
527
+ assert_raises (TypeError , mt19937 .dirichlet , p , float (1 ))
527
528
528
529
def test_exponential (self ):
529
530
mt19937 .seed (self .seed )
@@ -1583,7 +1584,7 @@ def test_two_arg_funcs(self):
1583
1584
1584
1585
# TODO: Uncomment once randint can broadcast arguments
1585
1586
# 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,
1587
1588
# np.int32, np.uint32, np.int64, np.uint64]
1588
1589
# func = mt19937.randint
1589
1590
# high = np.array([1])
0 commit comments