dmitry-chirkov-dremio commented on code in PR #51611:
URL: https://github.com/apache/arrow/pull/51611#discussion_r4348403699


##########
python/pyarrow/tests/test_compute.py:
##########
@@ -3899,6 +3899,45 @@ def test_list_element():
     assert result.equals(expected)
 
 
[email protected]("list_type", [
+    pa.list_(pa.int64()), pa.large_list(pa.int64()),
+    pa.list_view(pa.int64()), pa.large_list_view(pa.int64()),
+])
+def test_list_contains(list_type):
+    lists = pa.array([[1, 2, None], [3], [], None], list_type)
+    assert pc.list_contains(lists, 2).to_pylist() == [True, False, False, None]
+    assert pc.list_contains(lists, 2.0).to_pylist() == [True, False, False, 
None]
+    assert pc.list_contains(lists, 4).to_pylist() == [False, False, False, 
None]
+    # A null value matches null list values
+    assert pc.list_contains(lists, None).to_pylist() == [True, False, False, 
None]
+
+
+def test_list_contains_nan():
+    lists = pa.array([[1.5, None], [float("nan")], []])
+    result = pc.list_contains(lists, float("nan"))
+    assert result.to_pylist() == [False, True, False]
+
+
+def test_list_contains_fixed_size_list():
+    lists = pa.array([["a", "b"], ["c", None], None], pa.list_(pa.string(), 2))
+    assert pc.list_contains(lists, "c").to_pylist() == [False, True, None]
+
+
+def test_list_contains_array():
+    lists = pa.array([[1, 2], [3, None], [4], None])
+    values = pa.array([2, None, 5, 1])
+    result = pc.list_contains(lists, values)
+    assert result.to_pylist() == [True, True, False, None]
+
+
+def test_list_contains_invalid():
+    lists = pa.array([[1, 2], [3]])
+    with pytest.raises(pa.ArrowNotImplementedError):
+        pc.list_contains(lists, "a")
+    with pytest.raises(pa.ArrowNotImplementedError):
+        pc.list_contains(lists, pa.array(["a", "b"]))
+
+

Review Comment:
   What should this return when the list values and search value have different 
fixed-size binary widths?
   
   ```
   import pyarrow as pa
   import pyarrow.compute as pc
   
   
   def test_list_contains_different_binary_widths():
       lists = pa.array([[b"a"]], type=pa.list_(pa.binary(1)))
       value = pa.scalar(b"ab", type=pa.binary(2))
   
       assert pc.equal(lists.values, value).to_pylist() == [False]
       assert pc.list_contains(lists, value).to_pylist() == [False]
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to