Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DEP: deprecate np.bool, np.int, np.float, np.long, np.str, np.unicode, and np.complex, which are misleading aliases for builtin types #6103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@

import sys

from ._metamodule import install
install(__name__)
del install

class ModuleDeprecationWarning(DeprecationWarning):
"""Module deprecation warning.
Expand Down Expand Up @@ -205,11 +208,35 @@ def pkgload(*packages, **options):

# Make these accessible from numpy name-space
# but not imported in from numpy import *
# and make them issue a DeprecationWarning when used
if sys.version_info[0] >= 3:
from builtins import bool, int, float, complex, object, str
unicode = str
import builtins as _builtins
else:
from __builtin__ import bool, int, float, complex, object, unicode, str
import __builtin__ as _builtins
for _name, _numpy_equiv in [
("bool", "bool_"),
("int", "int_"),
("float", "float64"),
("complex", "complex128"),
("object", "object_"),
("str", "string_"),
Copy link
Member

@eric-wieser eric-wieser Jun 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not correct - np.dtype(str) and np.dtype(np.string_) are different on python 3. Should be np.str_

("unicode", "unicode_"),
]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing here: long

if sys.version_info[0] >= 3 and _name == "unicode":
_obj = str
else:
_obj = getattr(_builtins, _name)
__warn_on_access__[_name] = (
_obj,
DeprecationWarning(
"Writing 'np.{0}' is almost always a mistake. Historically "
"and currently it is identical to writing plain '{0}' "
"(i.e., it refers to the Python builtin), and at some point "
"in the future it will become an error. Replace with '{0}', "
"or if you want the numpy-specific type, use 'np.{1}'."
.format(_name, _numpy_equiv))
)
del _builtins, _name, _numpy_equiv, _obj

from .core import round, abs, max, min

Expand Down
4 changes: 3 additions & 1 deletion numpy/testing/nosetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,9 @@ def test(self, label='fast', verbose=1, extra_argv=None,
warnings.filterwarnings('always', category=DeprecationWarning)
# Force the requested warnings to raise
for warningtype in raise_warnings:
warnings.filterwarnings('error', category=warningtype)
warnings.filterwarnings('error',
category=warningtype,
module=r"numpy.*")
# Filter out annoying import messages.
warnings.filterwarnings('ignore', message='Not importing directory')
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
Expand Down