summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/_ufunc_config.py12
-rw-r--r--numpy/core/code_generators/generate_umath.py1
-rw-r--r--numpy/core/defchararray.py2
-rw-r--r--numpy/core/multiarray.py4
-rw-r--r--numpy/core/setup.py2
-rw-r--r--numpy/core/setup_common.py35
-rw-r--r--numpy/core/src/multiarray/scalarapi.c28
-rw-r--r--numpy/core/tests/test_mem_overlap.py17
-rw-r--r--numpy/core/tests/test_memmap.py3
-rw-r--r--numpy/core/tests/test_multiarray.py9
-rw-r--r--numpy/core/tests/test_records.py13
-rw-r--r--numpy/core/tests/test_scalarprint.py5
-rw-r--r--numpy/core/tests/test_umath_accuracy.py2
-rw-r--r--numpy/core/umath.py4
14 files changed, 44 insertions, 93 deletions
diff --git a/numpy/core/_ufunc_config.py b/numpy/core/_ufunc_config.py
index 4872a5385..454d911cf 100644
--- a/numpy/core/_ufunc_config.py
+++ b/numpy/core/_ufunc_config.py
@@ -3,12 +3,7 @@ Functions for changing global ufunc configuration
This provides helpers which wrap `umath.geterrobj` and `umath.seterrobj`
"""
-try:
- # Accessing collections abstract classes from collections
- # has been deprecated since Python 3.3
- import collections.abc as collections_abc
-except ImportError:
- import collections as collections_abc
+import collections.abc
import contextlib
from .overrides import set_module
@@ -307,8 +302,9 @@ def seterrcall(func):
OrderedDict([('divide', 'log'), ('invalid', 'log'), ('over', 'log'), ('under', 'log')])
"""
- 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):
+ 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/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py
index 7599360f5..f9ee7d993 100644
--- a/numpy/core/code_generators/generate_umath.py
+++ b/numpy/core/code_generators/generate_umath.py
@@ -298,6 +298,7 @@ defdict = {
],
TD(O, f='PyNumber_Multiply'),
),
+#'divide' : aliased to true_divide in umathmodule.c:initumath
'floor_divide':
Ufunc(2, 1, None, # One is only a unit to the right, not the left
docstrings.get('numpy.core.umath.floor_divide'),
diff --git a/numpy/core/defchararray.py b/numpy/core/defchararray.py
index 1cfdc55c0..bc101f84b 100644
--- a/numpy/core/defchararray.py
+++ b/numpy/core/defchararray.py
@@ -1908,7 +1908,7 @@ class chararray(ndarray):
unicode : bool, optional
Are the array elements of type unicode (True) or string (False).
Default is False.
- buffer : int, optional
+ buffer : object exposing the buffer interface or str, optional
Memory address of the start of the array data. Default is None,
in which case a new array is created.
offset : int, optional
diff --git a/numpy/core/multiarray.py b/numpy/core/multiarray.py
index 5749afdcc..d8adc640e 100644
--- a/numpy/core/multiarray.py
+++ b/numpy/core/multiarray.py
@@ -14,8 +14,8 @@ import sys
from . import overrides
from . import _multiarray_umath
import numpy as np
-from numpy.core._multiarray_umath import *
-from numpy.core._multiarray_umath import (
+from ._multiarray_umath import * # noqa: F403
+from ._multiarray_umath import (
_fastCopyAndTranspose, _flagdict, _insert, _reconstruct, _vec_string,
_ARRAY_API, _monotonicity, _get_ndarray_c_version
)
diff --git a/numpy/core/setup.py b/numpy/core/setup.py
index e376d5a23..66c1b782e 100644
--- a/numpy/core/setup.py
+++ b/numpy/core/setup.py
@@ -14,7 +14,7 @@ from numpy._build_utils.apple_accelerate import (
uses_accelerate_framework, get_sgemv_fix
)
from numpy.compat import npy_load_module
-from setup_common import *
+from setup_common import * # noqa: F403
# Set to True to enable relaxed strides checking. This (mostly) means
# that `strides[dim]` is ignored if `shape[dim] == 1` when setting flags.
diff --git a/numpy/core/setup_common.py b/numpy/core/setup_common.py
index 6d8e603a7..08337a81e 100644
--- a/numpy/core/setup_common.py
+++ b/numpy/core/setup_common.py
@@ -311,32 +311,15 @@ def pyod(filename):
We only implement enough to get the necessary information for long double
representation, this is not intended as a compatible replacement for od.
"""
- def _pyod2():
- out = []
-
- with open(filename, 'rb') as fid:
- yo = [int(oct(int(binascii.b2a_hex(o), 16))) for o in fid.read()]
- for i in range(0, len(yo), 16):
- line = ['%07d' % int(oct(i))]
- line.extend(['%03d' % c for c in yo[i:i+16]])
- out.append(" ".join(line))
- return out
-
- def _pyod3():
- out = []
-
- with open(filename, 'rb') as fid:
- yo2 = [oct(o)[2:] for o in fid.read()]
- for i in range(0, len(yo2), 16):
- line = ['%07d' % int(oct(i)[2:])]
- line.extend(['%03d' % int(c) for c in yo2[i:i+16]])
- out.append(" ".join(line))
- return out
-
- if sys.version_info[0] < 3:
- return _pyod2()
- else:
- return _pyod3()
+ out = []
+ with open(filename, 'rb') as fid:
+ yo2 = [oct(o)[2:] for o in fid.read()]
+ for i in range(0, len(yo2), 16):
+ line = ['%07d' % int(oct(i)[2:])]
+ line.extend(['%03d' % int(c) for c in yo2[i:i+16]])
+ out.append(" ".join(line))
+ return out
+
_BEFORE_SEQ = ['000', '000', '000', '000', '000', '000', '000', '000',
'001', '043', '105', '147', '211', '253', '315', '357']
diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c
index 3a66df454..5c4332364 100644
--- a/numpy/core/src/multiarray/scalarapi.c
+++ b/numpy/core/src/multiarray/scalarapi.c
@@ -45,7 +45,7 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
type_num = descr->type_num;
}
switch (type_num) {
-#define CASE(ut,lt) case NPY_##ut: return &(((Py##lt##ScalarObject *)scalar)->obval)
+#define CASE(ut,lt) case NPY_##ut: return &PyArrayScalar_VAL(scalar, lt)
CASE(BOOL, Bool);
CASE(BYTE, Byte);
CASE(UBYTE, UByte);
@@ -73,7 +73,8 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
case NPY_UNICODE:
return (void *)PyUnicode_AS_DATA(scalar);
case NPY_VOID:
- return ((PyVoidScalarObject *)scalar)->obval;
+ /* Note: no & needed here, so can't use CASE */
+ return PyArrayScalar_VAL(scalar, Void);
}
/*
@@ -81,14 +82,13 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
* scalar it inherits from.
*/
-#define _CHK(cls) (PyObject_IsInstance(scalar, \
- (PyObject *)&Py##cls##ArrType_Type))
-#define _OBJ(lt) &(((Py##lt##ScalarObject *)scalar)->obval)
-#define _IFCASE(cls) if _CHK(cls) return _OBJ(cls)
+#define _CHK(cls) PyObject_IsInstance(scalar, \
+ (PyObject *)&Py##cls##ArrType_Type)
+#define _IFCASE(cls) if (_CHK(cls)) return &PyArrayScalar_VAL(scalar, cls)
- if _CHK(Number) {
- if _CHK(Integer) {
- if _CHK(SignedInteger) {
+ if (_CHK(Number)) {
+ if (_CHK(Integer)) {
+ if (_CHK(SignedInteger)) {
_IFCASE(Byte);
_IFCASE(Short);
_IFCASE(Int);
@@ -107,7 +107,7 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
}
else {
/* Inexact */
- if _CHK(Floating) {
+ if (_CHK(Floating)) {
_IFCASE(Half);
_IFCASE(Float);
_IFCASE(Double);
@@ -122,10 +122,10 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
}
}
else if (_CHK(Bool)) {
- return _OBJ(Bool);
+ return &PyArrayScalar_VAL(scalar, Bool);
}
else if (_CHK(Datetime)) {
- return _OBJ(Datetime);
+ return &PyArrayScalar_VAL(scalar, Datetime);
}
else if (_CHK(Flexible)) {
if (_CHK(String)) {
@@ -135,7 +135,8 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
return (void *)PyUnicode_AS_DATA(scalar);
}
if (_CHK(Void)) {
- return ((PyVoidScalarObject *)scalar)->obval;
+ /* Note: no & needed here, so can't use _IFCASE */
+ return PyArrayScalar_VAL(scalar, Void);
}
}
else {
@@ -156,7 +157,6 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
}
return (void *)memloc;
#undef _IFCASE
-#undef _OBJ
#undef _CHK
}
diff --git a/numpy/core/tests/test_mem_overlap.py b/numpy/core/tests/test_mem_overlap.py
index 7c1cff9b7..d3b58d8e8 100644
--- a/numpy/core/tests/test_mem_overlap.py
+++ b/numpy/core/tests/test_mem_overlap.py
@@ -42,9 +42,7 @@ def _indices_for_axis():
res = []
for nelems in (0, 2, 3):
ind = _indices_for_nelems(nelems)
-
- # no itertools.product available in Py2.4
- res.extend([(a, b) for a in ind for b in ind]) # all assignments of size "nelems"
+ res.extend(itertools.product(ind, ind)) # all assignments of size "nelems"
return res
@@ -53,18 +51,7 @@ def _indices(ndims):
"""Returns ((axis0_src, axis0_dst), (axis1_src, axis1_dst), ... ) index pairs."""
ind = _indices_for_axis()
-
- # no itertools.product available in Py2.4
-
- res = [[]]
- for i in range(ndims):
- newres = []
- for elem in ind:
- for others in res:
- newres.append([elem] + others)
- res = newres
-
- return res
+ return itertools.product(ind, repeat=ndims)
def _check_assignment(srcidx, dstidx):
diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py
index bae7a318a..feef80ce8 100644
--- a/numpy/core/tests/test_memmap.py
+++ b/numpy/core/tests/test_memmap.py
@@ -3,11 +3,11 @@ import os
import shutil
import mmap
import pytest
+from pathlib import Path
from tempfile import NamedTemporaryFile, TemporaryFile, mktemp, mkdtemp
from numpy import (
memmap, sum, average, product, ndarray, isscalar, add, subtract, multiply)
-from numpy.compat import Path
from numpy import arange, allclose, asarray
from numpy.testing import (
@@ -74,7 +74,6 @@ class TestMemmap:
del b
del fp
- @pytest.mark.skipif(Path is None, reason="No pathlib.Path")
def test_path(self):
tmpname = mktemp('', 'mmap', dir=self.tempdir)
fp = memmap(Path(tmpname), dtype=self.dtype, mode='w+',
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 270daad1e..16f4f0b80 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -1,9 +1,4 @@
-try:
- # Accessing collections abstract classes from collections
- # has been deprecated since Python 3.3
- import collections.abc as collections_abc
-except ImportError:
- import collections as collections_abc
+import collections.abc
import tempfile
import sys
import shutil
@@ -7756,7 +7751,7 @@ class TestHashing:
def test_collections_hashable(self):
x = np.array([])
- assert_(not isinstance(x, collections_abc.Hashable))
+ assert_(not isinstance(x, collections.abc.Hashable))
class TestArrayPriority:
diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py
index bf43fedcc..4350a3407 100644
--- a/numpy/core/tests/test_records.py
+++ b/numpy/core/tests/test_records.py
@@ -1,16 +1,10 @@
-import sys
-try:
- # Accessing collections abstract classes from collections
- # has been deprecated since Python 3.3
- import collections.abc as collections_abc
-except ImportError:
- import collections as collections_abc
+import collections.abc
import textwrap
from os import path
+from pathlib import Path
import pytest
import numpy as np
-from numpy.compat import Path
from numpy.testing import (
assert_, assert_equal, assert_array_equal, assert_array_almost_equal,
assert_raises, temppath,
@@ -252,7 +246,7 @@ class TestFromrecords:
assert_array_equal(ra['shape'], [['A', 'B', 'C']])
ra.field = 5
assert_array_equal(ra['field'], [[5, 5, 5]])
- assert_(isinstance(ra.field, collections_abc.Callable))
+ assert_(isinstance(ra.field, collections.abc.Callable))
def test_fromrecords_with_explicit_dtype(self):
a = np.rec.fromrecords([(1, 'a'), (2, 'bbb')],
@@ -319,7 +313,6 @@ class TestFromrecords:
assert_equal(rec['f1'], [b'', b'', b''])
-@pytest.mark.skipif(Path is None, reason="No pathlib.Path")
class TestPathUsage:
# Test that pathlib.Path can be used
def test_tofile_fromfile(self):
diff --git a/numpy/core/tests/test_scalarprint.py b/numpy/core/tests/test_scalarprint.py
index 225b8295f..3293d0426 100644
--- a/numpy/core/tests/test_scalarprint.py
+++ b/numpy/core/tests/test_scalarprint.py
@@ -82,10 +82,7 @@ class TestRealScalars:
orig_stdout, orig_stderr = sys.stdout, sys.stderr
sys.stdout, sys.stderr = fo, fe
- # py2 code.interact sends irrelevant internal DeprecationWarnings
- with suppress_warnings() as sup:
- sup.filter(DeprecationWarning)
- code.interact(local={'np': np}, readfunc=input_func, banner='')
+ code.interact(local={'np': np}, readfunc=input_func, banner='')
sys.stdout, sys.stderr = orig_stdout, orig_stderr
diff --git a/numpy/core/tests/test_umath_accuracy.py b/numpy/core/tests/test_umath_accuracy.py
index 677d9af60..32211974c 100644
--- a/numpy/core/tests/test_umath_accuracy.py
+++ b/numpy/core/tests/test_umath_accuracy.py
@@ -3,7 +3,7 @@ import platform
from os import path
import sys
import pytest
-from ctypes import *
+from ctypes import c_float, c_int, cast, pointer, POINTER
from numpy.testing import assert_array_max_ulp
runtest = sys.platform.startswith('linux') and (platform.machine() == 'x86_64')
diff --git a/numpy/core/umath.py b/numpy/core/umath.py
index f3b26ab72..c3cebb03f 100644
--- a/numpy/core/umath.py
+++ b/numpy/core/umath.py
@@ -7,8 +7,8 @@ by importing from the extension module.
"""
from . import _multiarray_umath
-from numpy.core._multiarray_umath import *
-from numpy.core._multiarray_umath import (
+from ._multiarray_umath import * # noqa: F403
+from ._multiarray_umath import (
_UFUNC_API, _add_newdoc_ufunc, _ones_like
)