Skip to content

Commit 0b4135d

Browse files
committed
cover all cases
1 parent 5cc1140 commit 0b4135d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/array_api_extra/_lib/_utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def in1d(
4242
mask |= x1 == a
4343
return mask
4444

45+
rev_idx = xp.empty(0) # placeholder
4546
if not assume_unique:
4647
x1, rev_idx = xp.unique_inverse(x1)
4748
x2 = xp.unique_values(x2)
@@ -61,7 +62,4 @@ def in1d(
6162

6263
if assume_unique:
6364
return ret[: x1.shape[0]]
64-
# https://github.com/KotlinIsland/basedmypy/issues/826
65-
# https://github.com/pylint-dev/pylint/issues/10095
66-
# pylint: disable=possibly-used-before-assignment
67-
return xp.take(ret, rev_idx, axis=0) # type: ignore[possibly-undefined] # pyright: ignore[reportPossiblyUnboundVariable]
65+
return xp.take(ret, rev_idx, axis=0)

tests/test_utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
from __future__ import annotations # https://github.com/pylint-dev/pylint/pull/9990
22

3+
import typing
4+
35
# data-apis/array-api-strict#6
46
import array_api_strict as xp # type: ignore[import-untyped] # pyright: ignore[reportMissingTypeStubs]
7+
import pytest
58
from numpy.testing import assert_array_equal
69

710
from array_api_extra._lib._utils import in1d
811

12+
if typing.TYPE_CHECKING:
13+
from array_api_extra._lib._typing import Array
14+
915

1016
# some test coverage already provided by TestSetDiff1D
1117
class TestIn1D:
12-
def test_no_invert_assume_unique(self):
18+
# cover both code paths
19+
@pytest.mark.parametrize("x2", [xp.arange(9), xp.arange(15)])
20+
def test_no_invert_assume_unique(self, x2: Array):
1321
x1 = xp.asarray([3, 8, 20])
14-
x2 = xp.arange(15)
1522
expected = xp.asarray([True, True, False])
1623
actual = in1d(x1, x2, xp=xp)
1724
assert_array_equal(actual, expected)

0 commit comments

Comments
 (0)