ianmcook commented on code in PR #43849:
URL: https://github.com/apache/arrow/pull/43849#discussion_r1733604630
##########
python/pyarrow/types.pxi:
##########
@@ -2089,30 +2120,41 @@ def unregister_extension_type(type_name):
Examples
--------
- Define a UuidType extension type subclassing ExtensionType:
+ Define a RationalType extension type subclassing ExtensionType:
>>> import pyarrow as pa
- >>> 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()
- ...
+ >>> import pyarrow.types as pt
+ >>> class RationalType(pa.ExtensionType):
+ ... def __init__(self, data_type: pa.DataType):
+ ... if not pt.is_integer(data_type):
+ ... raise TypeError(f"data_type must be an integer type not
{data_type}")
+ ... super().__init__(
+ ... pa.struct(
+ ... [
+ ... ("numer", data_type),
+ ... ("denom", data_type),
+ ... ],
+ ... ),
+ ... # N.B. This name does _not_ reference `data_type` so
deserialization
+ ... # will work for _any_ integer `data_type` after
registration
+ ... "my_package.rational",
+ ... )
+ ... def __arrow_ext_serialize__(self) -> bytes:
+ ... # No serialized metadata necessary
+ ... return b""
+ ... @classmethod
+ ... def __arrow_ext_deserialize__(self, storage_type, serialized):
Review Comment:
```suggestion
... def __arrow_ext_deserialize__(cls, storage_type, serialized):
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]