Skip to content
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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)
Expand Down
14 changes: 14 additions & 0 deletions doc/reference/_deprecated.rst
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion doc/reference/array-manipulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ Changing kind of array
asarray
asanyarray
asnumpy
asfarray
asfortranarray
ascontiguousarray
asarray_chkfinite
Expand Down
4 changes: 1 addition & 3 deletions dpnp/dpnp_iface_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions dpnp/dpnp_iface_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -906,6 +911,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
)
Expand Down
11 changes: 7 additions & 4 deletions dpnp/tests/test_arraymanipulation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import dpctl.tensor as dpt
import numpy
import pytest
Expand Down Expand Up @@ -31,14 +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
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)


Expand Down
Loading