Skip to content

Commit

Permalink
feat!: revert breaking component of asarray PR (#2752)
Browse files Browse the repository at this point in the history
* feat!: revert breaking component of asarray PR

* fix: use `nplike.asarray`

* feat: improve error message
  • Loading branch information
agoose77 authored Oct 12, 2023
1 parent 2c69afd commit 0627266
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/awkward/contents/emptyarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions src/awkward/contents/numpyarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0627266

Please sign in to comment.