Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and mtsokol committed Jan 8, 2024
1 parent a1a6aee commit f45a2b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
25 changes: 19 additions & 6 deletions sparse/_coo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,7 @@ def clip(a, a_min=None, a_max=None, out=None):

# Array API set functions


class UniqueCountsResult(NamedTuple):
values: np.ndarray
counts: np.ndarray
Expand Down Expand Up @@ -1097,8 +1098,12 @@ def unique_counts(x, /):
"""
from .core import COO

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
sparse._coo.core
begins an import cycle.

if not isinstance(x, COO):
raise ValueError(f"Only COO arrays are supported but {type(x)} was passed.")
if isinstance(x, scipy.sparse.spmatrix):
x = COO.from_scipy_sparse(x)

Check warning on line 1102 in sparse/_coo/common.py

View check run for this annotation

Codecov / codecov/patch

sparse/_coo/common.py#L1102

Added line #L1102 was not covered by tests
elif not isinstance(x, SparseArray):
raise ValueError(f"Input must be an instance of SparseArray, but it's {type(x)}.")
elif not isinstance(x, COO):
x = x.asformat(COO)

Check warning on line 1106 in sparse/_coo/common.py

View check run for this annotation

Codecov / codecov/patch

sparse/_coo/common.py#L1106

Added line #L1106 was not covered by tests

x = x.flatten()
values, counts = np.unique(x.data, return_counts=True)
Expand Down Expand Up @@ -1140,8 +1145,12 @@ def unique_values(x, /):
"""
from .core import COO

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
sparse._coo.core
begins an import cycle.

if not isinstance(x, COO):
raise ValueError(f"Only COO arrays are supported but {type(x)} was passed.")
if isinstance(x, scipy.sparse.spmatrix):
x = COO.from_scipy_sparse(x)

Check warning on line 1149 in sparse/_coo/common.py

View check run for this annotation

Codecov / codecov/patch

sparse/_coo/common.py#L1149

Added line #L1149 was not covered by tests
elif not isinstance(x, SparseArray):
raise ValueError(f"Input must be an instance of SparseArray, but it's {type(x)}.")
elif not isinstance(x, COO):
x = x.asformat(COO)

Check warning on line 1153 in sparse/_coo/common.py

View check run for this annotation

Codecov / codecov/patch

sparse/_coo/common.py#L1153

Added line #L1153 was not covered by tests

x = x.flatten()
values = np.unique(x.data)
Expand Down Expand Up @@ -1212,8 +1221,12 @@ def _arg_minmax_common(

from .core import COO

if not isinstance(x, COO):
raise ValueError(f"Only COO arrays are supported but {type(x)} was passed.")
if isinstance(x, scipy.sparse.spmatrix):
x = COO.from_scipy_sparse(x)

Check warning on line 1225 in sparse/_coo/common.py

View check run for this annotation

Codecov / codecov/patch

sparse/_coo/common.py#L1225

Added line #L1225 was not covered by tests
elif not isinstance(x, SparseArray):
raise ValueError(f"Input must be an instance of SparseArray, but it's {type(x)}.")

Check warning on line 1227 in sparse/_coo/common.py

View check run for this annotation

Codecov / codecov/patch

sparse/_coo/common.py#L1227

Added line #L1227 was not covered by tests
elif not isinstance(x, COO):
x = x.asformat(COO)

Check warning on line 1229 in sparse/_coo/common.py

View check run for this annotation

Codecov / codecov/patch

sparse/_coo/common.py#L1229

Added line #L1229 was not covered by tests

if not isinstance(axis, (int, type(None))):
raise ValueError(f"`axis` must be `int` or `None`, but it's: {type(axis)}.")
Expand Down
6 changes: 2 additions & 4 deletions sparse/tests/test_coo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1773,9 +1773,7 @@ def test_unique_values(self, arr, fill_value):

np.testing.assert_equal(result, expected)

@pytest.mark.parametrize(
"func", [sparse.unique_counts, sparse.unique_values]
)
@pytest.mark.parametrize("func", [sparse.unique_counts, sparse.unique_values])
def test_input_validation(self, func):
with pytest.raises(ValueError, match=r"Only COO arrays are supported"):
with pytest.raises(ValueError, match=r"Input must be an instance of SparseArray"):
func(self.arr)

0 comments on commit f45a2b0

Please sign in to comment.