Skip to content

Commit 3b946b8

Browse files
BryanCutlerxhochy
authored andcommitted
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 <cutlerb@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
1 parent 072b7d6 commit 3b946b8

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

python/pyarrow/includes/libarrow.pxd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
8888

8989
cdef cppclass CSchema" arrow::Schema":
9090
CSchema(const vector[shared_ptr[CField]]& fields)
91+
92+
c_bool Equals(const shared_ptr[CSchema]& other)
93+
9194
const shared_ptr[CField]& field(int i)
9295
int num_fields()
9396
c_string ToString()

python/pyarrow/schema.pyx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ cdef class Schema:
110110
self.schema = schema.get()
111111
self.sp_schema = schema
112112

113+
def equals(self, other):
114+
"""
115+
Test if this schema is equal to the other
116+
"""
117+
cdef Schema _other
118+
_other = other
119+
120+
return self.sp_schema.get().Equals(_other.sp_schema)
121+
113122
@classmethod
114123
def from_fields(cls, fields):
115124
cdef:

python/pyarrow/tests/test_schema.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,20 @@ def test_schema(self):
6969
foo: int32
7070
bar: string
7171
baz: list<item: int8>"""
72+
73+
def test_schema_equals(self):
74+
fields = [
75+
A.field('foo', A.int32()),
76+
A.field('bar', A.string()),
77+
A.field('baz', A.list_(A.int8()))
78+
]
79+
80+
sch1 = A.schema(fields)
81+
print(dir(sch1))
82+
sch2 = A.schema(fields)
83+
assert sch1.equals(sch2)
84+
85+
del fields[-1]
86+
sch3 = A.schema(fields)
87+
assert not sch1.equals(sch3)
88+

0 commit comments

Comments
 (0)