diff options
Diffstat (limited to 'numpy')
36 files changed, 46 insertions, 94 deletions
diff --git a/numpy/_pytesttester.py b/numpy/_pytesttester.py index 8b6e3217e..e573d53ab 100644 --- a/numpy/_pytesttester.py +++ b/numpy/_pytesttester.py @@ -125,13 +125,6 @@ class PytestTester: import pytest import warnings - #FIXME This is no longer needed? Assume it was for use in tests. - # cap verbosity at 3, which is equivalent to the pytest '-vv' option - #from . import utils - #verbose = min(int(verbose), 3) - #utils.verbose = verbose - # - module = sys.modules[self.module_name] module_path = os.path.abspath(module.__path__[0]) @@ -162,16 +155,6 @@ class PytestTester: "-W ignore:the matrix subclass is not", ] - # Ignore python2.7 -3 warnings - pytest_args += [ - r"-W ignore:buffer\(\) not supported in 3\.x:DeprecationWarning", - r"-W ignore:CObject type is not supported in 3\.x:DeprecationWarning", - r"-W ignore:comparing unequal types not supported in 3\.x:DeprecationWarning", - r"-W ignore:the commands module has been removed in Python 3\.0:DeprecationWarning", - r"-W ignore:The 'new' module has been removed in Python 3\.0:DeprecationWarning", - ] - - if doctests: raise ValueError("Doctests not supported") diff --git a/numpy/core/_add_newdocs.py b/numpy/core/_add_newdocs.py index cb68b8360..87ae96fa0 100644 --- a/numpy/core/_add_newdocs.py +++ b/numpy/core/_add_newdocs.py @@ -8,7 +8,6 @@ NOTE: Many of the methods of ndarray have corresponding functions. core/fromnumeric.py, core/defmatrix.py up-to-date. """ -import sys from numpy.core import numerictypes as _numerictypes from numpy.core import dtype diff --git a/numpy/core/_exceptions.py b/numpy/core/_exceptions.py index 88a45561f..99172e23d 100644 --- a/numpy/core/_exceptions.py +++ b/numpy/core/_exceptions.py @@ -157,7 +157,6 @@ class _ArrayMemoryError(MemoryError): @staticmethod def _size_to_string(num_bytes): """ Convert a number of bytes into a binary size string """ - import math # https://en.wikipedia.org/wiki/Binary_prefix LOG2_STEP = 10 diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index ec7e4261f..456ef76f0 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -31,12 +31,12 @@ except ImportError: import numpy as np from . import numerictypes as _nt -from .umath import absolute, not_equal, isnan, isinf, isfinite, isnat +from .umath import absolute, isinf, isfinite, isnat from . import multiarray from .multiarray import (array, dragon4_positional, dragon4_scientific, datetime_as_string, datetime_data, ndarray, set_legacy_print_mode) -from .fromnumeric import ravel, any +from .fromnumeric import any from .numeric import concatenate, asarray, errstate from .numerictypes import (longlong, intc, int_, float_, complex_, bool_, flexible) diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 213a4438f..46dd961d8 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -6,7 +6,6 @@ import types import warnings import numpy as np -from .. import VisibleDeprecationWarning from . import multiarray as mu from . import overrides from . import umath as um diff --git a/numpy/core/multiarray.py b/numpy/core/multiarray.py index d8adc640e..d50c53e30 100644 --- a/numpy/core/multiarray.py +++ b/numpy/core/multiarray.py @@ -7,13 +7,10 @@ by importing from the extension module. """ import functools -import sys import warnings -import sys from . import overrides from . import _multiarray_umath -import numpy as np from ._multiarray_umath import * # noqa: F403 from ._multiarray_umath import ( _fastCopyAndTranspose, _flagdict, _insert, _reconstruct, _vec_string, diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 72c6089b8..f1d7d48f1 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -4,10 +4,9 @@ import operator import sys import warnings import numbers -import contextlib import numpy as np -from numpy.compat import pickle, basestring +from numpy.compat import basestring from . import multiarray from .multiarray import ( _fastCopyAndTranspose as fastCopyAndTranspose, ALLOW_THREADS, diff --git a/numpy/core/records.py b/numpy/core/records.py index d4aa2feb9..fbef40f72 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -33,7 +33,6 @@ Record arrays allow us to access fields as properties:: array([2., 2.]) """ -import sys import os import warnings from collections import Counter, OrderedDict diff --git a/numpy/core/setup_common.py b/numpy/core/setup_common.py index 08337a81e..7cac66e61 100644 --- a/numpy/core/setup_common.py +++ b/numpy/core/setup_common.py @@ -2,7 +2,6 @@ import sys import warnings import copy -import binascii import textwrap from numpy.distutils.misc_util import mingw32 diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src index cd26d20fa..383cef5bd 100644 --- a/numpy/core/src/multiarray/scalartypes.c.src +++ b/numpy/core/src/multiarray/scalartypes.c.src @@ -2562,25 +2562,20 @@ object_arrtype_dealloc(PyObject *v) * memory from the sub-types memory allocator. */ -#define _WORK(num) \ - if (type->tp_bases && (PyTuple_GET_SIZE(type->tp_bases)==2)) { \ - PyTypeObject *sup; \ - /* We are inheriting from a Python type as well so \ - give it first dibs on conversion */ \ - sup = (PyTypeObject *)PyTuple_GET_ITEM(type->tp_bases, num); \ - /* Prevent recursion */ \ - if (thisfunc != sup->tp_new) { \ - robj = sup->tp_new(type, args, kwds); \ - if (robj != NULL) goto finish; \ - if (PyTuple_GET_SIZE(args)!=1) return NULL; \ - PyErr_Clear(); \ - } \ - /* now do default conversion */ \ - } - -#define _WORK1 _WORK(1) -#define _WORKz _WORK(0) -#define _WORK0 +#define _WORK(cls, num) \ + assert(cls.tp_bases && (PyTuple_GET_SIZE(cls.tp_bases) == 2)); \ + /* We are inheriting from a Python type as well so \ + give it first dibs on conversion */ \ + PyTypeObject *sup = (PyTypeObject *)PyTuple_GET_ITEM(cls.tp_bases, num); \ + robj = sup->tp_new(type, args, kwds); \ + if (robj != NULL) goto finish; \ + if (PyTuple_GET_SIZE(args) != 1) return NULL; \ + PyErr_Clear(); \ + /* now do default conversion */ + +#define _WORK1(cls) _WORK(cls, 1) +#define _WORKz(cls) _WORK(cls, 0) +#define _WORK0(cls) /**begin repeat * #name = byte, short, int, long, longlong, ubyte, ushort, uint, ulong, @@ -2592,7 +2587,7 @@ object_arrtype_dealloc(PyObject *v) * #TYPE = BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, * ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, * CLONGDOUBLE, STRING, UNICODE, OBJECT# - * #work = 0,0,1,1,1,0,0,0,0,0,0,0,1,0,0,0,0,z,z,0# + * #work = 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,z,z,0# * #default = 0*17,1*2,2# */ @@ -2610,9 +2605,6 @@ static PyObject * PyObject *robj; PyArrayObject *arr; PyArray_Descr *typecode = NULL; -#if (@work@ != 0) || (@default@ == 1) - void *thisfunc = (void *)@name@_arrtype_new; -#endif #if !(@default@ == 2) int itemsize; void *dest, *src; @@ -2622,7 +2614,7 @@ static PyObject * * allow base-class (if any) to do conversion * If successful, this will jump to finish: */ - _WORK@work@ + _WORK@work@(Py@Name@ArrType_Type) /* TODO: include type name in error message, which is not @name@ */ if (!PyArg_ParseTuple(args, "|O", &obj)) { diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py index 96240be0f..cd3e501a5 100644 --- a/numpy/core/tests/test_arrayprint.py +++ b/numpy/core/tests/test_arrayprint.py @@ -837,7 +837,6 @@ class TestPrintOptions: assert_raises(TypeError, np.set_printoptions, threshold=b'1') def test_unicode_object_array(): - import sys expected = "array(['é'], dtype=object)" x = np.array([u'\xe9'], dtype=object) assert_equal(repr(x), expected) diff --git a/numpy/core/tests/test_defchararray.py b/numpy/core/tests/test_defchararray.py index 4c9016c3e..39600553d 100644 --- a/numpy/core/tests/test_defchararray.py +++ b/numpy/core/tests/test_defchararray.py @@ -1,10 +1,9 @@ -import sys import numpy as np from numpy.core.multiarray import _vec_string from numpy.testing import ( assert_, assert_equal, assert_array_equal, assert_raises, - assert_raises_regex, suppress_warnings, + assert_raises_regex ) kw_unicode_true = {'unicode': True} # make 2to3 work properly diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index 252133d7b..01b35ec90 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -4,11 +4,9 @@ to document how deprecations should eventually be turned into errors. """ import datetime -import sys import operator import warnings import pytest -import shutil import tempfile import numpy as np diff --git a/numpy/core/tests/test_function_base.py b/numpy/core/tests/test_function_base.py index 7e5ea1cc6..2197ef0cd 100644 --- a/numpy/core/tests/test_function_base.py +++ b/numpy/core/tests/test_function_base.py @@ -4,7 +4,6 @@ from numpy import ( ) from numpy.testing import ( assert_, assert_equal, assert_raises, assert_array_equal, assert_allclose, - suppress_warnings ) diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py index 237e381a7..4bb5cb11a 100644 --- a/numpy/core/tests/test_indexing.py +++ b/numpy/core/tests/test_indexing.py @@ -2,7 +2,6 @@ import sys import warnings import functools import operator -import pytest import numpy as np from numpy.core._multiarray_tests import array_indexing diff --git a/numpy/core/tests/test_mem_overlap.py b/numpy/core/tests/test_mem_overlap.py index d3b58d8e8..3e9875f5b 100644 --- a/numpy/core/tests/test_mem_overlap.py +++ b/numpy/core/tests/test_mem_overlap.py @@ -1,4 +1,3 @@ -import sys import itertools import pytest diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index c4956c298..33e71a064 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -2015,7 +2015,7 @@ class TestClip: def test_NaT_propagation(self, arr, amin, amax): # NOTE: the expected function spec doesn't # propagate NaT, but clip() now does - expected = np.minimum(np.maximum(a, amin), amax) + expected = np.minimum(np.maximum(arr, amin), amax) actual = np.clip(arr, amin, amax) assert_equal(actual, expected) diff --git a/numpy/core/tests/test_scalar_ctors.py b/numpy/core/tests/test_scalar_ctors.py index d3592a5fc..2de5084b6 100644 --- a/numpy/core/tests/test_scalar_ctors.py +++ b/numpy/core/tests/test_scalar_ctors.py @@ -1,13 +1,9 @@ """ Test the scalar constructors, which also do type-coercion """ -import sys -import platform -import pytest - import numpy as np from numpy.testing import ( - assert_equal, assert_almost_equal, assert_raises, assert_warns, + assert_equal, assert_almost_equal, assert_warns, ) class TestFromString: diff --git a/numpy/core/tests/test_scalar_methods.py b/numpy/core/tests/test_scalar_methods.py index c9de3e402..4f5fd2988 100644 --- a/numpy/core/tests/test_scalar_methods.py +++ b/numpy/core/tests/test_scalar_methods.py @@ -1,18 +1,14 @@ """ Test the scalar constructors, which also do type-coercion """ -import os import fractions import platform import pytest import numpy as np -from numpy.testing import ( - run_module_suite, - assert_equal, assert_almost_equal, assert_raises, assert_warns, - dec -) +from numpy.testing import assert_equal, assert_raises + class TestAsIntegerRatio: # derived in part from the cpython test "test_floatasratio" diff --git a/numpy/core/tests/test_scalarbuffer.py b/numpy/core/tests/test_scalarbuffer.py index bda1c5333..b8c6dd4aa 100644 --- a/numpy/core/tests/test_scalarbuffer.py +++ b/numpy/core/tests/test_scalarbuffer.py @@ -1,7 +1,6 @@ """ Test scalar buffer interface adheres to PEP 3118 """ -import sys import numpy as np import pytest diff --git a/numpy/core/tests/test_scalarinherit.py b/numpy/core/tests/test_scalarinherit.py index af3669d73..74829986c 100644 --- a/numpy/core/tests/test_scalarinherit.py +++ b/numpy/core/tests/test_scalarinherit.py @@ -2,6 +2,8 @@ """ Test printing of scalar types. """ +import pytest + import numpy as np from numpy.testing import assert_ @@ -21,6 +23,14 @@ class B0(np.float64, A): class C0(B0): pass +class HasNew: + def __new__(cls, *args, **kwargs): + return cls, args, kwargs + +class B1(np.float64, HasNew): + pass + + class TestInherit: def test_init(self): x = B(1.0) @@ -36,6 +46,15 @@ class TestInherit: y = C0(2.0) assert_(str(y) == '2.0') + def test_gh_15395(self): + # HasNew is the second base, so `np.float64` should have priority + x = B1(1.0) + assert_(str(x) == '1.0') + + # previously caused RecursionError!? + with pytest.raises(TypeError): + B1(1.0, 2.0) + class TestCharacter: def test_char_radd(self): diff --git a/numpy/core/tests/test_scalarprint.py b/numpy/core/tests/test_scalarprint.py index 3293d0426..d042eef8b 100644 --- a/numpy/core/tests/test_scalarprint.py +++ b/numpy/core/tests/test_scalarprint.py @@ -8,7 +8,7 @@ import pytest from tempfile import TemporaryFile import numpy as np -from numpy.testing import assert_, assert_equal, suppress_warnings +from numpy.testing import assert_, assert_equal class TestRealScalars: def test_str(self): diff --git a/numpy/core/tests/test_shape_base.py b/numpy/core/tests/test_shape_base.py index 7c23c7128..738260327 100644 --- a/numpy/core/tests/test_shape_base.py +++ b/numpy/core/tests/test_shape_base.py @@ -1,5 +1,4 @@ import pytest -import sys import numpy as np from numpy.core import ( array, arange, atleast_1d, atleast_2d, atleast_3d, block, vstack, hstack, diff --git a/numpy/core/tests/test_unicode.py b/numpy/core/tests/test_unicode.py index f16789148..ac065d5d6 100644 --- a/numpy/core/tests/test_unicode.py +++ b/numpy/core/tests/test_unicode.py @@ -1,5 +1,3 @@ -import sys - import numpy as np from numpy.compat import unicode from numpy.testing import assert_, assert_equal, assert_array_equal diff --git a/numpy/distutils/ccompiler.py b/numpy/distutils/ccompiler.py index dc7ae6d46..9ea083774 100644 --- a/numpy/distutils/ccompiler.py +++ b/numpy/distutils/ccompiler.py @@ -1,7 +1,6 @@ import os import re import sys -import types import shlex import time import subprocess diff --git a/numpy/lib/_datasource.py b/numpy/lib/_datasource.py index b40091c9b..76cc306b7 100644 --- a/numpy/lib/_datasource.py +++ b/numpy/lib/_datasource.py @@ -36,7 +36,6 @@ Example:: """ import os import sys -import warnings import shutil import io from contextlib import closing diff --git a/numpy/lib/format.py b/numpy/lib/format.py index 114bae287..b31340314 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -599,7 +599,7 @@ def _read_array_header(fp, version): raise ValueError(msg.format(d['fortran_order'])) try: dtype = descr_to_dtype(d['descr']) - except TypeError as e: + except TypeError: msg = "descr is not a valid dtype descriptor: {!r}" raise ValueError(msg.format(d['descr'])) diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py index d3bd88d7f..1ed7815d9 100644 --- a/numpy/lib/tests/test__datasource.py +++ b/numpy/lib/tests/test__datasource.py @@ -1,13 +1,10 @@ import os -import sys import pytest from tempfile import mkdtemp, mkstemp, NamedTemporaryFile from shutil import rmtree import numpy.lib._datasource as datasource -from numpy.testing import ( - assert_, assert_equal, assert_raises, assert_warns - ) +from numpy.testing import assert_, assert_equal, assert_raises import urllib.request as urllib_request from urllib.parse import urlparse diff --git a/numpy/lib/tests/test_mixins.py b/numpy/lib/tests/test_mixins.py index e184ffe19..a9a0c9081 100644 --- a/numpy/lib/tests/test_mixins.py +++ b/numpy/lib/tests/test_mixins.py @@ -1,6 +1,5 @@ import numbers import operator -import sys import numpy as np from numpy.testing import assert_, assert_equal, assert_raises diff --git a/numpy/lib/tests/test_regression.py b/numpy/lib/tests/test_regression.py index 37cc158ba..a2598990b 100644 --- a/numpy/lib/tests/test_regression.py +++ b/numpy/lib/tests/test_regression.py @@ -1,5 +1,4 @@ import os -import sys import numpy as np from numpy.testing import ( diff --git a/numpy/polynomial/chebyshev.py b/numpy/polynomial/chebyshev.py index 0bb297807..e547d151c 100644 --- a/numpy/polynomial/chebyshev.py +++ b/numpy/polynomial/chebyshev.py @@ -87,7 +87,6 @@ References (preprint: https://www.math.hmc.edu/~benjamin/papers/CombTrig.pdf, pg. 4) """ -import warnings import numpy as np import numpy.linalg as la from numpy.core.multiarray import normalize_axis_index @@ -1058,7 +1057,6 @@ def chebint(c, m=1, k=[], lbnd=0, scl=1, axis=0): if n > 1: tmp[2] = c[1]/4 for j in range(2, n): - t = c[j]/(2*j + 1) # FIXME: t never used tmp[j + 1] = c[j]/(2*(j + 1)) tmp[j - 1] -= c[j]/(2*(j - 1)) tmp[0] += k[i] - chebval(lbnd, tmp) diff --git a/numpy/polynomial/hermite.py b/numpy/polynomial/hermite.py index cb98b7e1f..4db344720 100644 --- a/numpy/polynomial/hermite.py +++ b/numpy/polynomial/hermite.py @@ -58,7 +58,6 @@ See also `numpy.polynomial` """ -import warnings import numpy as np import numpy.linalg as la from numpy.core.multiarray import normalize_axis_index diff --git a/numpy/polynomial/hermite_e.py b/numpy/polynomial/hermite_e.py index 1f4a93c24..a7ff67f9c 100644 --- a/numpy/polynomial/hermite_e.py +++ b/numpy/polynomial/hermite_e.py @@ -58,7 +58,6 @@ See also `numpy.polynomial` """ -import warnings import numpy as np import numpy.linalg as la from numpy.core.multiarray import normalize_axis_index diff --git a/numpy/polynomial/laguerre.py b/numpy/polynomial/laguerre.py index bf8e11623..0ab17f2f1 100644 --- a/numpy/polynomial/laguerre.py +++ b/numpy/polynomial/laguerre.py @@ -58,7 +58,6 @@ See also `numpy.polynomial` """ -import warnings import numpy as np import numpy.linalg as la from numpy.core.multiarray import normalize_axis_index diff --git a/numpy/polynomial/legendre.py b/numpy/polynomial/legendre.py index d74b87d5a..ec2f9e828 100644 --- a/numpy/polynomial/legendre.py +++ b/numpy/polynomial/legendre.py @@ -81,7 +81,6 @@ numpy.polynomial.hermite numpy.polynomial.hermite_e """ -import warnings import numpy as np import numpy.linalg as la from numpy.core.multiarray import normalize_axis_index diff --git a/numpy/polynomial/polynomial.py b/numpy/polynomial/polynomial.py index 92fdc06fa..94c722628 100644 --- a/numpy/polynomial/polynomial.py +++ b/numpy/polynomial/polynomial.py @@ -62,7 +62,6 @@ __all__ = [ 'polyfit', 'polytrim', 'polyroots', 'Polynomial', 'polyval2d', 'polyval3d', 'polygrid2d', 'polygrid3d', 'polyvander2d', 'polyvander3d'] -import warnings import numpy as np import numpy.linalg as la from numpy.core.multiarray import normalize_axis_index |