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: add 'dak.backend' and dak.to_list and verify that they overload the ak.* versions #498

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpivarski I wonder, should this be lazy and return a bag of lists?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We chatted in the meeting and thought not - this is only likely to be used in testing for small data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if I called this function, I wouldn't be interested in lazy data. The use-case that came up here was that I wanted to debug a test failure.



@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)) = }")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was here to diagnose the test failure.

But now it looks like the test passed, just having been run a second time. (Usually, not a good thing!)


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
Loading