Repository: arrow
Updated Branches:
  refs/heads/master 9deb3251e -> fb9fbe498


ARROW-604: Python: boxed Field instances are missing the reference to their 
DataType

Author: Uwe L. Korn <uw...@xhochy.com>

Closes #362 from xhochy/ARROW-604 and squashes the following commits:

2e837c8 [Uwe L. Korn] ARROW-604: Python: boxed Field instances are missing the 
reference to DataType


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/fb9fbe49
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/fb9fbe49
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/fb9fbe49

Branch: refs/heads/master
Commit: fb9fbe4981420aaa0a56bfe87254d8b10bd5ba18
Parents: 9deb325
Author: Uwe L. Korn <uw...@xhochy.com>
Authored: Tue Mar 7 17:13:57 2017 +0100
Committer: Uwe L. Korn <uw...@xhochy.com>
Committed: Tue Mar 7 17:13:57 2017 +0100

----------------------------------------------------------------------
 cpp/src/arrow/type.cc               | 3 +++
 python/pyarrow/schema.pyx           | 5 +++++
 python/pyarrow/tests/test_schema.py | 2 ++
 3 files changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/fb9fbe49/cpp/src/arrow/type.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/type.cc b/cpp/src/arrow/type.cc
index 23fa681..7e5f13a 100644
--- a/cpp/src/arrow/type.cc
+++ b/cpp/src/arrow/type.cc
@@ -54,6 +54,9 @@ bool DataType::Equals(const DataType& other) const {
 }
 
 bool DataType::Equals(const std::shared_ptr<DataType>& other) const {
+  if (!other) {
+    return false;
+  }
   return Equals(*other.get());
 }
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/fb9fbe49/python/pyarrow/schema.pyx
----------------------------------------------------------------------
diff --git a/python/pyarrow/schema.pyx b/python/pyarrow/schema.pyx
index 52eeeaf..19910ab 100644
--- a/python/pyarrow/schema.pyx
+++ b/python/pyarrow/schema.pyx
@@ -88,6 +88,7 @@ cdef class Field:
     cdef init(self, const shared_ptr[CField]& field):
         self.sp_field = field
         self.field = field.get()
+        self.type = box_data_type(field.get().type)
 
     @classmethod
     def from_py(cls, object name, DataType type, bint nullable=True):
@@ -326,11 +327,15 @@ def schema(fields):
     return Schema.from_fields(fields)
 
 cdef DataType box_data_type(const shared_ptr[CDataType]& type):
+    if type.get() == NULL:
+        return None
     cdef DataType out = DataType()
     out.init(type)
     return out
 
 cdef Field box_field(const shared_ptr[CField]& field):
+    if field.get() == NULL:
+        return None
     cdef Field out = Field()
     out.init(field)
     return out

http://git-wip-us.apache.org/repos/asf/arrow/blob/fb9fbe49/python/pyarrow/tests/test_schema.py
----------------------------------------------------------------------
diff --git a/python/pyarrow/tests/test_schema.py 
b/python/pyarrow/tests/test_schema.py
index 507ebb8..f6dc33c 100644
--- a/python/pyarrow/tests/test_schema.py
+++ b/python/pyarrow/tests/test_schema.py
@@ -64,6 +64,8 @@ class TestTypes(unittest.TestCase):
         assert len(sch) == 3
         assert sch[0].name == 'foo'
         assert sch[0].type == fields[0].type
+        assert sch.field_by_name('foo').name == 'foo'
+        assert sch.field_by_name('foo').type == fields[0].type
 
         assert repr(sch) == """\
 foo: int32

Reply via email to