Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Handle numpy's deprecation of accepting out-of-bound integers. #17209

Merged
merged 1 commit into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions scipy/sparse/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,8 @@ def test_numpy_sum(self):
def test_mean(self):
def check(dtype):
dat = array([[0, 1, 2],
[3, -4, 5],
[-6, 7, 9]], dtype=dtype)
[3, 4, 5],
[6, 7, 9]], dtype=dtype)
datsp = self.spmatrix(dat, dtype=dtype)

assert_array_almost_equal(dat.mean(), datsp.mean())
Expand Down
13 changes: 10 additions & 3 deletions scipy/sparse/tests/test_sparsetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
from pytest import raises as assert_raises


def int_to_int8(n):
"""
Wrap an integer to the interval [-128, 127].
"""
return (n + 128) % 256 - 128


def test_exception():
assert_raises(MemoryError, _sparsetools.test_throw_error)

Expand Down Expand Up @@ -157,7 +164,7 @@ def test_dia_matvec(self):
m = dia_matrix((data, offsets), shape=(n, n))
v = np.ones(m.shape[1], dtype=np.int8)
r = m.dot(v)
assert_equal(r[0], np.int8(n))
assert_equal(r[0], int_to_int8(n))
del data, offsets, m, v, r
gc.collect()

Expand Down Expand Up @@ -219,15 +226,15 @@ def _check_bsr_matvecs(self, m):

# _matvecs
r = m.dot(np.ones((n, 2), dtype=np.int8))
assert_equal(r[0,0], np.int8(n))
assert_equal(r[0, 0], int_to_int8(n))

def _check_bsr_matvec(self, m):
m = m()
n = self.n

# _matvec
r = m.dot(np.ones((n,), dtype=np.int8))
assert_equal(r[0], np.int8(n))
assert_equal(r[0], int_to_int8(n))

def _check_bsr_diagonal(self, m):
m = m()
Expand Down
7 changes: 4 additions & 3 deletions scipy/spatial/tests/test_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1996,11 +1996,12 @@ def test_sqeuclidean_dtypes():
assert_(np.issubdtype(d.dtype, np.floating))

for dtype in [np.uint8, np.uint16, np.uint32, np.uint64]:
d1 = wsqeuclidean([0], np.asarray([-1], dtype=dtype))
d2 = wsqeuclidean(np.asarray([-1], dtype=dtype), [0])
umax = np.iinfo(dtype).max
d1 = wsqeuclidean([0], np.asarray([umax], dtype=dtype))
d2 = wsqeuclidean(np.asarray([umax], dtype=dtype), [0])

assert_equal(d1, d2)
assert_equal(d1, np.float64(np.iinfo(dtype).max)**2)
assert_equal(d1, np.float64(umax)**2)

dtypes = [np.float32, np.float64, np.complex64, np.complex128]
for dtype in ['float16', 'float128']:
Expand Down