Skip to content

Commit 26383d1

Browse files
authored
Add k type check to triu_indices (#2855)
The PR adds explicit type check to `k` keyword in `dpnp.triu_indices` function.
1 parent 3007bee commit 26383d1

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum
6161
* `dpnp` uses pybind11 3.0.3 [#2834](https://github.com/IntelPython/dpnp/pull/2834)
6262
* Disabled `dpnp.tensor` tests by default in `conda build --test` to prevent OOM failures during package testing. Set `SKIP_TENSOR_TESTS=0` to re-enable them on systems with enough memory [#2860](https://github.com/IntelPython/dpnp/pull/2860)
6363
* `dpnp` uses pybind11 3.0.4 [#2865](https://github.com/IntelPython/dpnp/pull/2865)
64+
* Added explicit type check of `k` keyword in `dpnp.triu_indices` [#2855](https://github.com/IntelPython/dpnp/pull/2855)
6465

6566
### Deprecated
6667

dpnp/dpnp_iface_arraycreation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3680,8 +3680,7 @@ def tri(
36803680
try:
36813681
_k = operator.index(k)
36823682
except TypeError:
3683-
pass
3684-
if _k is None:
3683+
# pylint: disable=raise-missing-from
36853684
raise TypeError(f"`k` must be a integer data type, but got {type(k)}")
36863685

36873686
sycl_dev = dpnp.get_normalized_queue_device(

dpnp/dpnp_iface_indexing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,6 +2623,12 @@ def triu_indices(
26232623
26242624
"""
26252625

2626+
try:
2627+
k = operator.index(k)
2628+
except TypeError:
2629+
# pylint: disable=raise-missing-from
2630+
raise TypeError(f"`k` must be a integer data type, but got {type(k)}")
2631+
26262632
tri_ = ~dpnp.tri(
26272633
n,
26282634
m,

dpnp/tests/test_indexing.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,15 @@ def test_triu_indices(n, k, m):
11721172
assert_array_equal(expected, result)
11731173

11741174

1175+
@testing.with_requires("numpy>=2.3.0")
1176+
@pytest.mark.parametrize("k", [3.2, dpnp.bool(0), numpy.array(3.14)])
1177+
def test_triu_indices_error(k):
1178+
with pytest.raises(
1179+
TypeError, match="`k` must be a integer data type, but got"
1180+
):
1181+
dpnp.triu_indices(n=4, k=k)
1182+
1183+
11751184
@pytest.mark.parametrize("k", [-3, -2, -1, 0, 1, 2, 3])
11761185
@pytest.mark.parametrize(
11771186
"array",

0 commit comments

Comments
 (0)