diff --git a/python/pyarrow/tests/test_schema.py b/python/pyarrow/tests/test_schema.py index fadb901977c..80c91bdfd49 100644 --- a/python/pyarrow/tests/test_schema.py +++ b/python/pyarrow/tests/test_schema.py @@ -371,6 +371,15 @@ def test_schema_equals_propagates_check_metadata(): assert schema1.equals(schema2, check_metadata=False) +def test_schema_equals_invalid_type(): + # ARROW-5873 + schema = pa.schema([pa.field("a", pa.int64())]) + + for val in [None, 'string', pa.array([1, 2])]: + with pytest.raises(TypeError): + schema.equals(val) + + def test_schema_equality_operators(): fields = [ pa.field('foo', pa.int32()), diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi index 0c3f8b01967..412ebb72e0d 100644 --- a/python/pyarrow/types.pxi +++ b/python/pyarrow/types.pxi @@ -811,7 +811,7 @@ cdef class Schema: metadata=self.metadata ) - def equals(self, other, bint check_metadata=True): + def equals(self, Schema other not None, bint check_metadata=True): """ Test if this schema is equal to the other @@ -825,8 +825,7 @@ cdef class Schema: ------- is_equal : boolean """ - cdef Schema _other = other - return self.sp_schema.get().Equals(deref(_other.schema), + return self.sp_schema.get().Equals(deref(other.schema), check_metadata) @classmethod