Skip to content

Commit

Permalink
fix: dak.copy should copy metadata (#413)
Browse files Browse the repository at this point in the history
* fix: make deep (meta) copy in dak.copy

* fix: only copy metadata
  • Loading branch information
agoose77 authored Nov 13, 2023
1 parent 9d3433d commit e17a4c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 12 additions & 1 deletion src/dask_awkward/lib/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import builtins
import warnings
from collections.abc import Iterable, Mapping, Sequence
from copy import deepcopy
from numbers import Number
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -315,7 +316,17 @@ def combinations(

@borrow_docstring(ak.copy)
def copy(array: Array) -> Array:
return array
# Make a copy of meta, but don't try and copy the layout;
# dask-awkward's copy is metadata-only
old_meta = array._meta
new_meta = ak.Array(old_meta.layout, behavior=deepcopy(old_meta._behavior))

return Array(
array._dask,
array._name,
new_meta,
array._divisions,
)


class _FillNoneFn:
Expand Down
7 changes: 2 additions & 5 deletions tests/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,8 @@ def test_sort(daa, caa, ascending):


def test_copy(daa):
with pytest.raises(
DaskAwkwardNotImplemented,
match="This function is not necessary in the context of dask-awkward.",
):
dak.copy(daa)
result = dak.copy(daa)
assert result._meta is not daa._meta


@pytest.mark.parametrize(
Expand Down

0 comments on commit e17a4c9

Please sign in to comment.