diff --git a/CHANGELOG.md b/CHANGELOG.md index f8aaae542ec..f9c489e8bb1 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 diff --git a/dpnp/dpnp_iface_arraycreation.py b/dpnp/dpnp_iface_arraycreation.py index 5bcf5ea19b8..d0607990398 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 2a90f6cff63..9264ff1750f 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, diff --git a/dpnp/tests/test_indexing.py b/dpnp/tests/test_indexing.py index 27f34f6288b..4287ec6d02b 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",