Skip to content

Commit 499447e

Browse files
przembcharris
authored andcommitted
Changes suggested in review
1 parent f7f1df0 commit 499447e

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

numpy/random/_bounded_integers.pyx.in

-10
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,6 @@ cdef extern from "numpy/random/distributions.h":
5151
np.npy_bool *out) nogil
5252

5353

54-
55-
_integers_types = {'bool': (0, 2),
56-
'int8': (-2**7, 2**7),
57-
'int16': (-2**15, 2**15),
58-
'int32': (-2**31, 2**31),
59-
'int64': (-2**63, 2**63),
60-
'uint8': (0, 2**8),
61-
'uint16': (0, 2**16),
62-
'uint32': (0, 2**32),
63-
'uint64': (0, 2**64)}
6454
{{
6555
py:
6656
type_info = (('uint32', 'uint32', 'uint64', 'NPY_UINT64', 0, 0, 0, '0X100000000ULL'),

numpy/random/mtrand.pyx

+9-5
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,15 @@ cdef class RandomState:
723723

724724
_dtype = np.dtype(dtype)
725725

726+
if not _dtype.isnative:
727+
# numpy 1.17.0, 2019-05-28
728+
warnings.warn('Providing a dtype with a non-native byteorder is '
729+
'not supported. If you require platform-independent '
730+
'byteorder, call byteswap when required.\nIn future '
731+
'version, providing byteorder will raise a '
732+
'ValueError', DeprecationWarning)
733+
_dtype = _dtype.newbyteorder()
734+
726735
# Implementation detail: the use a masked method to generate
727736
# bounded uniform integers. Lemire's method is preferable since it is
728737
# faster. randomgen allows a choice, we will always use the slower but
@@ -748,11 +757,6 @@ cdef class RandomState:
748757
ret = _rand_uint8(low, high, size, _masked, _endpoint, &self._bitgen, self.lock)
749758
elif _dtype == np.bool_:
750759
ret = _rand_bool(low, high, size, _masked, _endpoint, &self._bitgen, self.lock)
751-
elif not _dtype.isnative:
752-
raise ValueError('Providing a dtype with a non-native byteorder '
753-
'is not supported. If you require '
754-
'platform-independent byteorder, call byteswap '
755-
'when required.')
756760
else:
757761
raise TypeError('Unsupported dtype %r for randint' % _dtype)
758762

numpy/random/tests/test_randomstate_regression.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ def __array__(self):
162162
def test_warns_byteorder(self):
163163
# GH 13159
164164
other_byteord_dt = '<i4' if sys.byteorder == 'big' else '>i4'
165-
assert_raises(ValueError, random.randint, 0, 200, size=10, dtype=other_byteord_dt)
165+
with pytest.deprecated_call(match='non-native byteorder is not'):
166+
random.randint(0, 200, size=10, dtype=other_byteord_dt)
166167

167168
def test_named_argument_initialization(self):
168169
# GH 13669

0 commit comments

Comments
 (0)