diff options
author | Frederick Lefebvre <fredlef@amazon.com> | 2018-03-14 03:33:05 +0000 |
---|---|---|
committer | fredlef <fredlef@amazon.com> | 2018-03-14 13:14:55 -0700 |
commit | 53b358ce7eddf78ac2bc22045fbe25e91e663b9a (patch) | |
tree | 37054f48b52d3725f7b1f6a840fd0f0d40ba2399 /numpy/core | |
parent | a91f61a429e35a47f6faa025ceb862664dc12609 (diff) | |
download | numpy-53b358ce7eddf78ac2bc22045fbe25e91e663b9a.tar.gz |
TST: Import abstract classes from collections.abc
Abstract collection classes accessed from the collections module
have been deprecated since Python 3.3. They should be
accessed through collections.abc. When run with Python
3.7, the deprecation warning cause multiple tests to
fail.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/numeric.py | 11 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 9 | ||||
-rw-r--r-- | numpy/core/tests/test_records.py | 9 |
3 files changed, 22 insertions, 7 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 1f249ae6c..d2348f364 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1,6 +1,11 @@ from __future__ import division, absolute_import, print_function -import collections +try: + # Accessing collections abstact classes from collections + # has been deprecated since Python 3.3 + import collections.abc as collections_abc +except ImportError: + import collections as collections_abc import itertools import operator import sys @@ -2758,8 +2763,8 @@ def seterrcall(func): {'over': 'log', 'divide': 'log', 'invalid': 'log', 'under': 'log'} """ - if func is not None and not isinstance(func, collections.Callable): - if not hasattr(func, 'write') or not isinstance(func.write, collections.Callable): + if func is not None and not isinstance(func, collections_abc.Callable): + if not hasattr(func, 'write') or not isinstance(func.write, collections_abc.Callable): raise ValueError("Only callable can be used as callback") pyvals = umath.geterrobj() old = geterrcall() diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 43bfb0635..c2d1f2ca5 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -1,6 +1,11 @@ from __future__ import division, absolute_import, print_function -import collections +try: + # Accessing collections abstact classes from collections + # has been deprecated since Python 3.3 + import collections.abc as collections_abc +except ImportError: + import collections as collections_abc import tempfile import sys import shutil @@ -6992,7 +6997,7 @@ class TestHashing(object): def test_collections_hashable(self): x = np.array([]) - assert_(not isinstance(x, collections.Hashable)) + assert_(not isinstance(x, collections_abc.Hashable)) class TestArrayPriority(object): diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py index d5423b1f1..32ce5dc42 100644 --- a/numpy/core/tests/test_records.py +++ b/numpy/core/tests/test_records.py @@ -1,7 +1,12 @@ from __future__ import division, absolute_import, print_function import sys -import collections +try: + # Accessing collections abstact classes from collections + # has been deprecated since Python 3.3 + import collections.abc as collections_abc +except ImportError: + import collections as collections_abc import pickle import warnings import textwrap @@ -252,7 +257,7 @@ class TestFromrecords(object): assert_array_equal(ra['shape'], [['A', 'B', 'C']]) ra.field = 5 assert_array_equal(ra['field'], [[5, 5, 5]]) - assert_(isinstance(ra.field, collections.Callable)) + assert_(isinstance(ra.field, collections_abc.Callable)) def test_fromrecords_with_explicit_dtype(self): a = np.rec.fromrecords([(1, 'a'), (2, 'bbb')], |