Skip to content

Commit 51340a9

Browse files
re-add test with list
1 parent 33db5d0 commit 51340a9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/arrays/string_/test_string.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,33 @@ def test_comparison_methods_array(comparison_op, dtype, dtype2):
376376
# tm.assert_equal(result, result3)
377377

378378

379+
def test_comparison_methods_list(comparison_op, dtype):
380+
op_name = f"__{comparison_op.__name__}__"
381+
382+
a = pd.array(["a", None, "c"], dtype=dtype)
383+
other = [None, None, "c"]
384+
result = comparison_op(a, other)
385+
386+
# ensure operation is commutative
387+
result2 = comparison_op(other, a)
388+
tm.assert_equal(result, result2)
389+
390+
if dtype.na_value is np.nan:
391+
if operator.ne == comparison_op:
392+
expected = np.array([True, True, False])
393+
else:
394+
expected = np.array([False, False, False])
395+
expected[-1] = getattr(other[-1], op_name)(a[-1])
396+
tm.assert_numpy_array_equal(result, expected)
397+
398+
else:
399+
expected_dtype = "boolean[pyarrow]" if dtype.storage == "pyarrow" else "boolean"
400+
expected = np.full(len(a), fill_value=None, dtype="object")
401+
expected[-1] = getattr(other[-1], op_name)(a[-1])
402+
expected = pd.array(expected, dtype=expected_dtype)
403+
tm.assert_extension_array_equal(result, expected)
404+
405+
379406
def test_constructor_raises(cls):
380407
if cls is pd.arrays.StringArray:
381408
msg = "StringArray requires a sequence of strings or pandas.NA"

0 commit comments

Comments
 (0)