8000 Array params from object by mwiebe · Pull Request #39 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Array params from object #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
3 commits merged into from
Feb 8, 2011
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
BUG: core: Fix regression ticket #1735
  • Loading branch information
mwiebe committed Feb 7, 2011
commit fa5ea049410ba5ad4fcdb24cd8698ed834122ea7
13 changes: 13 additions & 0 deletions numpy/core/src/multiarray/arraytypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,19 @@ STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap)
Py_ssize_t len;
PyObject *temp = NULL;

/* Handle case of assigning from an array scalar */
if (PyArray_Check(op) && PyArray_NDIM(op) == 0) {
temp = PyArray_ToScalar(PyArray_DATA(op), op);
if (temp == NULL) {
return -1;
}
else {
int res = STRING_setitem(temp, ov, ap);
Py_DECREF(temp);
return res;
}
}

if (!PyBytes_Check(op) && !PyUnicode_Check(op)
&& PySequence_Check(op) && PySequence_Size(op) != 0) {
PyErr_SetString(PyExc_ValueError,
Expand Down
14 changes: 14 additions & 0 deletions numpy/core/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,5 +1519,19 @@ def test_objectarray_setfield(self):
x = np.array([1,2,3], dtype=object)
assert_raises(RuntimeError, x.setfield, 4, np.int32, 0)

def test_setting_rank0_string(self):
"Ticket #1736"
a = np.zeros((), dtype="S10")
a[()] = b"hello1"
assert_equal(a, np.array(b"hello1"))
a[()] = np.array(b"hello2")
assert_equal(a, np.array(b"hello2"))

a = np.zeros((), dtype='f4')
a[()] = 3
assert_equal(a, np.array(3))
a[()] = np.array(4)
assert_equal(a, np.array(4))

if __name__ == "__main__":
run_module_suite()
0