diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2016-06-14 12:36:37 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-14 12:36:37 -0600 |
commit | fb1a2cc4ee72852503758e7939ad1c827ce690b3 (patch) | |
tree | f88e9d8c1a8076865be2df698e2095d1b89866b2 /numpy/core | |
parent | ce0896645ed6e188be33193484edecac8b7a0f94 (diff) | |
parent | dceaf05a55d51f1aab5e962c632c6a15c3f6448b (diff) | |
download | numpy-fb1a2cc4ee72852503758e7939ad1c827ce690b3.tar.gz |
Merge pull request #7743 from charris/update-7476
Update 7476, DEP: deprecate Numeric-style typecodes, closes #2148
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/multiarray/descriptor.c | 25 | ||||
-rw-r--r-- | numpy/core/tests/test_deprecations.py | 25 |
2 files changed, 49 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/descriptor.c b/numpy/core/src/multiarray/descriptor.c index 7f8be5356..fbfda72d7 100644 --- a/numpy/core/src/multiarray/descriptor.c +++ b/numpy/core/src/multiarray/descriptor.c @@ -1539,6 +1539,31 @@ finish: } #endif if (item) { + /* Check for a deprecated Numeric-style typecode */ + if (PyBytes_Check(obj)) { + char *type = NULL; + Py_ssize_t len = 0; + char *dep_tps[] = {"Bool", "Complex", "Float", "Int", + "Object0", "String0", "Timedelta64", + "Unicode0", "UInt", "Void0"}; + int ndep_tps = sizeof(dep_tps) / sizeof(dep_tps[0]); + int i; + + if (PyBytes_AsStringAndSize(obj, &type, &len) < 0) { + goto error; + } + for (i = 0; i < ndep_tps; ++i) { + char *dep_tp = dep_tps[i]; + + if (strncmp(type, dep_tp, strlen(dep_tp)) == 0) { + if (DEPRECATE("Numeric-style type codes are " + "deprecated and will result in " + "an error in the future.") < 0) { + goto fail; + } + } + } + } return PyArray_DescrConverter(item, at); } } diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index e6d3cd261..547280b23 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -198,7 +198,7 @@ class _DeprecationTestCase(object): (warning.category,)) if num is not None and num_found != num: msg = "%i warnings found but %i expected." % (len(self.log), num) - lst = [w.category for w in self.log] + lst = [str(w.category) for w in self.log] raise AssertionError("\n".join([msg] + lst)) with warnings.catch_warnings(): @@ -609,6 +609,29 @@ class TestBinaryReprInsufficientWidthParameterForRepresentation(_DeprecationTest self.assert_deprecated(np.binary_repr, args=args, kwargs=kwargs) +class TestNumericStyleTypecodes(_DeprecationTestCase): + """ + Deprecate the old numeric-style dtypes, which are especially + confusing for complex types, e.g. Complex32 -> complex64. When the + deprecation cycle is complete, the check for the strings should be + removed from PyArray_DescrConverter in descriptor.c, and the + deprecated keys should not be added as capitalized aliases in + _add_aliases in numerictypes.py. + """ + def test_all_dtypes(self): + deprecated_types = [ + 'Bool', 'Complex32', 'Complex64', 'Float16', 'Float32', 'Float64', + 'Int8', 'Int16', 'Int32', 'Int64', 'Object0', 'Timedelta64', + 'UInt8', 'UInt16', 'UInt32', 'UInt64', 'Void0' + ] + if sys.version_info[0] < 3: + deprecated_types.extend(['Unicode0', 'String0']) + + for dt in deprecated_types: + self.assert_deprecated(np.dtype, exceptions=(TypeError,), + args=(dt,)) + + class TestTestDeprecated(object): def test_assert_deprecated(self): test_case_instance = _DeprecationTestCase() |