@@ -137,25 +137,25 @@ class TestRandint(TestCase):
137
137
rfunc = np .random .randint
138
138
139
139
# valid integer/boolean types
140
- itype = [np .bool , np .int8 , np .uint8 , np .int16 , np .uint16 ,
140
+ itype = [np .bool_ , np .int8 , np .uint8 , np .int16 , np .uint16 ,
141
141
np .int32 , np .uint32 , np .int64 , np .uint64 ]
142
142
143
143
def test_unsupported_type (self ):
144
144
assert_raises (TypeError , self .rfunc , 1 , dtype = np .float )
145
145
146
146
def test_bounds_checking (self ):
147
147
for dt in self .itype :
148
- lbnd = 0 if dt is np .bool else np .iinfo (dt ).min
149
- ubnd = 2 if dt is np .bool else np .iinfo (dt ).max + 1
148
+ lbnd = 0 if dt is np .bool_ else np .iinfo (dt ).min
149
+ ubnd = 2 if dt is np .bool_ else np .iinfo (dt ).max + 1
150
150
assert_raises (ValueError , self .rfunc , lbnd - 1 , ubnd , dtype = dt )
151
151
assert_raises (ValueError , self .rfunc , lbnd , ubnd + 1 , dtype = dt )
152
152
assert_raises (ValueError , self .rfunc , ubnd , lbnd , dtype = dt )
153
153
assert_raises (ValueError , self .rfunc , 1 , 0 , dtype = dt )
154
154
155
155
def test_rng_zero_and_extremes (self ):
156
156
for dt in self .itype :
157
- lbnd = 0 if dt is np .bool else np .iinfo (dt ).min
158
- ubnd = 2 if dt is np .bool else np .iinfo (dt ).max + 1
157
+ lbnd = 0 if dt is np .bool_ else np .iinfo (dt ).min
158
+ ubnd = 2 if dt is np .bool_ else np .iinfo (dt ).max + 1
159
159
tgt = ubnd - 1
160
160
assert_equal (self .rfunc (tgt , tgt + 1 , size = 1000 , dtype = dt ), tgt )
161
161
tgt = lbnd
@@ -211,11 +211,20 @@ def test_repeatability(self):
211
211
def test_respect_dtype_singleton (self ):
212
212
# See gh-7203
213
213
for dt in self .itype :
214
+ lbnd = 0 if dt is np .bool_ else np .iinfo (dt ).min
215
+ ubnd = 2 if dt is np .bool_ else np .iinfo (dt ).max + 1
216
+
217
+ sample = self .rfunc (lbnd , ubnd , dtype = dt )
218
+ self .assertEqual (sample .dtype , np .dtype (dt ))
219
+
220
+ for dt in (np .bool , np .int , np .long ):
214
221
lbnd = 0 if dt is np .bool else np .iinfo (dt ).min
215
222
ubnd = 2 if dt is np .bool else np .iinfo (dt ).max + 1
216
223
224
+ # gh-7284: Ensure that we get Python data types
217
225
sample = self .rfunc (lbnd , ubnd , dtype = dt )
218
- self .assertEqual (sample .dtype , np .dtype (dt ))
226
+ self .assertFalse (hasattr (sample , 'dtype' ))
227
+ self .assertEqual (type (sample ), dt )
219
228
220
229
221
230
class TestRandomDist (TestCase ):
0 commit comments