summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/_internal.py3
-rw-r--r--numpy/core/defchararray.py18
-rw-r--r--numpy/core/memmap.py4
-rw-r--r--numpy/core/numerictypes.py5
-rw-r--r--numpy/core/records.py8
-rw-r--r--numpy/core/tests/test_arrayprint.py4
-rw-r--r--numpy/core/tests/test_mem_overlap.py2
-rw-r--r--numpy/core/tests/test_multiarray.py16
-rw-r--r--numpy/core/tests/test_regression.py6
-rw-r--r--numpy/core/tests/test_shape_base.py2
-rw-r--r--numpy/core/tests/test_unicode.py4
11 files changed, 30 insertions, 42 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index f21774cb6..1378497bb 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -9,7 +9,6 @@ import re
import sys
import platform
-from numpy.compat import unicode
from .multiarray import dtype, array, ndarray
try:
import ctypes
@@ -365,7 +364,7 @@ def _newnames(datatype, order):
"""
oldnames = datatype.names
nameslist = list(oldnames)
- if isinstance(order, (str, unicode)):
+ if isinstance(order, str):
order = [order]
seen = set()
if isinstance(order, (list, tuple)):
diff --git a/numpy/core/defchararray.py b/numpy/core/defchararray.py
index 1292b738c..cd01c0e77 100644
--- a/numpy/core/defchararray.py
+++ b/numpy/core/defchararray.py
@@ -24,7 +24,7 @@ from .numeric import array as narray
from numpy.core.multiarray import _vec_string
from numpy.core.overrides import set_module
from numpy.core import overrides
-from numpy.compat import asbytes, long
+from numpy.compat import asbytes
import numpy
__all__ = [
@@ -340,7 +340,7 @@ def multiply(a, i):
i_arr = numpy.asarray(i)
if not issubclass(i_arr.dtype.type, integer):
raise ValueError("Can only multiply by integers")
- out_size = _get_num_chars(a_arr) * max(long(i_arr.max()), 0)
+ out_size = _get_num_chars(a_arr) * max(int(i_arr.max()), 0)
return _vec_string(
a_arr, (a_arr.dtype.type, out_size), '__mul__', (i_arr,))
@@ -450,7 +450,7 @@ def center(a, width, fillchar=' '):
"""
a_arr = numpy.asarray(a)
width_arr = numpy.asarray(width)
- size = long(numpy.max(width_arr.flat))
+ size = int(numpy.max(width_arr.flat))
if numpy.issubdtype(a_arr.dtype, numpy.string_):
fillchar = asbytes(fillchar)
return _vec_string(
@@ -995,7 +995,7 @@ def ljust(a, width, fillchar=' '):
"""
a_arr = numpy.asarray(a)
width_arr = numpy.asarray(width)
- size = long(numpy.max(width_arr.flat))
+ size = int(numpy.max(width_arr.flat))
if numpy.issubdtype(a_arr.dtype, numpy.string_):
fillchar = asbytes(fillchar)
return _vec_string(
@@ -1265,7 +1265,7 @@ def rjust(a, width, fillchar=' '):
"""
a_arr = numpy.asarray(a)
width_arr = numpy.asarray(width)
- size = long(numpy.max(width_arr.flat))
+ size = int(numpy.max(width_arr.flat))
if numpy.issubdtype(a_arr.dtype, numpy.string_):
fillchar = asbytes(fillchar)
return _vec_string(
@@ -1733,7 +1733,7 @@ def zfill(a, width):
"""
a_arr = numpy.asarray(a)
width_arr = numpy.asarray(width)
- size = long(numpy.max(width_arr.flat))
+ size = int(numpy.max(width_arr.flat))
return _vec_string(
a_arr, (a_arr.dtype.type, size), 'zfill', (width_arr,))
@@ -1952,10 +1952,10 @@ class chararray(ndarray):
else:
dtype = string_
- # force itemsize to be a Python long, since using NumPy integer
+ # force itemsize to be a Python int, since using NumPy integer
# types results in itemsize.itemsize being used as the size of
# strings in the new array.
- itemsize = long(itemsize)
+ itemsize = int(itemsize)
if isinstance(buffer, str):
# unicode objects do not have the buffer interface
@@ -2720,7 +2720,7 @@ def array(obj, itemsize=None, copy=True, unicode=None, order=None):
(itemsize != obj.itemsize) or
(not unicode and isinstance(obj, unicode_)) or
(unicode and isinstance(obj, string_))):
- obj = obj.astype((dtype, long(itemsize)))
+ obj = obj.astype((dtype, int(itemsize)))
return obj
if isinstance(obj, ndarray) and issubclass(obj.dtype.type, object):
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py
index 61b8ba3ac..ad66446c2 100644
--- a/numpy/core/memmap.py
+++ b/numpy/core/memmap.py
@@ -1,7 +1,7 @@
import numpy as np
from .numeric import uint8, ndarray, dtype
from numpy.compat import (
- long, os_fspath, contextlib_nullcontext, is_pathlib_path
+ os_fspath, contextlib_nullcontext, is_pathlib_path
)
from numpy.core.overrides import set_module
@@ -242,7 +242,7 @@ class memmap(ndarray):
for k in shape:
size *= k
- bytes = long(offset + size*_dbytes)
+ bytes = int(offset + size*_dbytes)
if mode in ('w+', 'r+') and flen < bytes:
fid.seek(bytes - 1, 0)
diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py
index 9d7bbde93..aac741612 100644
--- a/numpy/core/numerictypes.py
+++ b/numpy/core/numerictypes.py
@@ -83,7 +83,6 @@ import types as _types
import numbers
import warnings
-from numpy.compat import bytes, long
from numpy.core.multiarray import (
typeinfo, ndarray, array, empty, dtype, datetime_data,
datetime_as_string, busday_offset, busday_count, is_busday,
@@ -119,8 +118,8 @@ from ._dtype import _kind_name
# we don't export these for import *, but we do want them accessible
# as numerictypes.bool, etc.
-from builtins import bool, int, float, complex, object, str
-unicode = str
+from builtins import bool, int, float, complex, object, str, bytes
+from numpy.compat import long, unicode
# We use this later
diff --git a/numpy/core/records.py b/numpy/core/records.py
index ddefa5881..b1ee1aa11 100644
--- a/numpy/core/records.py
+++ b/numpy/core/records.py
@@ -40,7 +40,7 @@ from collections import Counter, OrderedDict
from . import numeric as sb
from . import numerictypes as nt
from numpy.compat import (
- isfileobj, bytes, long, unicode, os_fspath, contextlib_nullcontext
+ isfileobj, os_fspath, contextlib_nullcontext
)
from numpy.core.overrides import set_module
from .arrayprint import get_printoptions
@@ -188,7 +188,7 @@ class format_parser:
if names:
if type(names) in [list, tuple]:
pass
- elif isinstance(names, (str, unicode)):
+ elif isinstance(names, str):
names = names.split(',')
else:
raise NameError("illegal input names %s" % repr(names))
@@ -703,7 +703,7 @@ def fromrecords(recList, dtype=None, shape=None, formats=None, names=None,
shape = _deprecate_shape_0_as_None(shape)
if shape is None:
shape = len(recList)
- if isinstance(shape, (int, long)):
+ if isinstance(shape, int):
shape = (shape,)
if len(shape) > 1:
raise ValueError("Can only deal with 1-d array.")
@@ -792,7 +792,7 @@ def fromfile(fd, dtype=None, shape=None, offset=0, formats=None,
if shape is None:
shape = (-1,)
- elif isinstance(shape, (int, long)):
+ elif isinstance(shape, int):
shape = (shape,)
if isfileobj(fd):
diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py
index 008ca20e6..e29217461 100644
--- a/numpy/core/tests/test_arrayprint.py
+++ b/numpy/core/tests/test_arrayprint.py
@@ -475,9 +475,7 @@ class TestPrintOptions:
assert_equal(repr(x), "array([0., 1., 2.])")
def test_0d_arrays(self):
- unicode = type(u'')
-
- assert_equal(unicode(np.array(u'café', '<U4')), u'café')
+ assert_equal(str(np.array(u'café', '<U4')), u'café')
assert_equal(repr(np.array('café', '<U4')),
"array('café', dtype='<U4')")
diff --git a/numpy/core/tests/test_mem_overlap.py b/numpy/core/tests/test_mem_overlap.py
index 44ebf1cd2..675613de4 100644
--- a/numpy/core/tests/test_mem_overlap.py
+++ b/numpy/core/tests/test_mem_overlap.py
@@ -5,7 +5,6 @@ import numpy as np
from numpy.core._multiarray_tests import solve_diophantine, internal_overlap
from numpy.core import _umath_tests
from numpy.lib.stride_tricks import as_strided
-from numpy.compat import long
from numpy.testing import (
assert_, assert_raises, assert_equal, assert_array_equal
)
@@ -387,7 +386,6 @@ def test_shares_memory_api():
assert_equal(np.shares_memory(a, b), True)
assert_equal(np.shares_memory(a, b, max_work=None), True)
assert_raises(np.TooHardError, np.shares_memory, a, b, max_work=1)
- assert_raises(np.TooHardError, np.shares_memory, a, b, max_work=long(1))
def test_may_share_memory_bad_max_work():
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 7b3397795..1637f6651 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -21,7 +21,7 @@ import builtins
from decimal import Decimal
import numpy as np
-from numpy.compat import strchar, unicode
+from numpy.compat import strchar
import numpy.core._multiarray_tests as _multiarray_tests
from numpy.testing import (
assert_, assert_raises, assert_warns, assert_equal, assert_almost_equal,
@@ -1457,12 +1457,12 @@ class TestZeroSizeFlexible:
assert_equal(zs.itemsize, 0)
zs = self._zeros(10, np.void)
assert_equal(zs.itemsize, 0)
- zs = self._zeros(10, unicode)
+ zs = self._zeros(10, str)
assert_equal(zs.itemsize, 0)
def _test_sort_partition(self, name, kinds, **kwargs):
# Previously, these would all hang
- for dt in [bytes, np.void, unicode]:
+ for dt in [bytes, np.void, str]:
zs = self._zeros(10, dt)
sort_method = getattr(zs, name)
sort_func = getattr(np, name)
@@ -1484,13 +1484,13 @@ class TestZeroSizeFlexible:
def test_resize(self):
# previously an error
- for dt in [bytes, np.void, unicode]:
+ for dt in [bytes, np.void, str]:
zs = self._zeros(10, dt)
zs.resize(25)
zs.resize((10, 10))
def test_view(self):
- for dt in [bytes, np.void, unicode]:
+ for dt in [bytes, np.void, str]:
zs = self._zeros(10, dt)
# viewing as itself should be allowed
@@ -1505,7 +1505,7 @@ class TestZeroSizeFlexible:
def test_pickle(self):
for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
- for dt in [bytes, np.void, unicode]:
+ for dt in [bytes, np.void, str]:
zs = self._zeros(10, dt)
p = pickle.dumps(zs, protocol=proto)
zs2 = pickle.loads(p)
@@ -4449,7 +4449,7 @@ class TestPutmask:
assert_equal(x[mask], np.array(val, T))
def test_ip_types(self):
- unchecked_types = [bytes, unicode, np.void]
+ unchecked_types = [bytes, str, np.void]
x = np.random.random(1000)*100
mask = x < 40
@@ -4503,7 +4503,7 @@ class TestTake:
assert_array_equal(x.take(ind, axis=0), x)
def test_ip_types(self):
- unchecked_types = [bytes, unicode, np.void]
+ unchecked_types = [bytes, str, np.void]
x = np.random.random(24)*100
x.shape = 2, 3, 4
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 18d5b6032..4d7639e43 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -15,7 +15,7 @@ from numpy.testing import (
_assert_valid_refcount, HAS_REFCOUNT,
)
from numpy.testing._private.utils import _no_tracing
-from numpy.compat import asbytes, asunicode, long, pickle
+from numpy.compat import asbytes, asunicode, pickle
try:
RecursionError
@@ -1504,7 +1504,7 @@ class TestRegression:
min //= -1
with np.errstate(divide="ignore"):
- for t in (np.int8, np.int16, np.int32, np.int64, int, np.compat.long):
+ for t in (np.int8, np.int16, np.int32, np.int64, int):
test_type(t)
def test_buffer_hashlib(self):
@@ -1803,7 +1803,6 @@ class TestRegression:
a = np.array(0, dtype=object)
a[()] = a
assert_raises(RecursionError, int, a)
- assert_raises(RecursionError, long, a)
assert_raises(RecursionError, float, a)
a[()] = None
@@ -1829,7 +1828,6 @@ class TestRegression:
b = np.array(0, dtype=object)
a[()] = b
assert_equal(int(a), int(0))
- assert_equal(long(a), long(0))
assert_equal(float(a), float(0))
def test_object_array_self_copy(self):
diff --git a/numpy/core/tests/test_shape_base.py b/numpy/core/tests/test_shape_base.py
index 738260327..546ecf001 100644
--- a/numpy/core/tests/test_shape_base.py
+++ b/numpy/core/tests/test_shape_base.py
@@ -11,7 +11,6 @@ from numpy.testing import (
assert_raises_regex, assert_warns
)
-from numpy.compat import long
class TestAtleast1d:
def test_0D_array(self):
@@ -49,7 +48,6 @@ class TestAtleast1d:
"""
assert_(atleast_1d(3).shape == (1,))
assert_(atleast_1d(3j).shape == (1,))
- assert_(atleast_1d(long(3)).shape == (1,))
assert_(atleast_1d(3.0).shape == (1,))
assert_(atleast_1d([[2, 3], [4, 5]]).shape == (2, 2))
diff --git a/numpy/core/tests/test_unicode.py b/numpy/core/tests/test_unicode.py
index ac065d5d6..8e0dd47cb 100644
--- a/numpy/core/tests/test_unicode.py
+++ b/numpy/core/tests/test_unicode.py
@@ -1,10 +1,8 @@
import numpy as np
-from numpy.compat import unicode
from numpy.testing import assert_, assert_equal, assert_array_equal
def buffer_length(arr):
- if isinstance(arr, unicode):
- arr = str(arr)
+ if isinstance(arr, str):
if not arr:
charmax = 0
else: