Skip to content

Commit 6d69a9e

Browse files
nschloemattip
authored andcommitted
MAINT: Fix randint 0d limits and other 0d cleanups (numpy#15126)
* MAINT: only treat 0d case separately in randint, simplify some tests
1 parent 0cea652 commit 6d69a9e

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

numpy/core/tests/test_machar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def _run_machar_highprec(self):
1616
# underflow
1717
try:
1818
hiprec = ntypes.float96
19-
MachAr(lambda v:array([v], hiprec))
19+
MachAr(lambda v: array(v, hiprec))
2020
except AttributeError:
2121
# Fixme, this needs to raise a 'skip' exception.
2222
"Skipping test: no ntypes.float96 available on this platform."

numpy/core/tests/test_multiarray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7564,8 +7564,8 @@ def test_to_int_scalar(self):
75647564
# gh-9972 means that these aren't always the same
75657565
int_funcs = (int, lambda x: x.__int__())
75667566
for int_func in int_funcs:
7567+
assert_equal(int_func(np.array(0)), 0)
75677568
assert_equal(int_func(np.array([1])), 1)
7568-
assert_equal(int_func(np.array([0])), 0)
75697569
assert_equal(int_func(np.array([[42]])), 42)
75707570
assert_raises(TypeError, int_func, np.array([1, 2]))
75717571

numpy/random/_bounded_integers.pyx.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ cdef object _rand_{{nptype}}(object low, object high, object size,
314314
high_arr = <np.ndarray>np.array(high, copy=False)
315315
low_ndim = np.PyArray_NDIM(low_arr)
316316
high_ndim = np.PyArray_NDIM(high_arr)
317-
if ((low_ndim == 0 or (low_ndim == 1 and low_arr.size == 1 and size is not None)) and
318-
(high_ndim == 0 or (high_ndim == 1 and high_arr.size == 1 and size is not None))):
317+
if low_ndim == 0 and high_ndim == 0:
319318
low = int(low_arr)
320319
high = int(high_arr)
321320
# Subtract 1 since internal generator produces on closed interval [low, high]

numpy/testing/tests/test_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,9 @@ class TestApproxEqual(object):
608608
def setup(self):
609609
self._assert_func = assert_approx_equal
610610

611-
def test_simple_arrays(self):
612-
x = np.array([1234.22])
613-
y = np.array([1234.23])
611+
def test_simple_0d_arrays(self):
612+
x = np.array(1234.22)
613+
y = np.array(1234.23)
614614

615615
self._assert_func(x, y, significant=5)
616616
self._assert_func(x, y, significant=6)

0 commit comments

Comments
 (0)