This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 750896f  ARROW-4822: [C++/Python] Check for None on calls to equals
750896f is described below

commit 750896fadb1dee805a1d643d4f46a6b016237e5d
Author: Korn, Uwe <[email protected]>
AuthorDate: Mon Mar 11 10:06:10 2019 -0500

    ARROW-4822: [C++/Python] Check for None on calls to equals
    
    Author: Korn, Uwe <[email protected]>
    
    Closes #3859 from xhochy/ARROW-4822 and squashes the following commits:
    
    fd7c6aeb2 <Korn, Uwe> ARROW-4822:  Check for None on calls to equals
---
 python/pyarrow/table.pxi           |  9 +++++++++
 python/pyarrow/tests/test_table.py | 11 +++++++++++
 2 files changed, 20 insertions(+)

diff --git a/python/pyarrow/table.pxi b/python/pyarrow/table.pxi
index c46cd6d..f0e7de9 100644
--- a/python/pyarrow/table.pxi
+++ b/python/pyarrow/table.pxi
@@ -140,6 +140,9 @@ cdef class ChunkedArray(_PandasConvertible):
             CChunkedArray* other_arr = other.chunked_array
             c_bool result
 
+        if other is None:
+            return False
+
         with nogil:
             result = this_arr.Equals(deref(other_arr))
 
@@ -507,6 +510,9 @@ cdef class Column(_PandasConvertible):
             CColumn* other_col = other.column
             c_bool result
 
+        if other is None:
+            return False
+
         with nogil:
             result = this_col.Equals(deref(other_col))
 
@@ -1050,6 +1056,9 @@ cdef class Table(_PandasConvertible):
             CTable* other_table = other.table
             c_bool result
 
+        if other is None:
+            return False
+
         with nogil:
             result = this_table.Equals(deref(other_table))
 
diff --git a/python/pyarrow/tests/test_table.py 
b/python/pyarrow/tests/test_table.py
index 5eb6aca..afdfd42 100644
--- a/python/pyarrow/tests/test_table.py
+++ b/python/pyarrow/tests/test_table.py
@@ -149,6 +149,8 @@ def test_chunked_array_equals():
     eq([a, c], [d])
     ne([c, a], [a, c])
 
+    assert not pa.chunked_array([], type=pa.int32()).equals(None)
+
 
 @pytest.mark.parametrize(
     ('data', 'typ'),
@@ -230,6 +232,7 @@ def test_column_basics():
     assert column == pa.Column.from_array("a", column.data)
     assert column != pa.Column.from_array("b", column.data)
     assert column != column.data
+    assert not column.equals(None)
 
 
 def test_column_factory_function():
@@ -505,6 +508,14 @@ def test_recordbatchlist_schema_equals():
         pa.Table.from_batches([batch1, batch2])
 
 
+def test_table_equals():
+    table = pa.Table.from_arrays([])
+
+    assert table.equals(table)
+    # ARROW-4822
+    assert not table.equals(None)
+
+
 def test_table_from_batches_and_schema():
     schema = pa.schema([
         pa.field('a', pa.int64()),

Reply via email to