diff options
author | przemb <sendthenote@gmail.com> | 2020-02-05 14:33:06 +0100 |
---|---|---|
committer | przemb <sendthenote@gmail.com> | 2020-02-05 14:33:06 +0100 |
commit | df27b88b9271b2fb1d0770217facf9c4190bb778 (patch) | |
tree | 054d288b416c0361bbace57e2dec7dfade80790b | |
parent | a15dc309cb28ca4bab3a2ef89f90c24e6659e9bd (diff) | |
download | numpy-df27b88b9271b2fb1d0770217facf9c4190bb778.tar.gz |
Changes suggested in review
-rw-r--r-- | numpy/random/_bounded_integers.pyx.in | 10 | ||||
-rw-r--r-- | numpy/random/mtrand.pyx | 14 | ||||
-rw-r--r-- | numpy/random/tests/test_randomstate_regression.py | 3 |
3 files changed, 11 insertions, 16 deletions
diff --git a/numpy/random/_bounded_integers.pyx.in b/numpy/random/_bounded_integers.pyx.in index 9e639b53b..9f46685d3 100644 --- a/numpy/random/_bounded_integers.pyx.in +++ b/numpy/random/_bounded_integers.pyx.in @@ -51,16 +51,6 @@ cdef extern from "numpy/random/distributions.h": np.npy_bool *out) nogil - -_integers_types = {'bool': (0, 2), - 'int8': (-2**7, 2**7), - 'int16': (-2**15, 2**15), - 'int32': (-2**31, 2**31), - 'int64': (-2**63, 2**63), - 'uint8': (0, 2**8), - 'uint16': (0, 2**16), - 'uint32': (0, 2**32), - 'uint64': (0, 2**64)} {{ py: type_info = (('uint32', 'uint32', 'uint64', 'NPY_UINT64', 0, 0, 0, '0X100000000ULL'), diff --git a/numpy/random/mtrand.pyx b/numpy/random/mtrand.pyx index b38e8bbbe..c58949e89 100644 --- a/numpy/random/mtrand.pyx +++ b/numpy/random/mtrand.pyx @@ -725,6 +725,15 @@ cdef class RandomState: _dtype = np.dtype(dtype) + if not _dtype.isnative: + # numpy 1.17.0, 2019-05-28 + warnings.warn('Providing a dtype with a non-native byteorder is ' + 'not supported. If you require platform-independent ' + 'byteorder, call byteswap when required.\nIn future ' + 'version, providing byteorder will raise a ' + 'ValueError', DeprecationWarning) + _dtype = _dtype.newbyteorder() + # Implementation detail: the use a masked method to generate # bounded uniform integers. Lemire's method is preferable since it is # faster. randomgen allows a choice, we will always use the slower but @@ -750,11 +759,6 @@ cdef class RandomState: ret = _rand_uint8(low, high, size, _masked, _endpoint, &self._bitgen, self.lock) elif _dtype == np.bool_: ret = _rand_bool(low, high, size, _masked, _endpoint, &self._bitgen, self.lock) - elif not _dtype.isnative: - raise ValueError('Providing a dtype with a non-native byteorder ' - 'is not supported. If you require ' - 'platform-independent byteorder, call byteswap ' - 'when required.') else: raise TypeError('Unsupported dtype %r for randint' % _dtype) diff --git a/numpy/random/tests/test_randomstate_regression.py b/numpy/random/tests/test_randomstate_regression.py index 9f9728df2..1d8a0ed5a 100644 --- a/numpy/random/tests/test_randomstate_regression.py +++ b/numpy/random/tests/test_randomstate_regression.py @@ -163,7 +163,8 @@ class TestRegression: def test_warns_byteorder(self): # GH 13159 other_byteord_dt = '<i4' if sys.byteorder == 'big' else '>i4' - assert_raises(ValueError, random.randint, 0, 200, size=10, dtype=other_byteord_dt) + with pytest.deprecated_call(match='non-native byteorder is not'): + random.randint(0, 200, size=10, dtype=other_byteord_dt) def test_named_argument_initialization(self): # GH 13669 |