You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/02/25 20:08:08 UTC
[arrow] branch master updated: ARROW-4662: [Python] Add support of
type_codes in UnionType
This is an automated email from the ASF dual-hosted git repository.
wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new a2cd589 ARROW-4662: [Python] Add support of type_codes in UnionType
a2cd589 is described below
commit a2cd5891737807980b4fbb3bd0e83c89d6209077
Author: Kenta Murata <mr...@mrkn.jp>
AuthorDate: Mon Feb 25 14:07:49 2019 -0600
ARROW-4662: [Python] Add support of type_codes in UnionType
UnionType should have `type_codes` property.
Author: Kenta Murata <mr...@mrkn.jp>
Closes #3732 from mrkn/python_union_type_codes and squashes the following commits:
3bf83b07 <Kenta Murata> Add support of type_codes in UnionType
---
python/pyarrow/includes/libarrow.pxd | 1 +
python/pyarrow/tests/test_types.py | 2 ++
python/pyarrow/types.pxi | 8 ++++++++
3 files changed, 11 insertions(+)
diff --git a/python/pyarrow/includes/libarrow.pxd b/python/pyarrow/includes/libarrow.pxd
index 64b907b..8382221 100644
--- a/python/pyarrow/includes/libarrow.pxd
+++ b/python/pyarrow/includes/libarrow.pxd
@@ -284,6 +284,7 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
CUnionType(const vector[shared_ptr[CField]]& fields,
const vector[uint8_t]& type_codes, UnionMode mode)
UnionMode mode()
+ const vector[uint8_t]& type_codes()
cdef cppclass CSchema" arrow::Schema":
CSchema(const vector[shared_ptr[CField]]& fields)
diff --git a/python/pyarrow/tests/test_types.py b/python/pyarrow/tests/test_types.py
index 2401bf5..d66e14e 100644
--- a/python/pyarrow/tests/test_types.py
+++ b/python/pyarrow/tests/test_types.py
@@ -296,10 +296,12 @@ def test_union_type():
ty = pa.union(fields, mode=mode)
assert ty.mode == 'sparse'
check_fields(ty, fields)
+ assert ty.type_codes == [0, 1]
for mode in ('dense', pa.lib.UnionMode_DENSE):
ty = pa.union(fields, mode=mode)
assert ty.mode == 'dense'
check_fields(ty, fields)
+ assert ty.type_codes == [0, 1]
for mode in ('unknown', 2):
with pytest.raises(ValueError, match='Invalid union mode'):
pa.union(fields, mode=mode)
diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi
index 0960d34..1de4fac 100644
--- a/python/pyarrow/types.pxi
+++ b/python/pyarrow/types.pxi
@@ -323,6 +323,14 @@ cdef class UnionType(DataType):
return 'sparse'
assert 0
+ @property
+ def type_codes(self):
+ """
+ The type code to indicate each data type in this union.
+ """
+ cdef CUnionType* type = <CUnionType*> self.sp_type.get()
+ return type.type_codes()
+
def __len__(self):
"""
Like num_children()