diff --git a/CHANGELOG.md b/CHANGELOG.md index 3507b51efc6..3b38d73bd1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum * `dpnp.asfarray` is deprecated. Use `dpnp.asarray` with an appropriate dtype instead [#2650](https://github.com/IntelPython/dpnp/pull/2650) * Passing the output array ``out`` positionally to `dpnp.minimum` and `dpnp.maximum` is deprecated. Pass the output with the keyword form, e.g. ``dpnp.minimum(a, b, out=c)`` [#2659](https://github.com/IntelPython/dpnp/pull/2659) * `dpnp.ndarray.T` property is deprecated for not two-dimensional array to be compatible with the Python array API standard. To achieve a similar behavior when ``a.ndim != 2``, either ``a.transpose()``, or ``a.mT`` (swaps the last two axes only), or ``dpnp.permute_dims(a, range(a.ndim)[::-1])`` can be used [#2681](https://github.com/IntelPython/dpnp/pull/2681) +* `dpnp.fix` is deprecated. Use `dpnp.trunc` instead, which provides identical functionality [#2730](https://github.com/IntelPython/dpnp/pull/2730) ### Removed diff --git a/dpnp/dpnp_algo/dpnp_elementwise_common.py b/dpnp/dpnp_algo/dpnp_elementwise_common.py index c404d71dfbc..57bf50422fa 100644 --- a/dpnp/dpnp_algo/dpnp_elementwise_common.py +++ b/dpnp/dpnp_algo/dpnp_elementwise_common.py @@ -60,6 +60,7 @@ "DPNPBinaryFunc", "DPNPBinaryFuncOutKw", "DPNPBinaryTwoOutputsFunc", + "DPNPDeprecatedUnaryFunc", "DPNPImag", "DPNPReal", "DPNPRound", @@ -230,6 +231,32 @@ def _unpack_out_kw(self, out): return out +class DPNPDeprecatedUnaryFunc(DPNPUnaryFunc): + """ + Class that implements a deprecated unary element-wise function. + + Parameters + ---------- + deprecated_msg : {str, None}, optional + Warning message to emit. If None, no warning is issued. + + Default: ``None``. + + """ + + def __init__(self, *args, deprecated_msg=None, **kwargs): + super().__init__(*args, **kwargs) + self._deprecated_msg = deprecated_msg + + @wraps(DPNPUnaryFunc.__call__) + def __call__(self, *args, **kwargs): + if self._deprecated_msg: + warnings.warn( + self._deprecated_msg, DeprecationWarning, stacklevel=2 + ) + return super().__call__(*args, **kwargs) + + class DPNPUnaryTwoOutputsFunc(UnaryElementwiseFunc): """ Class that implements unary element-wise functions with two output arrays. diff --git a/dpnp/dpnp_iface_mathematical.py b/dpnp/dpnp_iface_mathematical.py index 63aee599d9b..3e6a4b0ed12 100644 --- a/dpnp/dpnp_iface_mathematical.py +++ b/dpnp/dpnp_iface_mathematical.py @@ -66,6 +66,7 @@ DPNPBinaryFunc, DPNPBinaryFuncOutKw, DPNPBinaryTwoOutputsFunc, + DPNPDeprecatedUnaryFunc, DPNPImag, DPNPReal, DPNPRound, @@ -1853,6 +1854,12 @@ def ediff1d(ary, to_end=None, to_begin=None): :obj:`dpnp.floor` : Return the floor of the input, element-wise. :obj:`dpnp.ceil` : Return the ceiling of the input, element-wise. +Warning +------- +This function is deprecated. It is recommended to use +:func:`dpnp.trunc` instead, as it provides the same functionality of +truncating decimal values to their integer parts. + Examples -------- >>> import dpnp as np @@ -1867,13 +1874,14 @@ def ediff1d(ary, to_end=None, to_begin=None): """ # reuse trunc backend implementation for fix -fix = DPNPUnaryFunc( +fix = DPNPDeprecatedUnaryFunc( "fix", ti._trunc_result_type, ti._trunc, _FIX_DOCSTRING, mkl_fn_to_call="_mkl_trunc_to_call", mkl_impl_fn="_trunc", + deprecated_msg="dpnp.fix is deprecated in favor of dpnp.trunc", ) diff --git a/dpnp/tests/test_mathematical.py b/dpnp/tests/test_mathematical.py index e38cb149c30..d443b71adff 100644 --- a/dpnp/tests/test_mathematical.py +++ b/dpnp/tests/test_mathematical.py @@ -2029,7 +2029,18 @@ def test_out_dtype(self, func): @pytest.mark.parametrize("xp", [numpy, dpnp]) @pytest.mark.parametrize( - "func", ["abs", "fix", "round", "add", "frexp", "divmod"] + "func", + [ + "abs", + pytest.param( + "fix", + marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"), + ), + "round", + "add", + "frexp", + "divmod", + ], ) def test_out_wrong_tuple_len(self, xp, func): if func == "round" and xp is numpy: @@ -2544,7 +2555,18 @@ def test_projection(self, dtype): assert dpnp.allclose(result, expected) -@pytest.mark.parametrize("func", ["ceil", "floor", "trunc", "fix"]) +@pytest.mark.parametrize( + "func", + [ + "ceil", + "floor", + "trunc", + pytest.param( + "fix", + marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"), + ), + ], +) class TestRoundingFuncs: @testing.with_requires("numpy>=2.1.0") @pytest.mark.parametrize( diff --git a/dpnp/tests/test_sycl_queue.py b/dpnp/tests/test_sycl_queue.py index 0bd4d6b5333..6dcafa265d5 100644 --- a/dpnp/tests/test_sycl_queue.py +++ b/dpnp/tests/test_sycl_queue.py @@ -264,7 +264,11 @@ def test_meshgrid(device): pytest.param("exp2", [0.0, 1.0, 2.0]), pytest.param("expm1", [1.0e-10, 1.0, 2.0, 4.0, 7.0]), pytest.param("fabs", [-1.2, 1.2]), - pytest.param("fix", [2.1, 2.9, -2.1, -2.9]), + pytest.param( + "fix", + [2.1, 2.9, -2.1, -2.9], + marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"), + ), pytest.param("flatnonzero", [-2, -1, 0, 1, 2]), pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]), pytest.param("gradient", [1.0, 2.0, 4.0, 7.0, 11.0, 16.0]), diff --git a/dpnp/tests/test_usm_type.py b/dpnp/tests/test_usm_type.py index fa4fc62e34c..4fc0f2b958f 100644 --- a/dpnp/tests/test_usm_type.py +++ b/dpnp/tests/test_usm_type.py @@ -572,7 +572,11 @@ def test_meshgrid(usm_type_x, usm_type_y): pytest.param("exp2", [0.0, 1.0, 2.0]), pytest.param("expm1", [1.0e-10, 1.0, 2.0, 4.0, 7.0]), pytest.param("fabs", [-1.2, 1.2]), - pytest.param("fix", [2.1, 2.9, -2.1, -2.9]), + pytest.param( + "fix", + [2.1, 2.9, -2.1, -2.9], + marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"), + ), pytest.param("flatnonzero", [-2, -1, 0, 1, 2]), pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]), pytest.param("gradient", [1, 2, 4, 7, 11, 16]), diff --git a/dpnp/tests/third_party/cupy/math_tests/test_rounding.py b/dpnp/tests/third_party/cupy/math_tests/test_rounding.py index a2ad717f250..10e79715dd1 100644 --- a/dpnp/tests/third_party/cupy/math_tests/test_rounding.py +++ b/dpnp/tests/third_party/cupy/math_tests/test_rounding.py @@ -66,6 +66,7 @@ def test_trunc(self): self.check_unary("trunc") self.check_unary_complex_unsupported("trunc") + @pytest.mark.filterwarnings("ignore::DeprecationWarning") @testing.with_requires("numpy>=2.1") def test_fix(self): self.check_unary("fix")