Skip to content

Commit

Permalink
Merge pull request #16830 from bsipocz/python2_cleanup
Browse files Browse the repository at this point in the history
MAINT: more python <3.6  cleanup
  • Loading branch information
mattip committed May 18, 2022
2 parents 59aad3c + ae16484 commit 6932eff
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 70 deletions.
6 changes: 6 additions & 0 deletions doc/release/upcoming_changes/16830.expired.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
``NpzFile.iteritems()`` and ``NpzFile.iterkeys()`` are removed
--------------------------------------------------------------

As part of the continued removal of Python 2 compatibility
``NpzFile.iteritems()`` and ``NpzFile.iterkeys()`` methods are now removed. This
concludes the deprecation from 1.15.
20 changes: 1 addition & 19 deletions doc/source/user/misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ Only a survey of the choices. Little detail on how each works.

- getting it wrong leads to memory leaks, and worse, segfaults

- API will change for Python 3.0!

2) Cython

- Plusses:
Expand Down Expand Up @@ -183,21 +181,7 @@ Only a survey of the choices. Little detail on how each works.
- doesn't necessarily avoid reference counting issues or needing to know
API's

5) scipy.weave

- Plusses:

- can turn many numpy expressions into C code
- dynamic compiling and loading of generated C code
- can embed pure C code in Python module and have weave extract, generate
interfaces and compile, etc.

- Minuses:

- Future very uncertain: it's the only part of Scipy not ported to Python 3
and is effectively deprecated in favor of Cython.

6) Psyco
5) Psyco

- Plusses:

Expand Down Expand Up @@ -226,5 +210,3 @@ Interfacing to C++:
3) Boost.python
4) SWIG
5) SIP (used mainly in PyQT)


1 change: 1 addition & 0 deletions numpy/core/_add_newdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,7 @@
text, the binary mode of `fromstring` will first encode it into
bytes using either utf-8 (python 3) or the default encoding
(python 2), neither of which produce sane results.
${ARRAY_FUNCTION_LIKE}
.. versionadded:: 1.20.0
Expand Down
4 changes: 3 additions & 1 deletion numpy/core/include/numpy/npy_3kcompat.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* This is a convenience header file providing compatibility utilities
* for supporting Python 2 and Python 3 in the same code base.
* for supporting different minor versions of Python 3.
* It was originally used to support the transition from Python 2,
* hence the "3k" naming.
*
* If you want to use this for your own projects, it's recommended to make a
* copy of it. Although the stuff below is unlikely to change, we don't provide
Expand Down
3 changes: 0 additions & 3 deletions numpy/distutils/mingw32ccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ def get_msvcr_replacement():
msvcr = msvc_runtime_library()
return [] if msvcr is None else [msvcr]

# monkey-patch cygwinccompiler with our updated version from misc_util
# to avoid getting an exception raised on Python 3.5
distutils.cygwinccompiler.get_msvcr = get_msvcr_replacement

# Useful to generate table of symbols from a dll
_START = re.compile(r'\[Ordinal/Name Pointer\] Table')
Expand Down
5 changes: 1 addition & 4 deletions numpy/distutils/misc_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,7 @@ def get_shared_lib_extension(is_python_ext=False):
"""
confvars = distutils.sysconfig.get_config_vars()
# SO is deprecated in 3.3.1, use EXT_SUFFIX instead
so_ext = confvars.get('EXT_SUFFIX', None)
if so_ext is None:
so_ext = confvars.get('SO', '')
so_ext = confvars.get('EXT_SUFFIX', '')

if not is_python_ext:
# hardcode known values, config vars (including SHLIB_SUFFIX) are
Expand Down
3 changes: 1 addition & 2 deletions numpy/lib/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,7 @@ def _wrap_header(header, version):
import struct
assert version is not None
fmt, encoding = _header_size_info[version]
if not isinstance(header, bytes): # always true on python 3
header = header.encode(encoding)
header = header.encode(encoding)
hlen = len(header) + 1
padlen = ARRAY_ALIGN - ((MAGIC_LEN + struct.calcsize(fmt) + hlen) % ARRAY_ALIGN)
try:
Expand Down
20 changes: 0 additions & 20 deletions numpy/lib/npyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,26 +250,6 @@ def __getitem__(self, key):
else:
raise KeyError("%s is not a file in the archive" % key)

# deprecate the python 2 dict apis that we supported by accident in
# python 3. We forgot to implement itervalues() at all in earlier
# versions of numpy, so no need to deprecated it here.

def iteritems(self):
# Numpy 1.15, 2018-02-20
warnings.warn(
"NpzFile.iteritems is deprecated in python 3, to match the "
"removal of dict.itertems. Use .items() instead.",
DeprecationWarning, stacklevel=2)
return self.items()

def iterkeys(self):
# Numpy 1.15, 2018-02-20
warnings.warn(
"NpzFile.iterkeys is deprecated in python 3, to match the "
"removal of dict.iterkeys. Use .keys() instead.",
DeprecationWarning, stacklevel=2)
return self.keys()


@set_module('numpy')
def load(file, mmap_mode=None, allow_pickle=False, fix_imports=True,
Expand Down
8 changes: 1 addition & 7 deletions numpy/random/bit_generator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ import abc
import sys
from itertools import cycle
import re

try:
from secrets import randbits
except ImportError:
# secrets unavailable on python 3.5 and before
from random import SystemRandom
randbits = SystemRandom().getrandbits
from secrets import randbits

from threading import Lock

Expand Down
3 changes: 0 additions & 3 deletions numpy/testing/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,9 +1342,6 @@ def assert_raises_regex(exception_class, expected_regexp, *args, **kwargs):
Alternatively, can be used as a context manager like `assert_raises`.
Name of this function adheres to Python 3.2+ reference, but should work in
all versions down to 2.6.
Notes
-----
.. versionadded:: 1.9.0
Expand Down
16 changes: 5 additions & 11 deletions numpy/testing/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_suppress_overflow_warnings(self):
with pytest.raises(AssertionError):
with np.errstate(all="raise"):
np.testing.assert_array_equal(
np.array([1, 2, 3], np.float32),
np.array([1, 2, 3], np.float32),
np.array([1, 1e-40, 3], np.float32))


Expand Down Expand Up @@ -1224,7 +1224,7 @@ def test_regex(self):
lambda: assert_string_equal("aaa", "a+b"))


def assert_warn_len_equal(mod, n_in_context, py34=None, py37=None):
def assert_warn_len_equal(mod, n_in_context, py37=None):
try:
mod_warns = mod.__warningregistry__
except AttributeError:
Expand All @@ -1238,10 +1238,7 @@ def assert_warn_len_equal(mod, n_in_context, py34=None, py37=None):
mod_warns = {}

num_warns = len(mod_warns)
# Python 3.4 appears to clear any pre-existing warnings of the same type,
# when raising warnings inside a catch_warnings block. So, there is a
# warning generated by the tests within the context manager, but no
# previous warnings.

if 'version' in mod_warns:
# Python 3 adds a 'version' entry to the registry,
# do not count it.
Expand All @@ -1253,9 +1250,7 @@ def assert_warn_len_equal(mod, n_in_context, py34=None, py37=None):
if sys.version_info[:2] >= (3, 7):
if py37 is not None:
n_in_context = py37
else:
if py34 is not None:
n_in_context = py34

assert_equal(num_warns, n_in_context)

def test_warn_len_equal_call_scenarios():
Expand Down Expand Up @@ -1318,12 +1313,11 @@ def test_clear_and_catch_warnings():
warnings.warn('Another warning')
assert_warn_len_equal(my_mod, 1, py37=0)
# Another warning, no module spec does add to warnings dict, except on
# Python 3.4 (see comments in `assert_warn_len_equal`)
# Python 3.7 catch_warnings doesn't make an entry for 'ignore'.
with clear_and_catch_warnings():
warnings.simplefilter('ignore')
warnings.warn('Another warning')
assert_warn_len_equal(my_mod, 2, py34=1, py37=0)
assert_warn_len_equal(my_mod, 2, py37=0)


def test_suppress_warnings_module():
Expand Down

0 comments on commit 6932eff

Please sign in to comment.