From 6f5d0fd7a660980dd2d78d30604ca2b45c23df80 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 5 Nov 2025 05:46:01 -0800 Subject: [PATCH 1/6] Deprecate dpnp.asfarray() --- dpnp/dpnp_iface_manipulation.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 848700de93e3..476f03f40aef 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -906,6 +906,14 @@ def asfarray(a, dtype=None, *, device=None, usm_type=None, sycl_queue=None): """ + warnings.warn( + "`dpnp.asfarray` is deprecated, " + "and will be removed in a future release. " + "Please use `dpnp.asarray` with an appropriate dtype instead.", + DeprecationWarning, + stacklevel=2, + ) + _sycl_queue = dpnp.get_normalized_queue_device( a, sycl_queue=sycl_queue, device=device ) From e83cdca3d1cd5e1e3de89be524f0bb3d89fca12f Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 5 Nov 2025 05:50:55 -0800 Subject: [PATCH 2/6] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3714735c9ba0..e964236ced74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum ### Deprecated +* `dpnp.asfarray` is deprecated. Use `dpnp.asarray` with an appropriate dtype instead [#2650](https://github.com/IntelPython/dpnp/pull/2650) + ### Removed * Dropped support for Python 3.9 [#2626](https://github.com/IntelPython/dpnp/pull/2626) From 8656f44a87af7a3d72d80da60dc11b7880c2eeeb Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 7 Nov 2025 02:15:33 -0800 Subject: [PATCH 3/6] Apply remarks --- dpnp/dpnp_iface_arraycreation.py | 4 +--- dpnp/dpnp_iface_manipulation.py | 5 +++++ dpnp/tests/test_arraymanipulation.py | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/dpnp/dpnp_iface_arraycreation.py b/dpnp/dpnp_iface_arraycreation.py index d768a2f69a6f..b137a136de3f 100644 --- a/dpnp/dpnp_iface_arraycreation.py +++ b/dpnp/dpnp_iface_arraycreation.py @@ -511,7 +511,6 @@ def asanyarray( -------- :obj:`dpnp.asarray` : Similar function which always returns ndarrays. :obj:`dpnp.ascontiguousarray` : Convert input to a contiguous array. - :obj:`dpnp.asfarray` : Convert input to a floating point ndarray. :obj:`dpnp.asfortranarray` : Convert input to an ndarray with column-major memory order. :obj:`dpnp.asarray_chkfinite` : Similar function which checks input @@ -624,8 +623,7 @@ def asarray( -------- :obj:`dpnp.asanyarray` : Similar function which passes through subclasses. :obj:`dpnp.ascontiguousarray` : Convert input to a contiguous array. - :obj:`dpnp.asfarray` : Convert input to a floating point ndarray. - :obj:`dpnp.asfortranarray` : Convert input to an ndarray with column-major + :obj:`dpnp.asfortranarray` : Convert input to an ndarray with column-majors memory order. :obj:`dpnp.asarray_chkfinite` : Similar function which checks input for NaNs and Infs. diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 476f03f40aef..11f2538fb09b 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -894,6 +894,11 @@ def asfarray(a, dtype=None, *, device=None, usm_type=None, sycl_queue=None): out : dpnp.ndarray The input `a` as a float ndarray. + Warning + ------- + This function is deprecated in favor of :obj:dpnp.asarray and + will be removed in a future release. + Examples -------- >>> import dpnp as np diff --git a/dpnp/tests/test_arraymanipulation.py b/dpnp/tests/test_arraymanipulation.py index eafa0b853a89..1b3ca3f56305 100644 --- a/dpnp/tests/test_arraymanipulation.py +++ b/dpnp/tests/test_arraymanipulation.py @@ -32,6 +32,7 @@ def test_asfarray2(self, dtype, data, data_dtype): assert_array_equal(result, expected) # This is only for coverage with NumPy 2.0 and above + @pytest.mark.filterwarnings("ignore::DeprecationWarning") def test_asfarray_coverage(self): expected = dpnp.array([1.0, 2.0, 3.0]) result = dpnp.asfarray([1, 2, 3]) From ecbe052cfda44f73a7f2878dc2e5e366c0205abb Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 7 Nov 2025 02:53:52 -0800 Subject: [PATCH 4/6] Create _deprecated.rst for deprecated APIs and move dpnp.asfarray docs --- doc/reference/_deprecated.rst | 14 ++++++++++++++ doc/reference/array-manipulation.rst | 1 - 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 doc/reference/_deprecated.rst diff --git a/doc/reference/_deprecated.rst b/doc/reference/_deprecated.rst new file mode 100644 index 000000000000..fb46e6920a55 --- /dev/null +++ b/doc/reference/_deprecated.rst @@ -0,0 +1,14 @@ +:orphan: + +.. This page is to generate documentation for deprecated APIs removed from the + public table of contents. + +NumPy Routines +-------------- + +.. autosummary:: + :toctree: generated/ + :nosignatures: + + # Removed in NumPy v2.0 + dpnp.asfarray diff --git a/doc/reference/array-manipulation.rst b/doc/reference/array-manipulation.rst index 3a1593a89a31..18108dd7f2cb 100644 --- a/doc/reference/array-manipulation.rst +++ b/doc/reference/array-manipulation.rst @@ -72,7 +72,6 @@ Changing kind of array dpnp.asarray dpnp.asanyarray dpnp.asnumpy - dpnp.asfarray dpnp.asfortranarray dpnp.ascontiguousarray dpnp.asarray_chkfinite From 2106519395757e05527f09d0cb9821e60e1d9db6 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 7 Nov 2025 07:36:59 -0800 Subject: [PATCH 5/6] Apply remark --- dpnp/dpnp_iface_manipulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 11f2538fb09b..b6ffdc763075 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -896,7 +896,7 @@ def asfarray(a, dtype=None, *, device=None, usm_type=None, sycl_queue=None): Warning ------- - This function is deprecated in favor of :obj:dpnp.asarray and + This function is deprecated in favor of :obj:`dpnp.asarray` and will be removed in a future release. Examples From e4560bdc9325994dc77bda71d1e300a5b23ef250 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 7 Nov 2025 07:38:00 -0800 Subject: [PATCH 6/6] Add test_asfarray_deprecated instead of test_asfarray_coverage --- dpnp/tests/test_arraymanipulation.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dpnp/tests/test_arraymanipulation.py b/dpnp/tests/test_arraymanipulation.py index 1b3ca3f56305..da058ffb938d 100644 --- a/dpnp/tests/test_arraymanipulation.py +++ b/dpnp/tests/test_arraymanipulation.py @@ -1,3 +1,5 @@ +import warnings + import dpctl.tensor as dpt import numpy import pytest @@ -31,15 +33,15 @@ def test_asfarray2(self, dtype, data, data_dtype): result = dpnp.asfarray(dpnp.array(data, dtype=data_dtype), dtype) assert_array_equal(result, expected) - # This is only for coverage with NumPy 2.0 and above - @pytest.mark.filterwarnings("ignore::DeprecationWarning") - def test_asfarray_coverage(self): + def test_asfarray_deprecated(self): expected = dpnp.array([1.0, 2.0, 3.0]) - result = dpnp.asfarray([1, 2, 3]) + with pytest.warns(DeprecationWarning, match="deprecated"): + result = dpnp.asfarray([1, 2, 3]) assert_array_equal(result, expected) expected = dpnp.array([1.0, 2.0, 3.0], dtype=dpnp.float32) - result = dpnp.asfarray([1, 2, 3], dtype=dpnp.float32) + with pytest.warns(DeprecationWarning, match="deprecated"): + result = dpnp.asfarray([1, 2, 3], dtype=dpnp.float32) assert_array_equal(result, expected)