summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2017-04-14 21:00:47 +0200
committerJulian Taylor <jtaylor.debian@googlemail.com>2017-05-03 02:18:49 +0200
commit9c39207aeddd0effcb6ae3d39f73ee0b77926424 (patch)
treed071e2db5d20aa4ede6d032e2b86a8776c396bab
parenta618b4e10dde4b41acceac3d8f7c042fb88af1a7 (diff)
downloadnumpy-9c39207aeddd0effcb6ae3d39f73ee0b77926424.tar.gz
MAINT: add deprecation warnings for NPY_CHAR usage
-rw-r--r--numpy/core/include/numpy/ndarraytypes.h15
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src12
-rw-r--r--numpy/core/src/multiarray/multiarray_tests.c.src11
-rw-r--r--numpy/core/tests/test_deprecations.py7
4 files changed, 44 insertions, 1 deletions
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h
index 7f6fe6524..e0df189f9 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -15,7 +15,17 @@
#define NPY_ALLOW_THREADS 0
#endif
+#ifndef __has_extension
+#define __has_extension(x) 0
+#endif
+#if !defined(_NPY_NO_DEPRECATIONS) && \
+ ((defined(__GNUC__)&& __GNUC__ >= 6) || \
+ __has_extension(attribute_deprecated_with_message))
+#define NPY_ATTR_DEPRECATE(text) __attribute__ ((deprecated (text)))
+#else
+#define NPY_ATTR_DEPRECATE(text)
+#endif
/*
* There are several places in the code where an array of dimensions
@@ -71,12 +81,15 @@ enum NPY_TYPES { NPY_BOOL=0,
NPY_NTYPES,
NPY_NOTYPE,
- NPY_CHAR, /* special flag */
+ NPY_CHAR NPY_ATTR_DEPRECATE("Use NPY_STRING"),
NPY_USERDEF=256, /* leave room for characters */
/* The number of types not including the new 1.6 types */
NPY_NTYPES_ABI_COMPATIBLE=21
};
+#ifdef _MSC_VER
+#pragma deprecated(NPY_CHAR)
+#endif
/* basetype array priority */
#define NPY_PRIORITY 0.0
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index 49d6ae1d2..b11134305 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -6,6 +6,7 @@
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
+#define _NPY_NO_DEPRECATIONS /* for NPY_CHAR */
#include "numpy/npy_common.h"
#include "numpy/arrayobject.h"
@@ -4415,6 +4416,17 @@ PyArray_DescrFromType(int type)
return NULL;
}
else if ((type == NPY_CHAR) || (type == NPY_CHARLTR)) {
+ if (type == NPY_CHAR) {
+ /*
+ * warning added 2017-04-25, 1.13
+ * deprecated in 1.7
+ * */
+ if (DEPRECATE("The NPY_CHAR type_num is deprecated. "
+ "Please port your code to use "
+ "NPY_STRING instead.") < 0) {
+ return NULL;
+ }
+ }
ret = PyArray_DescrNew(_builtin_descrs[NPY_STRING]);
if (ret == NULL) {
return NULL;
diff --git a/numpy/core/src/multiarray/multiarray_tests.c.src b/numpy/core/src/multiarray/multiarray_tests.c.src
index 45092dc0c..de05cc280 100644
--- a/numpy/core/src/multiarray/multiarray_tests.c.src
+++ b/numpy/core/src/multiarray/multiarray_tests.c.src
@@ -1,6 +1,7 @@
/* -*-c-*- */
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#include <Python.h>
+#define _NPY_NO_DEPRECATIONS /* for NPY_CHAR */
#include "numpy/arrayobject.h"
#include "mem_overlap.h"
#include "npy_extint128.h"
@@ -608,6 +609,13 @@ incref_elide_l(PyObject *dummy, PyObject *args)
return res;
}
+/* used to test NPY_CHAR usage emits deprecation warning */
+static PyObject*
+npy_char_deprecation(PyObject* NPY_UNUSED(self), PyObject* NPY_UNUSED(args))
+{
+ PyArray_Descr * descr = PyArray_DescrFromType(NPY_CHAR);
+ return (PyObject *)descr;
+}
#if !defined(NPY_PY3K)
static PyObject *
@@ -1576,6 +1584,9 @@ static PyMethodDef Multiarray_TestsMethods[] = {
{"incref_elide_l",
incref_elide_l,
METH_VARARGS, NULL},
+ {"npy_char_deprecation",
+ npy_char_deprecation,
+ METH_NOARGS, NULL},
#if !defined(NPY_PY3K)
{"test_int_subclass",
int_subclass,
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index 46b2c79aa..2f1cedd9b 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -421,5 +421,12 @@ class TestClassicIntDivision(_DeprecationTestCase):
dt2 = dt1
+class TestNPY_CHAR(_DeprecationTestCase):
+ def test_npy_char_deprecation(self):
+ from numpy.core.multiarray_tests import npy_char_deprecation
+ self.assert_deprecated(npy_char_deprecation)
+ assert_(npy_char_deprecation() == 'S1')
+
+
if __name__ == "__main__":
run_module_suite()