Skip to content
Closed
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
31 changes: 31 additions & 0 deletions tests/io/test_pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3885,6 +3885,37 @@ def test__to_requested_schema_null_map_of_structs() -> None:
assert result.column(1).to_pylist() == [[], None, [("b", 2), ("c", None)]]


@pytest.mark.parametrize("list_type", [pa.list_, pa.large_list])
def test__to_requested_schema_null_list_of_structs(list_type: Callable[[pa.DataType], pa.DataType]) -> None:
requested_schema = Schema(
NestedField(
1,
"col_list_with_struct",
ListType(
11,
StructType(NestedField(111, "source", StringType(), required=False)),
element_required=False,
),
required=False,
),
)
arrow_schema = pa.schema([pa.field("col_list_with_struct", list_type(pa.struct([pa.field("source", pa.string())])))])
batch = pa.RecordBatch.from_arrays(
[pa.array([[{"source": "x"}], [], None, [{"source": "y"}, None]], type=arrow_schema.field(0).type)],
schema=arrow_schema,
)

result = _to_requested_schema(requested_schema, requested_schema, batch)
assert result.column(0).to_pylist() == [[{"source": "x"}], [], None, [{"source": "y"}, None]]

# A sliced batch has to keep the nulls as well
result = _to_requested_schema(requested_schema, requested_schema, batch.slice(1, 3))
assert result.column(0).to_pylist() == [[], None, [{"source": "y"}, None]]

result = _to_requested_schema(requested_schema, requested_schema, batch.slice(2, 0))
assert result.column(0).to_pylist() == []


@pytest.mark.parametrize(
"arrow_type,iceberg_type,expected_arrow_type",
[
Expand Down
Loading