Skip to content

Commit 865b53e

Browse files
Deprecate dpnp.fix() (#2730)
This PR deprecates `dpnp.fix()` in favor of `dpnp.trunc` (following NumPy 2.5) It adds `DPNPDeprecatedUnaryFunc` wrapper and updates tests to ignore DeprecationWarning Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com>
1 parent 626bd3b commit 865b53e

File tree

7 files changed

+72
-5
lines changed

7 files changed

+72
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum
5151
* `dpnp.asfarray` is deprecated. Use `dpnp.asarray` with an appropriate dtype instead [#2650](https://github.com/IntelPython/dpnp/pull/2650)
5252
* 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)
5353
* `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)
54+
* `dpnp.fix` is deprecated. Use `dpnp.trunc` instead, which provides identical functionality [#2730](https://github.com/IntelPython/dpnp/pull/2730)
5455

5556
### Removed
5657

dpnp/dpnp_algo/dpnp_elementwise_common.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"DPNPBinaryFunc",
6161
"DPNPBinaryFuncOutKw",
6262
"DPNPBinaryTwoOutputsFunc",
63+
"DPNPDeprecatedUnaryFunc",
6364
"DPNPImag",
6465
"DPNPReal",
6566
"DPNPRound",
@@ -230,6 +231,32 @@ def _unpack_out_kw(self, out):
230231
return out
231232

232233

234+
class DPNPDeprecatedUnaryFunc(DPNPUnaryFunc):
235+
"""
236+
Class that implements a deprecated unary element-wise function.
237+
238+
Parameters
239+
----------
240+
deprecated_msg : {str, None}, optional
241+
Warning message to emit. If None, no warning is issued.
242+
243+
Default: ``None``.
244+
245+
"""
246+
247+
def __init__(self, *args, deprecated_msg=None, **kwargs):
248+
super().__init__(*args, **kwargs)
249+
self._deprecated_msg = deprecated_msg
250+
251+
@wraps(DPNPUnaryFunc.__call__)
252+
def __call__(self, *args, **kwargs):
253+
if self._deprecated_msg:
254+
warnings.warn(
255+
self._deprecated_msg, DeprecationWarning, stacklevel=2
256+
)
257+
return super().__call__(*args, **kwargs)
258+
259+
233260
class DPNPUnaryTwoOutputsFunc(UnaryElementwiseFunc):
234261
"""
235262
Class that implements unary element-wise functions with two output arrays.

dpnp/dpnp_iface_mathematical.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
DPNPBinaryFunc,
6767
DPNPBinaryFuncOutKw,
6868
DPNPBinaryTwoOutputsFunc,
69+
DPNPDeprecatedUnaryFunc,
6970
DPNPImag,
7071
DPNPReal,
7172
DPNPRound,
@@ -1853,6 +1854,12 @@ def ediff1d(ary, to_end=None, to_begin=None):
18531854
:obj:`dpnp.floor` : Return the floor of the input, element-wise.
18541855
:obj:`dpnp.ceil` : Return the ceiling of the input, element-wise.
18551856
1857+
Warning
1858+
-------
1859+
This function is deprecated. It is recommended to use
1860+
:func:`dpnp.trunc` instead, as it provides the same functionality of
1861+
truncating decimal values to their integer parts.
1862+
18561863
Examples
18571864
--------
18581865
>>> import dpnp as np
@@ -1867,13 +1874,14 @@ def ediff1d(ary, to_end=None, to_begin=None):
18671874
"""
18681875

18691876
# reuse trunc backend implementation for fix
1870-
fix = DPNPUnaryFunc(
1877+
fix = DPNPDeprecatedUnaryFunc(
18711878
"fix",
18721879
ti._trunc_result_type,
18731880
ti._trunc,
18741881
_FIX_DOCSTRING,
18751882
mkl_fn_to_call="_mkl_trunc_to_call",
18761883
mkl_impl_fn="_trunc",
1884+
deprecated_msg="dpnp.fix is deprecated in favor of dpnp.trunc",
18771885
)
18781886

18791887

dpnp/tests/test_mathematical.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,7 +2029,18 @@ def test_out_dtype(self, func):
20292029

20302030
@pytest.mark.parametrize("xp", [numpy, dpnp])
20312031
@pytest.mark.parametrize(
2032-
"func", ["abs", "fix", "round", "add", "frexp", "divmod"]
2032+
"func",
2033+
[
2034+
"abs",
2035+
pytest.param(
2036+
"fix",
2037+
marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"),
2038+
),
2039+
"round",
2040+
"add",
2041+
"frexp",
2042+
"divmod",
2043+
],
20332044
)
20342045
def test_out_wrong_tuple_len(self, xp, func):
20352046
if func == "round" and xp is numpy:
@@ -2544,7 +2555,18 @@ def test_projection(self, dtype):
25442555
assert dpnp.allclose(result, expected)
25452556

25462557

2547-
@pytest.mark.parametrize("func", ["ceil", "floor", "trunc", "fix"])
2558+
@pytest.mark.parametrize(
2559+
"func",
2560+
[
2561+
"ceil",
2562+
"floor",
2563+
"trunc",
2564+
pytest.param(
2565+
"fix",
2566+
marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"),
2567+
),
2568+
],
2569+
)
25482570
class TestRoundingFuncs:
25492571
@testing.with_requires("numpy>=2.1.0")
25502572
@pytest.mark.parametrize(

dpnp/tests/test_sycl_queue.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ def test_meshgrid(device):
261261
pytest.param("exp2", [0.0, 1.0, 2.0]),
262262
pytest.param("expm1", [1.0e-10, 1.0, 2.0, 4.0, 7.0]),
263263
pytest.param("fabs", [-1.2, 1.2]),
264-
pytest.param("fix", [2.1, 2.9, -2.1, -2.9]),
264+
pytest.param(
265+
"fix",
266+
[2.1, 2.9, -2.1, -2.9],
267+
marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"),
268+
),
265269
pytest.param("flatnonzero", [-2, -1, 0, 1, 2]),
266270
pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
267271
pytest.param("gradient", [1.0, 2.0, 4.0, 7.0, 11.0, 16.0]),

dpnp/tests/test_usm_type.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,11 @@ def test_meshgrid(usm_type_x, usm_type_y):
572572
pytest.param("exp2", [0.0, 1.0, 2.0]),
573573
pytest.param("expm1", [1.0e-10, 1.0, 2.0, 4.0, 7.0]),
574574
pytest.param("fabs", [-1.2, 1.2]),
575-
pytest.param("fix", [2.1, 2.9, -2.1, -2.9]),
575+
pytest.param(
576+
"fix",
577+
[2.1, 2.9, -2.1, -2.9],
578+
marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"),
579+
),
576580
pytest.param("flatnonzero", [-2, -1, 0, 1, 2]),
577581
pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
578582
pytest.param("gradient", [1, 2, 4, 7, 11, 16]),

dpnp/tests/third_party/cupy/math_tests/test_rounding.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def test_trunc(self):
6666
self.check_unary("trunc")
6767
self.check_unary_complex_unsupported("trunc")
6868

69+
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
6970
@testing.with_requires("numpy>=2.1")
7071
def test_fix(self):
7172
self.check_unary("fix")

0 commit comments

Comments
 (0)