You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by uw...@apache.org on 2016/12/01 12:27:00 UTC

arrow git commit: ARROW-396: [Python] Add pyarrow.schema.Schema.equals

Repository: arrow
Updated Branches:
  refs/heads/master 072b7d671 -> 3b946b822


ARROW-396: [Python] Add pyarrow.schema.Schema.equals

Added pyarrow api for `Schema.equals` to check if 2 schema's are equal and corresponding test case.

Author: Bryan Cutler <cu...@gmail.com>

Closes #221 from BryanCutler/add-pyarrow-schema_equals-ARROW-396 and squashes the following commits:

910e943 [Bryan Cutler] added test case for pyarrow Schema equals
24cf982 [Bryan Cutler] added pyarrow Schema equals, and related def for CSchema


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

Branch: refs/heads/master
Commit: 3b946b822445f21872c7cb42563c8d0c7bc84b80
Parents: 072b7d6
Author: Bryan Cutler <cu...@gmail.com>
Authored: Thu Dec 1 13:26:43 2016 +0100
Committer: Uwe L. Korn <uw...@xhochy.com>
Committed: Thu Dec 1 13:26:43 2016 +0100

----------------------------------------------------------------------
 python/pyarrow/includes/libarrow.pxd |  3 +++
 python/pyarrow/schema.pyx            |  9 +++++++++
 python/pyarrow/tests/test_schema.py  | 17 +++++++++++++++++
 3 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/3b946b82/python/pyarrow/includes/libarrow.pxd
----------------------------------------------------------------------
diff --git a/python/pyarrow/includes/libarrow.pxd b/python/pyarrow/includes/libarrow.pxd
index 3ae1789..19da408 100644
--- a/python/pyarrow/includes/libarrow.pxd
+++ b/python/pyarrow/includes/libarrow.pxd
@@ -88,6 +88,9 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
 
     cdef cppclass CSchema" arrow::Schema":
         CSchema(const vector[shared_ptr[CField]]& fields)
+
+        c_bool Equals(const shared_ptr[CSchema]& other)
+
         const shared_ptr[CField]& field(int i)
         int num_fields()
         c_string ToString()

http://git-wip-us.apache.org/repos/asf/arrow/blob/3b946b82/python/pyarrow/schema.pyx
----------------------------------------------------------------------
diff --git a/python/pyarrow/schema.pyx b/python/pyarrow/schema.pyx
index 084c304..e0badb9 100644
--- a/python/pyarrow/schema.pyx
+++ b/python/pyarrow/schema.pyx
@@ -110,6 +110,15 @@ cdef class Schema:
         self.schema = schema.get()
         self.sp_schema = schema
 
+    def equals(self, other):
+        """
+        Test if this schema is equal to the other
+        """
+        cdef Schema _other
+        _other = other
+
+        return self.sp_schema.get().Equals(_other.sp_schema)
+
     @classmethod
     def from_fields(cls, fields):
         cdef:

http://git-wip-us.apache.org/repos/asf/arrow/blob/3b946b82/python/pyarrow/tests/test_schema.py
----------------------------------------------------------------------
diff --git a/python/pyarrow/tests/test_schema.py b/python/pyarrow/tests/test_schema.py
index 2894ea8..4aa8112 100644
--- a/python/pyarrow/tests/test_schema.py
+++ b/python/pyarrow/tests/test_schema.py
@@ -69,3 +69,20 @@ class TestTypes(unittest.TestCase):
 foo: int32
 bar: string
 baz: list<item: int8>"""
+
+    def test_schema_equals(self):
+        fields = [
+            A.field('foo', A.int32()),
+            A.field('bar', A.string()),
+            A.field('baz', A.list_(A.int8()))
+        ]
+
+        sch1 = A.schema(fields)
+        print(dir(sch1))
+        sch2 = A.schema(fields)
+        assert sch1.equals(sch2)
+
+        del fields[-1]
+        sch3 = A.schema(fields)
+        assert not sch1.equals(sch3)
+