Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: revert breaking component of asarray PR #2752

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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