From a9eed13531982099e56c8a682973864aceb2bc28 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 15 Apr 2026 15:52:56 +0200 Subject: [PATCH 1/3] Add strict type check for k keyword --- dpnp/dpnp_iface_arraycreation.py | 3 +-- dpnp/dpnp_iface_indexing.py | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dpnp/dpnp_iface_arraycreation.py b/dpnp/dpnp_iface_arraycreation.py index 5bcf5ea19b82..d0607990398a 100644 --- a/dpnp/dpnp_iface_arraycreation.py +++ b/dpnp/dpnp_iface_arraycreation.py @@ -3680,8 +3680,7 @@ def tri( try: _k = operator.index(k) except TypeError: - pass - if _k is None: + # pylint: disable=raise-missing-from raise TypeError(f"`k` must be a integer data type, but got {type(k)}") sycl_dev = dpnp.get_normalized_queue_device( diff --git a/dpnp/dpnp_iface_indexing.py b/dpnp/dpnp_iface_indexing.py index 2a90f6cff637..9264ff1750ff 100644 --- a/dpnp/dpnp_iface_indexing.py +++ b/dpnp/dpnp_iface_indexing.py @@ -2621,6 +2621,12 @@ def triu_indices( """ + try: + k = operator.index(k) + except TypeError: + # pylint: disable=raise-missing-from + raise TypeError(f"`k` must be a integer data type, but got {type(k)}") + tri_ = ~dpnp.tri( n, m, From 3462bfbab9334e2ba56d44a1bdc314e4438c5db9 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 15 Apr 2026 15:53:56 +0200 Subject: [PATCH 2/3] Add test coverage --- dpnp/tests/test_indexing.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dpnp/tests/test_indexing.py b/dpnp/tests/test_indexing.py index 27f34f6288b3..4287ec6d02bd 100644 --- a/dpnp/tests/test_indexing.py +++ b/dpnp/tests/test_indexing.py @@ -1172,6 +1172,14 @@ def test_triu_indices(n, k, m): assert_array_equal(expected, result) +@pytest.mark.parametrize("k", [3.2, dpnp.bool(0), numpy.array(3.14)]) +def test_triu_indices_error(k): + with pytest.raises( + TypeError, match="`k` must be a integer data type, but got" + ): + dpnp.triu_indices(n=4, k=k) + + @pytest.mark.parametrize("k", [-3, -2, -1, 0, 1, 2, 3]) @pytest.mark.parametrize( "array", From 2e8e42634d2466983bc3a747c27545dcb20aec16 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 15 Apr 2026 16:01:27 +0200 Subject: [PATCH 3/3] Populate the changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8aaae542ec5..f9c489e8bb13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum * Updated QR tests to avoid element-wise comparisons for `raw` and `r` modes [#2785](https://github.com/IntelPython/dpnp/pull/2785) * Moved all SYCL kernel functors from `backend/extensions/` to a unified `backend/kernels/` directory hierarchy [#2816](https://github.com/IntelPython/dpnp/pull/2816) * `dpnp` uses pybind11 3.0.3 [#2834](https://github.com/IntelPython/dpnp/pull/2834) +* Added explicit type check of `k` keyword in `dpnp.triu_indices` [#2855](https://github.com/IntelPython/dpnp/pull/2855) ### Deprecated