jonasdedden commented on code in PR #51611:
URL: https://github.com/apache/arrow/pull/51611#discussion_r4352154102
##########
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:
Good catch, thanks! Values of different fixed-size binary widths were
compared with only the values' width, so `b"a"` matched the prefix of `b"ab"`.
Fixed in 6fdfc18 so they never match, like for `equal`. Fuzzing against `equal`
found no other wrong results, but two cases that didn't raise where `equal`
does, now fixed too: types without a cast between them with null queries
(cbda884), and empty inputs (21030b7).
--
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]