Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/pyarrow/includes/libarrow.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions python/pyarrow/schema.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions python/pyarrow/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,20 @@ def test_schema(self):
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)