Skip to content

Commit 06d3076

Browse files
Deprecate dpnp.asfarray() and raise a DeprecationWarning (#2650)
This PR marks `dpnp.asfarray()` as deprecated to align with NumPy>=2.0 where this function was removed ([Release Notes Numpy 2.0](https://numpy.org/doc/2.0/release/2.0.0-notes.html)) A `DeprecationWarning` is now raised informing users that the function will be removed in a future release and suggesting to use `dpnp.asarray(dtype=...)` instead.
1 parent 7cd5570 commit 06d3076

File tree

6 files changed

+37
-8
lines changed

6 files changed

+37
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum
3131

3232
### Deprecated
3333

34+
* `dpnp.asfarray` is deprecated. Use `dpnp.asarray` with an appropriate dtype instead [#2650](https://github.com/IntelPython/dpnp/pull/2650)
35+
3436
### Removed
3537

3638
* Dropped support for Python 3.9 [#2626](https://github.com/IntelPython/dpnp/pull/2626)

doc/reference/_deprecated.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
:orphan:
2+
3+
.. This page is to generate documentation for deprecated APIs removed from the
4+
public table of contents.
5+
6+
NumPy Routines
7+
--------------
8+
9+
.. autosummary::
10+
:toctree: generated/
11+
:nosignatures:
12+
13+
# Removed in NumPy v2.0
14+
dpnp.asfarray

doc/reference/array-manipulation.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ Changing kind of array
7474
asarray
7575
asanyarray
7676
asnumpy
77-
asfarray
7877
asfortranarray
7978
ascontiguousarray
8079
asarray_chkfinite

dpnp/dpnp_iface_arraycreation.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,6 @@ def asanyarray(
511511
--------
512512
:obj:`dpnp.asarray` : Similar function which always returns ndarrays.
513513
:obj:`dpnp.ascontiguousarray` : Convert input to a contiguous array.
514-
:obj:`dpnp.asfarray` : Convert input to a floating point ndarray.
515514
:obj:`dpnp.asfortranarray` : Convert input to an ndarray with column-major
516515
memory order.
517516
:obj:`dpnp.asarray_chkfinite` : Similar function which checks input
@@ -624,8 +623,7 @@ def asarray(
624623
--------
625624
:obj:`dpnp.asanyarray` : Similar function which passes through subclasses.
626625
:obj:`dpnp.ascontiguousarray` : Convert input to a contiguous array.
627-
:obj:`dpnp.asfarray` : Convert input to a floating point ndarray.
628-
:obj:`dpnp.asfortranarray` : Convert input to an ndarray with column-major
626+
:obj:`dpnp.asfortranarray` : Convert input to an ndarray with column-majors
629627
memory order.
630628
:obj:`dpnp.asarray_chkfinite` : Similar function which checks input
631629
for NaNs and Infs.

dpnp/dpnp_iface_manipulation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,11 @@ def asfarray(a, dtype=None, *, device=None, usm_type=None, sycl_queue=None):
894894
out : dpnp.ndarray
895895
The input `a` as a float ndarray.
896896
897+
Warning
898+
-------
899+
This function is deprecated in favor of :obj:`dpnp.asarray` and
900+
will be removed in a future release.
901+
897902
Examples
898903
--------
899904
>>> import dpnp as np
@@ -906,6 +911,14 @@ def asfarray(a, dtype=None, *, device=None, usm_type=None, sycl_queue=None):
906911
907912
"""
908913

914+
warnings.warn(
915+
"`dpnp.asfarray` is deprecated, "
916+
"and will be removed in a future release. "
917+
"Please use `dpnp.asarray` with an appropriate dtype instead.",
918+
DeprecationWarning,
919+
stacklevel=2,
920+
)
921+
909922
_sycl_queue = dpnp.get_normalized_queue_device(
910923
a, sycl_queue=sycl_queue, device=device
911924
)

dpnp/tests/test_arraymanipulation.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import warnings
2+
13
import dpctl.tensor as dpt
24
import numpy
35
import pytest
@@ -31,14 +33,15 @@ def test_asfarray2(self, dtype, data, data_dtype):
3133
result = dpnp.asfarray(dpnp.array(data, dtype=data_dtype), dtype)
3234
assert_array_equal(result, expected)
3335

34-
# This is only for coverage with NumPy 2.0 and above
35-
def test_asfarray_coverage(self):
36+
def test_asfarray_deprecated(self):
3637
expected = dpnp.array([1.0, 2.0, 3.0])
37-
result = dpnp.asfarray([1, 2, 3])
38+
with pytest.warns(DeprecationWarning, match="deprecated"):
39+
result = dpnp.asfarray([1, 2, 3])
3840
assert_array_equal(result, expected)
3941

4042
expected = dpnp.array([1.0, 2.0, 3.0], dtype=dpnp.float32)
41-
result = dpnp.asfarray([1, 2, 3], dtype=dpnp.float32)
43+
with pytest.warns(DeprecationWarning, match="deprecated"):
44+
result = dpnp.asfarray([1, 2, 3], dtype=dpnp.float32)
4245
assert_array_equal(result, expected)
4346

4447

0 commit comments

Comments
 (0)