diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-08-01 18:15:29 +0000 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-08-05 21:56:03 -0500 |
commit | 091b8c3b16d39d18f6921f9a17d06c1652b40dca (patch) | |
tree | d4dd9c45a2a27893134cd77c7bd959afacb42c51 /numpy/core | |
parent | 4cac8cba65b343f845a7068407997105cca7bfc9 (diff) | |
download | numpy-091b8c3b16d39d18f6921f9a17d06c1652b40dca.tar.gz |
DEP: Deprecate the coercion of dtype-likes to their superclass
In many cases, this coercion is surprising, or would be if the user knew about it:
* [('a', int)] -> np.flexible
* str - > str (!) - not even a numpy type
* 'float32' -> np.floating (discards size)
* int -> np.signed_integer (not np.integer, as is usually meant)
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/numerictypes.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index fbe89b226..d961d69ac 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -85,6 +85,7 @@ from __future__ import division, absolute_import, print_function import types as _types import sys import numbers +import warnings from numpy.compat import bytes, long from numpy.core.multiarray import ( @@ -763,6 +764,27 @@ def issubdtype(arg1, arg2): mro = arg2.mro() arg2 = mro[1] if len(mro) > 1 else mro[0] + def type_repr(x): + """ Helper to produce clear error messages """ + if not isinstance(x, type): + return repr(x) + elif issubclass(x, generic): + return "np.{}".format(x.__name__) + else: + return x.__name__ + + # 1.14, 2017-08-01 + warnings.warn( + "Conversion of the second argument of issubdtype from `{raw}` " + "to `{abstract}` is deprecated. In future, it will be treated " + "as `{concrete} == np.dtype({raw}).type`.".format( + raw=type_repr(arg2_orig), + abstract=type_repr(arg2), + concrete=type_repr(dtype(arg2_orig).type) + ), + FutureWarning, stacklevel=2 + ) + return issubclass(arg1, arg2) |