diff options
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/_globals.py | 4 | ||||
| -rw-r--r-- | numpy/core/include/numpy/ndarraytypes.h | 8 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/conversion_utils.c | 16 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/methods.c | 5 |
4 files changed, 20 insertions, 13 deletions
diff --git a/numpy/_globals.py b/numpy/_globals.py index 9a99acde3..b7a399a79 100644 --- a/numpy/_globals.py +++ b/numpy/_globals.py @@ -95,8 +95,8 @@ _NoValue = _NoValueType() class CopyMode(enum.Enum): - ALWAYS = 1 - IF_NEEDED = 0 + ALWAYS = True + IF_NEEDED = False NEVER = 2 def __bool__(self): diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h index 6626da1e9..6a861dc1d 100644 --- a/numpy/core/include/numpy/ndarraytypes.h +++ b/numpy/core/include/numpy/ndarraytypes.h @@ -452,10 +452,10 @@ typedef struct { } PyArray_Dims; typedef enum PyNpCopyMode { - NPY_IF_NEEDED, - NPY_ALWAYS, - NPY_NEVER -} PyNpCopyMode_Enum; + NPY_COPY_IF_NEEDED, + NPY_COPY_ALWAYS, + NPY_COPY_NEVER +} PyArray_CopyMode; typedef struct { /* diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c index e16c03e31..8f608ea3e 100644 --- a/numpy/core/src/multiarray/conversion_utils.c +++ b/numpy/core/src/multiarray/conversion_utils.c @@ -176,17 +176,23 @@ PyArray_CopyConverter(PyObject *obj, PyNpCopyMode_Enum *copymode) { int int_copymode = -1; PyObject* numpy_CopyMode = NULL; npy_cache_import("numpy._globals", "CopyMode", &numpy_CopyMode); - if( numpy_CopyMode != NULL ) { - if(PyObject_IsInstance(obj, numpy_CopyMode)) { - PyObject* mode_value = PyObject_GetAttrString(obj, "value"); - PyArray_PythonPyIntFromInt(mode_value, &int_copymode); + if (numpy_CopyMode == NULL) { + return NPY_FAIL; + } + if (PyObject_IsInstance(obj, numpy_CopyMode)) { + PyObject* mode_value = PyObject_GetAttrString(obj, "value"); + if (mode_value == NULL) { + return NPY_FAIL; + } + if (!PyArray_PythonPyIntFromInt(mode_value, &int_copymode)) { + return NPY_FAIL; } } // If obj is not an instance of numpy.CopyMode then follow // the conventional assumption that it must be value that // can be converted to an integer. - if( int_copymode < 0 ) { + else { PyArray_PythonPyIntFromInt(obj, &int_copymode); } diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c index 9613bf04e..a3b97ea7c 100644 --- a/numpy/core/src/multiarray/methods.c +++ b/numpy/core/src/multiarray/methods.c @@ -828,7 +828,8 @@ array_astype(PyArrayObject *self, */ NPY_CASTING casting = NPY_UNSAFE_CASTING; NPY_ORDER order = NPY_KEEPORDER; - PyNpCopyMode_Enum forcecopy = 1, subok = 1; + PyNpCopyMode_Enum forcecopy = 1; + int subok = 1; NPY_PREPARE_ARGPARSER; if (npy_parse_arguments("astype", args, len_args, kwnames, "dtype", &PyArray_DescrConverter, &dtype, @@ -852,7 +853,7 @@ array_astype(PyArrayObject *self, * and it's not a subtype if subok is False, then we * can skip the copy. */ - if ( (forcecopy == NPY_IF_NEEDED || forcecopy == NPY_NEVER) && + if (forcecopy != NPY_ALWAYS && (order == NPY_KEEPORDER || (order == NPY_ANYORDER && (PyArray_IS_C_CONTIGUOUS(self) || |
