Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dea4fab

Browse files
committed
Backport of #2897 (ndindex failing)
This backports all relevant changes from: #2897 I squashed them into just one commit.
1 parent 788d4bc commit dea4fab

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

numpy/core/src/multiarray/ctors.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,11 +2079,6 @@ PyArray_FromInterface(PyObject *origin)
20792079
/* Case for data access through pointer */
20802080
if (attr && PyTuple_Check(attr)) {
20812081
PyObject *dataptr;
2082-
if (n == 0) {
2083-
PyErr_SetString(PyExc_ValueError,
2084-
"__array_interface__ shape must be at least size 1");
2085-
goto fail;
2086-
}
20872082
if (PyTuple_GET_SIZE(attr) != 2) {
20882083
PyErr_SetString(PyExc_TypeError,
20892084
"__array_interface__ data must be a 2-tuple with "

numpy/core/tests/test_multiarray.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,6 +2835,13 @@ def __array_interface__(self):
28352835
f.iface['shape'] = (2,)
28362836
assert_raises(ValueError, np.array, f)
28372837

2838+
# test scalar with no shape
2839+
class ArrayLike(object):
2840+
array = np.array(1)
2841+
__array_interface__ = array.__array_interface__
2842+
assert_equal(np.array(ArrayLike()), 1)
2843+
2844+
28382845
def test_flat_element_deletion():
28392846
it = np.ones(3).flat
28402847
try:

numpy/lib/tests/test_index_tricks.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ def test_diag_indices_from():
236236
assert_array_equal(r, np.arange(4))
237237
assert_array_equal(c, np.arange(4))
238238

239+
x = list(np.ndindex((1, 2, 3)))
240+
assert_array_equal(x, expected)
241+
242+
# Make sure size argument is optional
243+
x = list(np.ndindex())
244+
assert_equal(x, [()])
245+
246+
x = list(np.ndindex(()))
247+
assert_equal(x, [()])
248+
239249

240250
if __name__ == "__main__":
241251
run_module_suite()

0 commit comments

Comments
 (0)