diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c79fea05bb..2c9af82eb76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum * `dpnp` uses pybind11 3.0.3 [#2834](https://github.com/IntelPython/dpnp/pull/2834) * 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) * `dpnp` uses pybind11 3.0.4 [#2865](https://github.com/IntelPython/dpnp/pull/2865) +* 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 da6b45517eb..31be7a8c276 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 1c9776582b7..333dbc2349c 100644 --- a/dpnp/dpnp_iface_indexing.py +++ b/dpnp/dpnp_iface_indexing.py @@ -2623,6 +2623,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 d54ae381a38..8342be2e939 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",