Skip to content

Commit

Permalink
Add dak.to_list
Browse files Browse the repository at this point in the history
  • Loading branch information
martindurant committed Apr 12, 2024
1 parent af95510 commit b7a03a5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/dask_awkward/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
singletons,
sort,
strings_astype,
to_list,
to_packed,
to_regular,
unflatten,
Expand Down
1 change: 1 addition & 0 deletions src/dask_awkward/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
singletons,
sort,
strings_astype,
to_list,
to_packed,
to_regular,
unflatten,
Expand Down
10 changes: 10 additions & 0 deletions src/dask_awkward/lib/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"singletons",
"sort",
"strings_astype",
"to_list",
"to_packed",
"to_regular",
"unflatten",
Expand Down Expand Up @@ -691,6 +692,15 @@ def ones_like(
)


@borrow_docstring(ak.to_list)
def to_list(array: Array) -> list:
"""Return list/dict version of the data
Unlike most functions, this one requires a compute() of the data.
"""
return array.compute().to_list()


@borrow_docstring(ak.to_packed)
def to_packed(
array: Array,
Expand Down
3 changes: 0 additions & 3 deletions tests/test_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ def test_distance_behavior(
caa1 = ak.Array(caa_p1.points, with_name="Point", behavior=behaviors)
caa2 = ak.Array(caa_p2.points)

print(f"{ak.to_list(daa1.distance(daa2)) = }")
print(f"{ak.to_list(caa1.distance(caa2)) = }")

assert_eq(daa1.distance(daa2), caa1.distance(caa2))
assert_eq(np.abs(daa1), np.abs(caa1))

Expand Down
4 changes: 4 additions & 0 deletions tests/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ def test_to_packed(daa, caa):
)


def test_to_list(daa):
assert dak.to_list(daa) == daa.compute().to_list()


def test_ravel(daa, caa):
assert_eq(
dak.ravel(daa.points.x),
Expand Down

0 comments on commit b7a03a5

Please sign in to comment.