Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 091b8c3

Browse filesBrowse files
committed
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)
1 parent 4cac8cb commit 091b8c3
Copy full SHA for 091b8c3

File tree

Expand file treeCollapse file tree

2 files changed

+33
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+33
-0
lines changed

‎doc/release/1.14.0-notes.rst

Copy file name to clipboardExpand all lines: doc/release/1.14.0-notes.rst
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ Deprecations
2525
Future Changes
2626
==============
2727

28+
``np.issubdtype`` will stop downcasting dtype-like arguments
29+
------------------------------------------------------------
30+
It would be expected that ``issubdtype(np.float32, 'float64')`` and
31+
``issubdtype(np.float32, np.float64)`` mean the same thing - however, there
32+
was an undocumented special case that translated the former into
33+
``issubdtype(np.float32, np.floating)``, giving the surprising result of True.
34+
35+
This translation now gives a warning explaining what translation is occuring.
36+
In future, the translation will be disabled, and the first example will be made
37+
equivalent to the second.
38+
2839

2940
Build System Changes
3041
====================

‎numpy/core/numerictypes.py

Copy file name to clipboardExpand all lines: numpy/core/numerictypes.py
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import types as _types
8686
import sys
8787
import numbers
88+
import warnings
8889

8990
from numpy.compat import bytes, long
9091
from numpy.core.multiarray import (
@@ -763,6 +764,27 @@ def issubdtype(arg1, arg2):
763764
mro = arg2.mro()
764765
arg2 = mro[1] if len(mro) > 1 else mro[0]
765766

767+
def type_repr(x):
768+
""" Helper to produce clear error messages """
769+
if not isinstance(x, type):
770+
return repr(x)
771+
elif issubclass(x, generic):
772+
return "np.{}".format(x.__name__)
773+
else:
774+
return x.__name__
775+
776+
# 1.14, 2017-08-01
777+
warnings.warn(
778+
"Conversion of the second argument of issubdtype from `{raw}` "
779+
"to `{abstract}` is deprecated. In future, it will be treated "
780+
"as `{concrete} == np.dtype({raw}).type`.".format(
781+
raw=type_repr(arg2_orig),
782+
abstract=type_repr(arg2),
783+
concrete=type_repr(dtype(arg2_orig).type)
784+
),
785+
FutureWarning, stacklevel=2
786+
)
787+
766788
return issubclass(arg1, arg2)
767789

768790

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.