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

Maintance fixes. #462

Merged
merged 2 commits into from
Apr 21, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sparse/_compressed/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def getitem(x, key):
return get_single_element(x, key)

shape = []
compressed_inds = np.zeros(len(x.shape), dtype=np.bool)
uncompressed_inds = np.zeros(len(x.shape), dtype=np.bool)
compressed_inds = np.zeros(len(x.shape), dtype=np.bool_)
uncompressed_inds = np.zeros(len(x.shape), dtype=np.bool_)

# which axes will be compressed in the resulting array
shape_key = np.zeros(len(x.shape), dtype=np.intp)
Expand Down
2 changes: 1 addition & 1 deletion sparse/_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def _get_func_coords_data(self, mask):
func_coords, func_data, self.shape, has_duplicates=False, sorted=True
)

unmatched_mask = np.ones(func_array.nnz, dtype=np.bool)
unmatched_mask = np.ones(func_array.nnz, dtype=np.bool_)

for arg in unmatched_args:
matched_idx = self._match_coo(func_array, arg, return_midx=True)[0]
Expand Down
8 changes: 4 additions & 4 deletions sparse/tests/test_coo.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,8 @@ def test_two_random_same_seed():
"rvs, dtype",
[
(None, np.float64),
(scipy.stats.poisson(25, loc=10).rvs, np.int),
(lambda x: np.random.choice([True, False], size=x), np.bool),
(scipy.stats.poisson(25, loc=10).rvs, np.int_),
(lambda x: np.random.choice([True, False], size=x), np.bool_),
],
)
@pytest.mark.parametrize("shape", [(2, 4, 5), (20, 40, 50)])
Expand Down Expand Up @@ -1016,7 +1016,7 @@ def test_np_array():
],
)
def test_three_arg_where(shapes):
cs = sparse.random(shapes[0], density=0.5).astype(np.bool)
cs = sparse.random(shapes[0], density=0.5).astype(np.bool_)
xs = sparse.random(shapes[1], density=0.5)
ys = sparse.random(shapes[2], density=0.5)

Expand Down Expand Up @@ -1052,7 +1052,7 @@ def test_one_arg_where_dense():


def test_two_arg_where():
cs = sparse.random((2, 3, 4), density=0.5).astype(np.bool)
cs = sparse.random((2, 3, 4), density=0.5).astype(np.bool_)
xs = sparse.random((2, 3, 4), density=0.5)

with pytest.raises(ValueError):
Expand Down
85 changes: 51 additions & 34 deletions sparse/tests/test_dok.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,76 +130,93 @@ def test_getitem_index_error(shape, density, indices):


@pytest.mark.parametrize(
"shape, index, value",
"shape, index, value_shape",
[
((2,), slice(None), np.random.rand()),
((2,), slice(1, 2), np.random.rand()),
((2,), slice(0, 2), np.random.rand(2)),
((2,), 1, np.random.rand()),
((2, 3), (0, slice(None)), np.random.rand()),
((2, 3), (0, slice(1, 3)), np.random.rand()),
((2, 3), (1, slice(None)), np.random.rand(3)),
((2, 3), (0, slice(1, 3)), np.random.rand(2)),
((2, 3), (0, slice(2, 0, -1)), np.random.rand(2)),
((2, 3), (slice(None), 1), np.random.rand()),
((2, 3), (slice(None), 1), np.random.rand(2)),
((2, 3), (slice(1, 2), 1), np.random.rand()),
((2, 3), (slice(1, 2), 1), np.random.rand(1)),
((2, 3), (0, 2), np.random.rand()),
((2, 3), ([0, 1], [1, 2]), np.random.rand(2)),
((2, 3), ([0, 1], [1, 2]), np.random.rand()),
((4,), ([1, 3]), np.random.rand()),
((2, 3), ([0, 1], [1, 2]), 0),
((2,), slice(None), ()),
((2,), slice(1, 2), ()),
((2,), slice(0, 2), (2,)),
((2,), 1, ()),
((2, 3), (0, slice(None)), ()),
((2, 3), (0, slice(1, 3)), ()),
((2, 3), (1, slice(None)), (3,)),
((2, 3), (0, slice(1, 3)), (2,)),
((2, 3), (0, slice(2, 0, -1)), (2,)),
((2, 3), (slice(None), 1), ()),
((2, 3), (slice(None), 1), (2,)),
((2, 3), (slice(1, 2), 1), ()),
((2, 3), (slice(1, 2), 1), (1,)),
((2, 3), (0, 2), ()),
((2, 3), ([0, 1], [1, 2]), (2,)),
((2, 3), ([0, 1], [1, 2]), ()),
((4,), ([1, 3]), ()),
],
)
def test_setitem(shape, index, value):
def test_setitem(shape, index, value_shape):
s = sparse.random(shape, 0.5, format="dok")
x = s.todense()

value = np.random.rand(*value_shape)

s[index] = value
x[index] = value

assert_eq(x, s)


def test_setitem_delete():
shape = (2, 3)
index = [0, 1], [1, 2]
value = 0
s = sparse.random(shape, 1.0, format="dok")
x = s.todense()

s[index] = value
x[index] = value

assert_eq(x, s)
assert s.nnz < s.size


@pytest.mark.parametrize(
"shape, index, value",
"shape, index, value_shape",
[
((2, 3), ([0, 1.5], [1, 2]), np.random.rand()),
((2, 3), ([0, 1], [1]), np.random.rand()),
((2, 3), ([[0], [1]], [1, 2]), np.random.rand()),
((2, 3), ([0, 1.5], [1, 2]), ()),
((2, 3), ([0, 1], [1]), ()),
((2, 3), ([[0], [1]], [1, 2]), ()),
],
)
def test_setitem_index_error(shape, index, value):
def test_setitem_index_error(shape, index, value_shape):
s = sparse.random(shape, 0.5, format="dok")
value = np.random.rand(*value_shape)

with pytest.raises(IndexError):
s[index] = value


@pytest.mark.parametrize(
"shape, index, value",
"shape, index, value_shape",
[
((2, 3), ([0, 1],), np.random.rand()),
((2, 3), ([0, 1],), ()),
],
)
def test_setitem_notimplemented_error(shape, index, value):
def test_setitem_notimplemented_error(shape, index, value_shape):
s = sparse.random(shape, 0.5, format="dok")

value = np.random.rand(*value_shape)
with pytest.raises(NotImplementedError):
s[index] = value


@pytest.mark.parametrize(
"shape, index, value",
"shape, index, value_shape",
[
((2, 3), ([0, 1], [1, 2]), np.random.rand(1, 2)),
((2, 3), ([0, 1], [1, 2]), np.random.rand(3)),
((2,), 1, np.random.rand(2)),
((2, 3), ([0, 1], [1, 2]), (1, 2)),
((2, 3), ([0, 1], [1, 2]), (3,)),
((2,), 1, (2,)),
],
)
def test_setitem_value_error(shape, index, value):
def test_setitem_value_error(shape, index, value_shape):
s = sparse.random(shape, 0.5, format="dok")
value = np.random.rand(*value_shape)

with pytest.raises(ValueError):
s[index] = value
Expand Down