Skip to content

Commit

Permalink
add test for ext type
Browse files Browse the repository at this point in the history
  • Loading branch information
fecet committed Sep 14, 2024
1 parent 676f544 commit 899170b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions python/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,26 @@ def test_delta_schema():
assert schema_without_metadata == Schema.from_pyarrow(pa_schema)


def _generate_test_type():
class UuidType(pa.ExtensionType):
def __init__(self):
pa.ExtensionType.__init__(self, pa.binary(16), "my_package.uuid")

def __arrow_ext_serialize__(self):
# since we don't have a parameterized type, we don't need extra
# metadata to be deserialized
return b""

@classmethod
def __arrow_ext_deserialize__(self, storage_type, serialized):
# return an instance of this subclass given the serialized
# metadata.
return UuidType()

pa.register_extension_type(UuidType())
return UuidType()


def _generate_test_tuples():
test_tuples = [
(
Expand Down Expand Up @@ -515,6 +535,11 @@ def _generate_test_tuples():
),
ArrowSchemaConversionMode.NORMAL,
),
(
pa.schema([("uuid", _generate_test_type())]),
pa.schema([("uuid", pa.binary(16))]),
ArrowSchemaConversionMode.NORMAL,
),
]

return test_tuples
Expand Down

0 comments on commit 899170b

Please sign in to comment.