You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "khwilson (via GitHub)" <gi...@apache.org> on 2024/10/15 01:49:59 UTC
Re: [I] [Python] Allow creating extension arrays via `pa.array` constructor [arrow]
khwilson commented on issue #44406:
URL: https://github.com/apache/arrow/issues/44406#issuecomment-2412650636
I believe this already works. See https://github.com/apache/arrow/blob/main/python/pyarrow/array.pxi#L372 and this example:
```python
from uuid import uuid4
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()
def main():
data = [uuid4().bytes]
arr = pa.array(data, type=UuidType())
print(arr)
if __name__ == "__main__":
main()
```
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org