Skip to content

Commit

Permalink
feat: add to_backend to ak.record.Record
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Apr 3, 2023
1 parent 01df95d commit 35c3ed9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/awkward/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections.abc import Iterable

import awkward as ak
from awkward._backends import Backend
from awkward._behavior import get_record_class
from awkward._layout import wrap_layout
from awkward._nplikes.numpylike import NumpyMetadata
Expand Down Expand Up @@ -247,6 +248,16 @@ def _to_list(self, behavior, json_conversions):
else:
return dict(zip(self._array.fields, contents))

def to_backend(self, backend: Backend | str | None = None) -> Self:
if backend is None:
backend = self._array.backend
else:
backend = ak._backends.regularize_backend(backend)
if backend is self._array.backend:
return self
else:
return Record(self._array._to_backend(backend), self._at)

def __copy__(self) -> Self:
return self.copy()

Expand Down

0 comments on commit 35c3ed9

Please sign in to comment.