Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Chia committed Aug 13, 2023
1 parent f12d340 commit 850ae4e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 0 additions & 3 deletions daft/logical/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ def from_pyarrow_schema(cls, pa_schema: pa.Schema) -> Schema:
Returns:
Schema: Converted Daft schema
"""
if not isinstance(pa_schema, pa.Schema):
raise ValueError(f"Expected pa_schema to be a PyArrow schema object, but received instead: {pa_schema}")

return cls._from_field_name_and_types(
[(pa_field.name, DataType.from_arrow_type(pa_field.type)) for pa_field in pa_schema]
)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import copy

import pyarrow as pa
import pytest

from daft.datatype import DataType
Expand Down Expand Up @@ -130,3 +131,23 @@ def test_schema_pickling():
assert s1 != t_empty.schema()
t_empty_schema_copy = copy.deepcopy(t_empty.schema())
assert t_empty.schema() == t_empty_schema_copy


def test_schema_from_pyarrow():
pa_schema = pa.schema(
{
"int": pa.int64(),
"str": pa.string(),
"list": pa.list_(pa.int64()),
}
)

expected_daft_schema = Schema._from_field_name_and_types(
[
("int", DataType.int64()),
("str", DataType.string()),
("list", DataType.list("item", DataType.int64())),
]
)

assert Schema.from_pyarrow_schema(pa_schema) == expected_daft_schema

0 comments on commit 850ae4e

Please sign in to comment.