diff --git a/src/awkward/contents/emptyarray.py b/src/awkward/contents/emptyarray.py index 871394093a..775d757f09 100644 --- a/src/awkward/contents/emptyarray.py +++ b/src/awkward/contents/emptyarray.py @@ -7,6 +7,7 @@ from awkward._backends.backend import Backend from awkward._backends.numpy import NumpyBackend from awkward._backends.typetracer import TypeTracerBackend +from awkward._errors import deprecate from awkward._layout import maybe_posaxis from awkward._nplikes.numpy import Numpy from awkward._nplikes.numpylike import ArrayLike, IndexType, NumpyMetadata @@ -95,6 +96,13 @@ def __copy__(self): def __deepcopy__(self, memo): return self.copy() + def __array__(self, dtype=None): + deprecate( + f"np.asarray(content) is deprecated for {type(self).__name__}. Use ak.to_numpy(content) instead", + version="2.6.0", + ) + return numpy.empty(0, dtype=dtype) + @classmethod def simplified(cls, *, parameters=None, backend=None): if not (parameters is None or len(parameters) == 0): diff --git a/src/awkward/contents/numpyarray.py b/src/awkward/contents/numpyarray.py index 6a3f7a572c..1b39cc822b 100644 --- a/src/awkward/contents/numpyarray.py +++ b/src/awkward/contents/numpyarray.py @@ -9,6 +9,7 @@ from awkward._backends.dispatch import backend_of from awkward._backends.numpy import NumpyBackend from awkward._backends.typetracer import TypeTracerBackend +from awkward._errors import deprecate from awkward._layout import maybe_posaxis from awkward._nplikes import to_nplike from awkward._nplikes.jax import Jax @@ -151,6 +152,13 @@ def __deepcopy__(self, memo): parameters=copy.deepcopy(self._parameters, memo), ) + def __array__(self, dtype=None): + deprecate( + f"np.asarray(content) is deprecated for {type(self).__name__}. Use ak.to_numpy(content) instead", + version="2.6.0", + ) + return numpy.asarray(self._data, dtype=dtype) + @classmethod def simplified(cls, data, *, parameters=None, backend=None): return cls(data, parameters=parameters, backend=backend)