Skip to content

Commit bcfc5dd

Browse files
authored
NumPy 2.0 support. (#625)
1 parent f2d8f1d commit bcfc5dd

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

sparse/_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def random_value_array(value, fraction):
358358
def replace_values(n):
359359
i = int(n * fraction)
360360

361-
ar = np.empty((n,), dtype=np.float_)
361+
ar = np.empty((n,), dtype=np.float64)
362362
ar[:i] = value
363363
ar[i:] = default_rng.random(n - i)
364364
return ar
@@ -465,7 +465,7 @@ def html_table(arr):
465465
table = ["<table><tbody>"]
466466
headings = ["Format", "Data Type", "Shape", "nnz", "Density", "Read-only"]
467467

468-
density = np.float_(arr.nnz) / np.float_(arr.size)
468+
density = np.float64(arr.nnz) / np.float64(arr.size)
469469

470470
info = [
471471
type(arr).__name__.lower(),
@@ -482,7 +482,9 @@ def html_table(arr):
482482
headings.append("Size")
483483
info.append(human_readable_size(arr.nbytes))
484484
headings.append("Storage ratio")
485-
info.append(f"{np.float_(arr.nbytes) / np.float_(reduce(operator.mul, arr.shape, 1) * arr.dtype.itemsize):.2f}")
485+
info.append(
486+
f"{np.float64(arr.nbytes) / np.float64(reduce(operator.mul, arr.shape, 1) * arr.dtype.itemsize):.2f}"
487+
)
486488

487489
# compressed_axes
488490
if type(arr).__name__ == "GCXS":

sparse/tests/test_coo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def test_advanced_indexing(index):
550550

551551

552552
def test_custom_dtype_slicing():
553-
dt = np.dtype([("part1", np.float_), ("part2", np.int64, (2,)), ("part3", np.int64, (2, 2))])
553+
dt = np.dtype([("part1", np.float64), ("part2", np.int64, (2,)), ("part3", np.int64, (2, 2))])
554554

555555
x = np.zeros((2, 3, 4), dtype=dt)
556556
x[1, 1, 1] = (0.64, [4, 2], [[1, 2], [3, 0]])
@@ -800,7 +800,7 @@ def test_cache_csr():
800800
def test_empty_shape():
801801
x = COO(np.empty((0, 1), dtype=np.int8), [1.0])
802802
assert x.shape == ()
803-
assert_eq(2 * x, np.float_(2.0))
803+
assert_eq(2 * x, np.float64(2.0))
804804

805805

806806
def test_single_dimension():
@@ -876,7 +876,7 @@ def test_triul(shape, k):
876876

877877

878878
def test_empty_reduction():
879-
x = np.zeros((2, 3, 4), dtype=np.float_)
879+
x = np.zeros((2, 3, 4), dtype=np.float64)
880880
xs = COO.from_numpy(x)
881881

882882
assert_eq(x.sum(axis=(0, 2)), xs.sum(axis=(0, 2)))

sparse/tests/test_elemwise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def test_ndarray_densification_fails(rng):
378378

379379
def test_elemwise_noargs():
380380
def func():
381-
return np.float_(5.0)
381+
return np.float64(5.0)
382382

383383
with pytest.raises(ValueError, match=r"None of the args is sparse:"):
384384
sparse.elemwise(func)

0 commit comments

Comments
 (0)