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

Support JSON lines with missing struct fields #7160

Merged
merged 2 commits into from
Sep 23, 2024
Merged
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
Next Next commit
Test cast_array_to_features with struct with missing fields
  • Loading branch information
albertvillanova committed Sep 23, 2024
commit c81e495e5dfe51bd4f2e50b6be26e68ec3cb211c
8 changes: 8 additions & 0 deletions tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,14 @@ def test_cast_decimal_array_to_features():
cast_array_to_feature(arr, Sequence(Value("string")), allow_decimal_to_str=False)


def test_cast_array_to_features_with_struct_with_missing_fields():
arr = pa.array([{"age": 25}, {"age": 63}])
feature = {"age": Value("int32"), "name": Value("string")}
cast_array = cast_array_to_feature(arr, feature)
assert cast_array.type == pa.struct({"age": pa.int32(), "name": pa.string()})
assert cast_array.to_pylist() == [{"age": 25, "name": None}, {"age": 63, "name": None}]


def test_cast_array_to_features_nested():
arr = pa.array([[{"foo": [0]}]])
assert cast_array_to_feature(arr, [{"foo": Sequence(Value("string"))}]).type == pa.list_(
Expand Down
Loading