Make numpy arrays immutable (#183)

* Make numpy arrays immutable in numbuf

* Move break statement outside of brackets

* Simplify test case

* Simplify test case
This commit is contained in:
Stephanie Wang
2017-01-05 19:47:52 -08:00
committed by Philipp Moritz
parent 651aa6007a
commit cac473b557
2 changed files with 14 additions and 2 deletions
+6 -2
View File
@@ -27,8 +27,7 @@ namespace numbuf {
num_dims, dim.data(), NPY_##TYPE, reinterpret_cast<void*>(data)); \
if (base != Py_None) { PyArray_SetBaseObject((PyArrayObject*)*out, base); } \
Py_XINCREF(base); \
} \
return Status::OK();
} break;
Status DeserializeArray(
std::shared_ptr<Array> array, int32_t offset, PyObject* base, PyObject** out) {
@@ -57,6 +56,11 @@ Status DeserializeArray(
default:
DCHECK(false) << "arrow type not recognized: " << content->value_type()->type;
}
/* Mark the array as immutable. */
PyObject* flags = PyObject_GetAttrString(*out, "flags");
DCHECK(flags != NULL) << "Could not mark Numpy array immutable";
int flag_set = PyObject_SetAttrString(flags, "writeable", Py_False);
DCHECK(flag_set == 0) << "Could not mark Numpy array immutable";
return Status::OK();
}