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

Fix project_form for projections within a RecordArray field and for node types without indexes. #582

Merged
merged 4 commits into from
Oct 18, 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
51 changes: 51 additions & 0 deletions tiled/_tests/test_awkward.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json

import awkward
import numpy
import pyarrow.feather
import pyarrow.parquet
import pytest
Expand Down Expand Up @@ -144,3 +145,53 @@ def test_large_number_of_form_keys(client):
assert form_key_length > URL_LENGTH_LIMIT
url_length = len(str(request.url))
assert url_length <= URL_LENGTH_LIMIT


def test_more_slicing_1(client):
array = awkward.Array(
[
{
"stuff": 123,
"file": [
{"filename": 321, "other": 3.14},
],
},
]
)
returned = client.write_awkward(array, key="test")
# Test with client returned, and with client from lookup.
for aac in [returned, client["test"]]:
# Read the data back out from the AwkwardArrrayClient, progressively sliced.
assert awkward.almost_equal(aac.read(), array)
assert awkward.almost_equal(aac[:], array)
assert awkward.almost_equal(aac["file", "filename"], array["file", "filename"])


def test_more_slicing_2(client):
array = awkward.from_numpy(
numpy.arange(2 * 3 * 5).reshape(2, 3, 5), regulararray=True
)
returned = client.write_awkward(array, key="test")
# Test with client returned, and with client from lookup.
for aac in [returned, client["test"]]:
# Read the data back out from the AwkwardArrrayClient, progressively sliced.
assert awkward.almost_equal(aac.read(), array)
assert awkward.almost_equal(aac[:], array)
assert awkward.almost_equal(aac[1:], array[1:])
assert awkward.almost_equal(aac[1:, 1:], array[1:, 1:])


def test_more_slicing_3(client):
array = awkward.Array(
[
{"good": 123, "bad": 123},
{"good": 321, "bad": [1, 2, 3]},
]
)
returned = client.write_awkward(array, key="test")
# Test with client returned, and with client from lookup.
for aac in [returned, client["test"]]:
# Read the data back out from the AwkwardArrrayClient, progressively sliced.
assert awkward.almost_equal(aac.read(), array)
assert awkward.almost_equal(aac[:], array[:])
assert awkward.almost_equal(aac["good"], array["good"])
7 changes: 6 additions & 1 deletion tiled/structures/awkward.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def project_form(form, form_keys_touched):
projected = project_form(content, form_keys_touched)
if projected is not None:
fields.append(field)
contents.append(content)
contents.append(projected)

if form.fields is None:
fields = None
Expand All @@ -41,6 +41,8 @@ def project_form(form, form_keys_touched):
return None
elif len(step2) == 1:
return step2[0]
elif step2 == form.contents:
return form
else:
raise NotImplementedError(
"Certain UnionForms are not yet supported. "
Expand All @@ -60,6 +62,9 @@ def project_form(form, form_keys_touched):
else:
return None

elif isinstance(form, (awkward.forms.RegularForm, awkward.forms.UnmaskedForm)):
return form.copy(content=project_form(form.content, form_keys_touched))

else:
if form.form_key in form_keys_touched:
return form.copy(content=project_form(form.content, form_keys_touched))
Expand Down